Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Deprecations: Changes we can make with 5.3 for the banner component (Backend) #44330

Draft
wants to merge 2 commits into
base: 5.3-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -147,7 +148,7 @@ public static function getClientOptions()
{
$options = [];

$db = Factory::getDbo();
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true)
->select(
[
Expand Down
14 changes: 9 additions & 5 deletions administrator/components/com_banners/src/Model/BannerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@
class BannerModel extends AdminModel
{
use VersionableModelTrait;
use LegacyErrorHandlingTrait;

/**
* The prefix to use with controller messages.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
49 changes: 34 additions & 15 deletions administrator/components/com_banners/src/Model/TracksModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading