diff --git a/administrator/components/com_banners/src/Controller/BannersController.php b/administrator/components/com_banners/src/Controller/BannersController.php index 4c44abbc47374..528a98eeebea7 100644 --- a/administrator/components/com_banners/src/Controller/BannersController.php +++ b/administrator/components/com_banners/src/Controller/BannersController.php @@ -99,6 +99,7 @@ public function sticky_publish() // Change the state of the records. if (!$model->stick($ids, $value)) { + // @todo: 6.0 - Update Error handling $this->app->enqueueMessage($model->getError(), 'warning'); } else { if ($value == 1) { diff --git a/administrator/components/com_banners/src/Controller/TracksController.php b/administrator/components/com_banners/src/Controller/TracksController.php index 1652afc823768..ccb0fe242ed1b 100644 --- a/administrator/components/com_banners/src/Controller/TracksController.php +++ b/administrator/components/com_banners/src/Controller/TracksController.php @@ -78,6 +78,7 @@ public function delete() // Remove the items. if (!$model->delete()) { + // @todo: 6.0 - Update Error handling $this->app->enqueueMessage($model->getError(), 'warning'); } elseif ($count > 0) { $this->setMessage(Text::plural('COM_BANNERS_TRACKS_N_ITEMS_DELETED', $count)); diff --git a/administrator/components/com_banners/src/Helper/BannersHelper.php b/administrator/components/com_banners/src/Helper/BannersHelper.php index cd867e89e53e5..52f5c5a7a51d3 100644 --- a/administrator/components/com_banners/src/Helper/BannersHelper.php +++ b/administrator/components/com_banners/src/Helper/BannersHelper.php @@ -15,7 +15,8 @@ use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; -use Joomla\CMS\Table\Table; +use Joomla\Component\Banners\Administrator\Table\ClientTable; +use Joomla\Database\DatabaseInterface; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects @@ -38,7 +39,7 @@ class BannersHelper extends ContentHelper */ public static function updateReset() { - $db = Factory::getDbo(); + $db = Factory::getContainer()->get(DatabaseInterface::class); $nowDate = Factory::getDate()->toSql(); $app = Factory::getApplication(); $user = $app->getIdentity(); @@ -78,7 +79,7 @@ public static function updateReset() if ($purchaseType < 0 && $row->cid) { /** @var \Joomla\Component\Banners\Administrator\Table\ClientTable $client */ - $client = Table::getInstance('ClientTable', '\\Joomla\\Component\\Banners\\Administrator\\Table\\'); + $client = new ClientTable(Factory::getContainer()->get(DatabaseInterface::class)); $client->load($row->cid); $purchaseType = $client->purchase_type; } @@ -147,7 +148,7 @@ public static function getClientOptions() { $options = []; - $db = Factory::getDbo(); + $db = Factory::getContainer()->get(DatabaseInterface::class); $query = $db->getQuery(true) ->select( [ diff --git a/administrator/components/com_banners/src/Model/BannerModel.php b/administrator/components/com_banners/src/Model/BannerModel.php index b03de8fd0eb8f..b60f5c4c22191 100644 --- a/administrator/components/com_banners/src/Model/BannerModel.php +++ b/administrator/components/com_banners/src/Model/BannerModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Object\LegacyErrorHandlingTrait; use Joomla\CMS\Table\Table; use Joomla\CMS\Table\TableInterface; use Joomla\CMS\Versioning\VersionableModelTrait; @@ -32,6 +33,7 @@ class BannerModel extends AdminModel { use VersionableModelTrait; + use LegacyErrorHandlingTrait; /** * The prefix to use with controller messages. @@ -115,6 +117,7 @@ protected function batchClient($value, $pks, $contexts) foreach ($pks as $pk) { if (!$user->authorise('core.edit', $contexts[$pk])) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); return false; @@ -125,6 +128,7 @@ protected function batchClient($value, $pks, $contexts) $table->cid = (int) $value; if (!$table->store()) { + // @todo: 6.0 - Update Error handling $this->setError($table->getError()); return false; @@ -302,6 +306,7 @@ public function stick(&$pks, $value = 1) // Attempt to change the state of the records. if (!$table->stick($pks, $value, $this->getCurrentUser()->id)) { + // @todo: 6.0 - Update Error handling $this->setError($table->getError()); return false; @@ -431,6 +436,7 @@ public function save($data) // Create new category. if (!$categoryModel->save($category)) { + // @todo: 6.0 - Update Error handling $this->setError($categoryModel->getError()); return false; @@ -447,13 +453,11 @@ public function save($data) $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { - list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); + [$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; - } else { - if ($data['alias'] == $origTable->alias) { - $data['alias'] = ''; - } + } elseif ($data['alias'] == $origTable->alias) { + $data['alias'] = ''; } $data['state'] = 0; diff --git a/administrator/components/com_banners/src/Model/ClientsModel.php b/administrator/components/com_banners/src/Model/ClientsModel.php index c78f011b5bcd2..6ee21ace0614b 100644 --- a/administrator/components/com_banners/src/Model/ClientsModel.php +++ b/administrator/components/com_banners/src/Model/ClientsModel.php @@ -245,6 +245,7 @@ public function getItems() $state = 1; $countPublished = $db->loadAssocList('cid', 'count_published'); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -255,6 +256,7 @@ public function getItems() $state = 0; $countUnpublished = $db->loadAssocList('cid', 'count_published'); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -265,6 +267,7 @@ public function getItems() $state = -2; $countTrashed = $db->loadAssocList('cid', 'count_published'); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -275,6 +278,7 @@ public function getItems() $state = 2; $countArchived = $db->loadAssocList('cid', 'count_published'); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; diff --git a/administrator/components/com_banners/src/Model/TracksModel.php b/administrator/components/com_banners/src/Model/TracksModel.php index bc820a86e8d7d..1408d2621e464 100644 --- a/administrator/components/com_banners/src/Model/TracksModel.php +++ b/administrator/components/com_banners/src/Model/TracksModel.php @@ -124,7 +124,8 @@ protected function getListQuery() // Filter by type. - if ($type = (int) $this->getState('filter.type')) { + $type = (int) $this->getState('filter.type'); + if ($type) { $query->where($db->quoteName('a.track_type') . ' = :type') ->bind(':type', $type, ParameterType::INTEGER); } @@ -148,25 +149,29 @@ protected function getListQuery() } // Filter by begin date. - if ($begin = $this->getState('filter.begin')) { + $begin = $this->getState('filter.begin'); + if ($begin) { $query->where($db->quoteName('a.track_date') . ' >= :begin') ->bind(':begin', $begin); } // Filter by end date. - if ($end = $this->getState('filter.end')) { + $end = $this->getState('filter.end'); + if ($end) { $query->where($db->quoteName('a.track_date') . ' <= :end') ->bind(':end', $end); } // Filter on the level. - if ($level = (int) $this->getState('filter.level')) { + $level = (int) $this->getState('filter.level'); + if ($level) { $query->where($db->quoteName('c.level') . ' <= :level') ->bind(':level', $level, ParameterType::INTEGER); } // Filter by search in banner name or client name. - if ($search = $this->getState('filter.search')) { + $search = $this->getState('filter.search'); + if ($search) { $search = '%' . StringHelper::strtolower($search) . '%'; $query->where('(LOWER(' . $db->quoteName('b.name') . ') LIKE :search1 OR LOWER(' . $db->quoteName('cl.name') . ') LIKE :search2)') ->bind([':search1', ':search2'], $search); @@ -204,19 +209,22 @@ public function delete() ->delete($db->quoteName('#__banner_tracks')); // Filter by type - if ($type = (int) $this->getState('filter.type')) { + $type = (int) $this->getState('filter.type'); + if ($type) { $query->where($db->quoteName('track_type') . ' = :type') ->bind(':type', $type, ParameterType::INTEGER); } // Filter by begin date - if ($begin = $this->getState('filter.begin')) { + $begin = $this->getState('filter.begin'); + if ($begin) { $query->where($db->quoteName('track_date') . ' >= :begin') ->bind(':begin', $begin); } // Filter by end date - if ($end = $this->getState('filter.end')) { + $end = $this->getState('filter.end'); + if ($end) { $query->where($db->quoteName('track_date') . ' <= :end') ->bind(':end', $end); } @@ -226,7 +234,8 @@ public function delete() ->from($db->quoteName('#__banners')); // Filter by client - if ($clientId = (int) $this->getState('filter.client_id')) { + $clientId = (int) $this->getState('filter.client_id'); + if ($clientId) { $subQuery->where($db->quoteName('cid') . ' = :clientId'); $query->bind(':clientId', $clientId, ParameterType::INTEGER); } @@ -240,11 +249,13 @@ public function delete() $query->where($db->quoteName('banner_id') . ' IN (' . $subQuery . ')'); $db->setQuery($query); + // @todo: 6.0 - Update Error handling $this->setError((string) $query); try { $db->execute(); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -352,6 +363,7 @@ protected function getCategoryName() try { $name = $db->loadResult(); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -386,6 +398,7 @@ protected function getClientName() try { $name = $db->loadResult(); } catch (\RuntimeException $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -463,23 +476,29 @@ public function getContent() $delete = Folder::files($app->get('tmp_path') . '/', uniqid('banners_tracks_'), false, true); if (!empty($delete)) { - if (!File::delete($delete)) { - // File::delete throws an error - $this->setError(Text::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE')); - - return false; + foreach ($delete as $file) { + if (!File::delete($file)) { + // File::delete throws an error + // @todo: 6.0 - Update Error handling + $this->setError(Text::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE')); + + return false; + } } } $archive = new Archive(); - if (!$packager = $archive->getAdapter('zip')) { + $packager = $archive->getAdapter('zip'); + if (!$packager) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('COM_BANNERS_ERR_ZIP_ADAPTER_FAILURE')); return false; } if (!$packager->create($ziproot, $files)) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('COM_BANNERS_ERR_ZIP_CREATE_FAILURE')); return false; diff --git a/administrator/components/com_banners/src/Table/BannerTable.php b/administrator/components/com_banners/src/Table/BannerTable.php index bd3968945314b..edddc85b9e256 100644 --- a/administrator/components/com_banners/src/Table/BannerTable.php +++ b/administrator/components/com_banners/src/Table/BannerTable.php @@ -41,6 +41,12 @@ class BannerTable extends Table implements VersionableTableInterface */ protected $_supportNullValue = true; + /** + * @var string + * @since __DEPLOY_VERSION__ + */ + public $created; + /** * Constructor * @@ -90,6 +96,7 @@ public function check() try { parent::check(); } catch (\Exception $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -110,7 +117,9 @@ public function check() } // Check for a valid category. - if (!$this->catid = (int) $this->catid) { + $this->catid = (int) $this->catid; + if (!$this->catid) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); return false; @@ -132,6 +141,7 @@ public function check() // Check the publish down date is not earlier than publish up. if (!\is_null($this->publish_down) && !\is_null($this->publish_up) && $this->publish_down < $this->publish_up) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); return false; @@ -175,12 +185,14 @@ public function bind($array, $ignore = []) $registry = new Registry($array['params']); if ((int) $registry->get('width', 0) < 0) { + // @todo: 6.0 - Update Error handling $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', Text::_('COM_BANNERS_FIELD_WIDTH_LABEL'))); return false; } if ((int) $registry->get('height', 0) < 0) { + // @todo: 6.0 - Update Error handling $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', Text::_('COM_BANNERS_FIELD_HEIGHT_LABEL'))); return false; @@ -256,6 +268,7 @@ public function store($updateNulls = true) // Get the old row $oldrow = new self($db, $this->getDispatcher()); + // @todo: 6.0 - Update Error handling if (!$oldrow->load($this->id) && $oldrow->getError()) { $this->setError($oldrow->getError()); } @@ -264,6 +277,7 @@ public function store($updateNulls = true) $table = new self($db, $this->getDispatcher()); if ($table->load(['alias' => $this->alias, 'catid' => $this->catid]) && ($table->id != $this->id || $this->id == 0)) { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('COM_BANNERS_ERROR_UNIQUE_ALIAS')); return false; @@ -279,6 +293,7 @@ public function store($updateNulls = true) } } + // @todo: 6.0 - Update Error handling return \count($this->getErrors()) == 0; } @@ -310,6 +325,7 @@ public function stick($pks = null, $state = 1, $userId = 0) $pks = [$this->$k]; } else { // Nothing to set publishing state on, return false. + // @todo: 6.0 - Update Error handling $this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); return false; @@ -323,6 +339,7 @@ public function stick($pks = null, $state = 1, $userId = 0) foreach ($pks as $pk) { // Load the banner if (!$table->load($pk)) { + // @todo: 6.0 - Update Error handling $this->setError($table->getError()); } @@ -338,11 +355,13 @@ public function stick($pks = null, $state = 1, $userId = 0) // Store the row if (!$table->store()) { + // @todo: 6.0 - Update Error handling $this->setError($table->getError()); } } } + // @todo: 6.0 - Update Error handling return \count($this->getErrors()) == 0; } diff --git a/administrator/components/com_banners/src/Table/ClientTable.php b/administrator/components/com_banners/src/Table/ClientTable.php index 5a08c82bb4c79..45bfa85502b1e 100644 --- a/administrator/components/com_banners/src/Table/ClientTable.php +++ b/administrator/components/com_banners/src/Table/ClientTable.php @@ -77,6 +77,7 @@ public function check() try { parent::check(); } catch (\Exception $e) { + // @todo: 6.0 - Update Error handling $this->setError($e->getMessage()); return false; @@ -84,6 +85,7 @@ public function check() // Check for valid name if (trim($this->name) === '') { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('COM_BANNERS_WARNING_PROVIDE_VALID_NAME')); return false; @@ -91,6 +93,7 @@ public function check() // Check for valid contact if (trim($this->contact) === '') { + // @todo: 6.0 - Update Error handling $this->setError(Text::_('COM_BANNERS_PROVIDE_VALID_CONTACT')); return false; diff --git a/administrator/components/com_banners/src/View/Banner/HtmlView.php b/administrator/components/com_banners/src/View/Banner/HtmlView.php index 7e2785000a55c..d3d1bd73901c5 100644 --- a/administrator/components/com_banners/src/View/Banner/HtmlView.php +++ b/administrator/components/com_banners/src/View/Banner/HtmlView.php @@ -76,7 +76,8 @@ public function display($tpl = null): void $this->state = $model->getState(); // Check for errors. - if (\count($errors = $model->getErrors())) { + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Banners/HtmlView.php b/administrator/components/com_banners/src/View/Banners/HtmlView.php index dced0e0e68bcd..cfbf3599c7348 100644 --- a/administrator/components/com_banners/src/View/Banners/HtmlView.php +++ b/administrator/components/com_banners/src/View/Banners/HtmlView.php @@ -110,12 +110,15 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + $this->isEmptyState = $model->getIsEmptyState(); + if (!\count($this->items) && $this->isEmptyState) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Client/HtmlView.php b/administrator/components/com_banners/src/View/Client/HtmlView.php index 0772f29620c42..1669c96a6399b 100644 --- a/administrator/components/com_banners/src/View/Client/HtmlView.php +++ b/administrator/components/com_banners/src/View/Client/HtmlView.php @@ -85,7 +85,9 @@ public function display($tpl = null): void $this->canDo = ContentHelper::getActions('com_banners'); // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Clients/HtmlView.php b/administrator/components/com_banners/src/View/Clients/HtmlView.php index adc913a2edd5b..098f9add04704 100644 --- a/administrator/components/com_banners/src/View/Clients/HtmlView.php +++ b/administrator/components/com_banners/src/View/Clients/HtmlView.php @@ -99,12 +99,15 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + $this->isEmptyState = $model->getIsEmptyState(); + if (!\count($this->items) && $this->isEmptyState) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Download/HtmlView.php b/administrator/components/com_banners/src/View/Download/HtmlView.php index a9bf5b198bd2b..478a79611d7ae 100644 --- a/administrator/components/com_banners/src/View/Download/HtmlView.php +++ b/administrator/components/com_banners/src/View/Download/HtmlView.php @@ -52,7 +52,9 @@ public function display($tpl = null): void $this->form = $model->getForm(); // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Tracks/HtmlView.php b/administrator/components/com_banners/src/View/Tracks/HtmlView.php index 65044eed4151e..d3d92dcb7afb9 100644 --- a/administrator/components/com_banners/src/View/Tracks/HtmlView.php +++ b/administrator/components/com_banners/src/View/Tracks/HtmlView.php @@ -99,12 +99,15 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + $this->isEmptyState = $model->getIsEmptyState(); + if (!\count($this->items) && $this->isEmptyState) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Tracks/RawView.php b/administrator/components/com_banners/src/View/Tracks/RawView.php index ff7652ac2f78a..7c055b2e56cfd 100644 --- a/administrator/components/com_banners/src/View/Tracks/RawView.php +++ b/administrator/components/com_banners/src/View/Tracks/RawView.php @@ -48,7 +48,9 @@ public function display($tpl = null): void $content = $model->getContent(); // Check for errors. - if (\count($errors = $model->getErrors())) { + // @todo: 6.0 - Update Error handling + $errors = $model->getErrors(); + if (\count($errors)) { throw new GenericDataException(implode("\n", $errors), 500); }