| @@ -155,8 +155,56 @@ | ||
| 155 | 155 | return array_map([$this, 'normalizeObject'], $records); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | + * Method to delete one or more records. | |
| 160 | + * | |
| 161 | + * @param mixed $pks An array of record primary keys, or a single one. | |
| 162 | + * | |
| 163 | + * @return bool True if successful, false if an error occurs. | |
| 164 | + * | |
| 165 | + * @since 1.8.19 (J) - 1.8.9 (WP) | |
| 166 | + */ | |
| 167 | + public function delete($pks) | |
| 168 | + { | |
| 169 | + $dbo = JFactory::getDbo(); | |
| 170 | + | |
| 171 | + if (!$pks) { | |
| 172 | + // nothing to delete | |
| 173 | + return false; | |
| 174 | + } | |
| 175 | + | |
| 176 | + if (!is_array($pks)) { | |
| 177 | + // wrap into an array | |
| 178 | + $pks = [$pks]; | |
| 179 | + } | |
| 180 | + | |
| 181 | + $deleted = 0; | |
| 182 | + | |
| 183 | + foreach ($pks as $pk) { | |
| 184 | + // ensure the item exists | |
| 185 | + $item = $this->getItem($pk); | |
| 186 | + | |
| 187 | + if (!$item) { | |
| 188 | + continue; | |
| 189 | + } | |
| 190 | + | |
| 191 | + $dbo->setQuery( | |
| 192 | + $dbo->getQuery(true) | |
| 193 | + ->delete($dbo->qn('#__vikbooking_payschedules')) | |
| 194 | + ->where($dbo->qn('id') . ' = ' . (int) $item->id) | |
| 195 | + ); | |
| 196 | + $dbo->execute(); | |
| 197 | + | |
| 198 | + if ((bool) $dbo->getAffectedRows()) { | |
| 199 | + $deleted++; | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 203 | + return (bool) $deleted; | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 159 | 207 | * Watches and eventually processes the automatic payment collections scheduled. |
| 160 | 208 | * |
| 161 | 209 | * @param int $lim the limit of payments to process, defaults to 5 per execution. |
| 162 | 210 | * |
| @@ -201,12 +249,17 @@ | ||
| 201 | 249 | $processed++; |
| 202 | 250 | } |
| 203 | 251 | } catch (Exception $e) { |
| 204 | 252 | // append failure execution log and update status (2 = error) |
| 205 | - $dbo->setQuery( | |
| 253 | + $maxBytes = 65000; | |
| 254 | + $recordLog = ltrim($payschedule->logs . "\n" . $e->getMessage(), "\n"); | |
| 255 | + if (strlen($recordLog) > $maxBytes) { | |
| 256 | + $recordLog = function_exists('mb_strcut') ? mb_strcut($recordLog, -$maxBytes, $maxBytes, 'UTF-8') : substr($recordLog, -$maxBytes, $maxBytes); | |
| 257 | + } | |
| 258 | + $dbo->setQuery( | |
| 206 | 259 | $dbo->getQuery(true) |
| 207 | 260 | ->update($dbo->qn('#__vikbooking_payschedules')) |
| 208 | - ->set($dbo->qn('logs') . ' = ' . $dbo->q(ltrim($payschedule->logs . "\n" . $e->getMessage(), "\n"))) | |
| 261 | + ->set($dbo->qn('logs') . ' = ' . $dbo->q($recordLog)) | |
| 209 | 262 | ->set($dbo->qn('status') . ' = 2') |
| 210 | 263 | ->where($dbo->qn('id') . ' = ' . (int) $payschedule->id) |
| 211 | 264 | ); |
| 212 | 265 | $dbo->execute(); |