Skip to content

Commit

Permalink
Empty State for Checking for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil E. Taylor committed May 1, 2021
1 parent 8ef49ee commit 6925110
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Language\Associations;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;

Expand Down Expand Up @@ -490,30 +491,28 @@ public function countItems(&$items, $extension)
}

/**
* Is this an empty state, I.e: no items of this type regardless of the searched for states.
* Manipulate the query to be used to evaluate if this is an Empty State to provide specific conditions for this extension.
*
* @return boolean
* @return DatabaseQuery
*
* @since __DEPLOY_VERSION__
*/
public function getisEmptyState()
protected function getEmptyStateQuery(): DatabaseQuery
{
$extension = $this->getState('filter.extension');
$query = parent::getEmptyStateQuery();

$sql = $this->query
->clear('select')
->clear('values')
->clear('bounded')
->clear('limit')
->clear('order')
->clear('where')
->select('count(*)');
// Remove select because it contains fields from joined tables, that have been removed from join.
$query->clear('select');

$sql->where($this->_db->quoteName('extension') . ' = :extension')
->bind(':extension', $extension);
// Add back a simple count select.
$query->select('count(*)');

// Get the extension from the filter
$extension = $this->getState('filter.extension');

$this->_db->setQuery($sql);
$query->where($this->_db->quoteName('extension') . ' = :extension')
->bind(':extension', $extension);

return !($this->_db->loadResult() > 0);
return $query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\CMS\Session\Session;
use Joomla\CMS\Updater\Updater;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Installer\Administrator\Model\UpdateModel;
use Joomla\Utilities\ArrayHelper;

/**
Expand All @@ -40,7 +41,7 @@ public function update()
// Check for request forgeries.
$this->checkToken();

/** @var \Joomla\Component\Installer\Administrator\Model\UpdateModel $model */
/** @var UpdateModel $model */
$model = $this->getModel('update');

$uid = $this->input->get('cid', array(), 'array');
Expand Down Expand Up @@ -96,9 +97,12 @@ public function find()
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);

// Find updates.
/** @var \Joomla\Component\Installer\Administrator\Model\UpdateModel $model */
/** @var UpdateModel $model */
$model = $this->getModel('update');

// Purge the table before checking again
$model->purge();

$disabledUpdateSites = $model->getDisabledUpdateSites();

if ($disabledUpdateSites)
Expand All @@ -108,26 +112,13 @@ public function find()
}

$model->findUpdates(0, $cache_timeout, $minimum_stability);
$this->setRedirect(Route::_('index.php?option=com_installer&view=update', false));
}

/**
* Purges updates.
*
* @return void
*
* @since 1.6
*/
public function purge()
{
// Check for request forgeries.
$this->checkToken();

/** @var \Joomla\Component\Installer\Administrator\Model\UpdateModel $model */
$model = $this->getModel('update');
$model->purge();
if (0 === $model->getTotal())
{
$this->setMessage(Text::_('COM_INSTALLER_MSG_UPDATE_NOUPDATES'), 'info');
}

$this->setRedirect(Route::_('index.php?option=com_installer&view=update', false), $model->_message);
$this->setRedirect(Route::_('index.php?option=com_installer&view=update', false));
}

/**
Expand Down Expand Up @@ -170,7 +161,7 @@ public function ajax()
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
}

/** @var \Joomla\Component\Installer\Administrator\Model\UpdateModel $model */
/** @var UpdateModel $model */
$model = $this->getModel('update');
$model->findUpdates($eid, $cache_timeout, $minimum_stability);

Expand Down
17 changes: 17 additions & 0 deletions administrator/components/com_installer/src/Model/UpdateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Updater\Update;
use Joomla\CMS\Updater\Updater;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;
Expand Down Expand Up @@ -630,4 +631,20 @@ protected function preparePreUpdate($update, $table)
break;
}
}

/**
* Manipulate the query to be used to evaluate if this is an Empty State to provide specific conditions for this extension.
*
* @return DatabaseQuery
*
* @since __DEPLOY_VERSION__
*/
protected function getEmptyStateQuery(): DatabaseQuery
{
$query = parent::getEmptyStateQuery();

$query->where($this->_db->quoteName('extension_id') . ' != 0');

return $query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class HtmlView extends InstallerViewDefault
*/
protected $missingDownloadKeys = 0;

/**
* @var boolean
* @since __DEPLOY_VERSION__
*/
private $isEmptyState = false;

/**
* Display the view.
*
Expand All @@ -70,7 +76,11 @@ public function display($tpl = null)

$this->paths = &$paths;

if (count($this->items) > 0)
if (count($this->items) === 0 && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}
else
{
Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_MSG_WARNINGS_UPDATE_NOTICE'), 'warning');
}
Expand Down Expand Up @@ -113,9 +123,12 @@ public function display($tpl = null)
*/
protected function addToolbar()
{
ToolbarHelper::custom('update.update', 'upload', '', 'COM_INSTALLER_TOOLBAR_UPDATE', true);
if (false === $this->isEmptyState)
{
ToolbarHelper::custom('update.update', 'upload', '', 'COM_INSTALLER_TOOLBAR_UPDATE', true);
}

ToolbarHelper::custom('update.find', 'refresh', '', 'COM_INSTALLER_TOOLBAR_FIND_UPDATES', false);
ToolbarHelper::custom('update.purge', 'purge', '', 'COM_INSTALLER_TOOLBAR_PURGE', false);
ToolbarHelper::divider();

parent::addToolbar();
Expand Down
30 changes: 30 additions & 0 deletions administrator/components/com_installer/tmpl/update/emptystate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Session\Session;

$displayData = [
'textPrefix' => 'COM_INSTALLER',
'formURL' => 'index.php?option=com_installer&view=update',
'helpURL' => 'https://docs.joomla.org/Help4.x:Extensions:_Update',
'icon' => 'icon-puzzle-piece install',
];

$user = Factory::getApplication()->getIdentity();

if ($user->authorise('core.create', 'com_content') || count($user->getAuthorisedCategories('com_content', 'core.create')) > 0)
{
$displayData['createURL'] = 'index.php?option=com_installer&task=update.find&' . Session::getFormToken() . '=1';
}

echo LayoutHelper::render('joomla.content.emptystate', $displayData);

0 comments on commit 6925110

Please sign in to comment.