Skip to content

Commit

Permalink
[4] Empty State for Checking for updates (#33474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil E. Taylor authored May 2, 2021
1 parent e32f5d8 commit c590711
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 25 deletions.
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);
5 changes: 4 additions & 1 deletion administrator/language/en-GB/com_installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ COM_INSTALLER_DISCOVER_TABLE_CAPTION="Table of Discovered Extensions"
COM_INSTALLER_DOWNLOADKEY_EXTRA_QUERY_LABEL="Download Key"
COM_INSTALLER_DOWNLOADKEY_MISSING_LABEL="The Download Key is missing"
COM_INSTALLER_DOWNLOADKEY_MISSING_TIP="Updates for this extension will not work until you enter its Download Key. Click on the Update Site's title to enter the Download Key."
COM_INSTALLER_EMPTYSTATE_TITLE="Check For Updates"
COM_INSTALLER_EMPTYSTATE_BUTTON_ADD="Check For Updates"
COM_INSTALLER_EMPTYSTATE_CONTENT="You currently have no pending updates to apply. Check regularly for new updates to keep your site up to date and secure."
COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED="Disable default template is not permitted."
COM_INSTALLER_ERROR_METHOD="Method Not Implemented"
COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED="No extensions selected."
Expand Down Expand Up @@ -225,7 +228,7 @@ COM_INSTALLER_TITLE_UPDATESITES="Extensions: Update Sites"
COM_INSTALLER_TOOLBAR_DATABASE_FIX="Update Structure"
COM_INSTALLER_TOOLBAR_DISCOVER="Discover"
COM_INSTALLER_TOOLBAR_FIND_LANGUAGES="Find languages"
COM_INSTALLER_TOOLBAR_FIND_UPDATES="Find Updates"
COM_INSTALLER_TOOLBAR_FIND_UPDATES="Check For Updates"
COM_INSTALLER_TOOLBAR_INSTALL="Install"
COM_INSTALLER_TOOLBAR_PURGE="Clear Cache"
COM_INSTALLER_TOOLBAR_UPDATE="Update"
Expand Down

0 comments on commit c590711

Please sign in to comment.