Skip to content

Commit

Permalink
extend Admin on Controller/Updatesites
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoLopesPT committed Jun 8, 2017
1 parent b8de81f commit 84d9c75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 78 deletions.
76 changes: 2 additions & 74 deletions administrator/components/com_installer/Controller/Updatesites.php
Expand Up @@ -10,9 +10,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\Controller\Controller;
use Joomla\CMS\Controller\Admin;
use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;
use Joomla\Utilities\ArrayHelper;

/**
* Installer Update Sites Controller
Expand All @@ -21,7 +20,7 @@
* @subpackage com_installer
* @since 3.4
*/
class Updatesites extends Controller
class Updatesites extends Admin
{
/**
* Constructor.
Expand All @@ -38,80 +37,9 @@ public function __construct($config = array(), MvcFactoryInterface $factory = nu
{
parent::__construct($config, $factory, $app, $input);

$this->registerTask('unpublish', 'publish');
$this->registerTask('publish', 'publish');
$this->registerTask('delete', 'delete');
$this->registerTask('rebuild', 'rebuild');
}

/**
* Enable/Disable an extension (if supported).
*
* @return void
*
* @since 3.4
*
* @throws \Exception on error
*/
public function publish()
{
// Check for request forgeries.
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));

$ids = $this->input->get('cid', array(), 'array');
$values = array('publish' => 1, 'unpublish' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');

if (empty($ids))
{
throw new \Exception(\JText::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500);
}

// Get the model.
/* @var \Joomla\Component\Installer\Administrator\Model\Updatesites $model */
$model = $this->getModel('Updatesites');

// Change the state of the records.
if (!$model->publish($ids, $value))
{
throw new \Exception(implode('<br>', $model->getErrors()), 500);
}

$ntext = ($value == 0) ? 'COM_INSTALLER_N_UPDATESITES_UNPUBLISHED' : 'COM_INSTALLER_N_UPDATESITES_PUBLISHED';

$this->setMessage(\JText::plural($ntext, count($ids)));

$this->setRedirect(\JRoute::_('index.php?option=com_installer&view=updatesites', false));
}

/**
* Deletes an update site (if supported).
*
* @return void
*
* @since 3.6
*
* @throws \Exception on error
*/
public function delete()
{
// Check for request forgeries.
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));

$ids = $this->input->get('cid', array(), 'array');

if (empty($ids))
{
throw new \Exception(\JText::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500);
}

// Delete the records.
$this->getModel('Updatesites')->delete($ids);

$this->setRedirect(\JRoute::_('index.php?option=com_installer&view=updatesites', false));
}

/**
* Rebuild update sites tables.
*
Expand Down
8 changes: 4 additions & 4 deletions administrator/language/en-GB/en-GB.com_installer.ini
Expand Up @@ -183,10 +183,10 @@ COM_INSTALLER_N_EXTENSIONS_PUBLISHED="%d extensions enabled."
COM_INSTALLER_N_EXTENSIONS_PUBLISHED_1="%d extension enabled."
COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED="%d extensions disabled."
COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED_1="%d extension disabled."
COM_INSTALLER_N_UPDATESITES_PUBLISHED="%d update sites enabled."
COM_INSTALLER_N_UPDATESITES_PUBLISHED_1="%d update site enabled."
COM_INSTALLER_N_UPDATESITES_UNPUBLISHED="%d update sites disabled."
COM_INSTALLER_N_UPDATESITES_UNPUBLISHED_1="%d update site disabled."
COM_INSTALLER_N_ITEMS_PUBLISHED="%d update sites enabled."
COM_INSTALLER_N_ITEMS_PUBLISHED_1="%d update site enabled."
COM_INSTALLER_N_ITEMS_UNPUBLISHED="%d update sites disabled."
COM_INSTALLER_N_ITEMS_UNPUBLISHED_1="%d update site disabled."
COM_INSTALLER_NEW_INSTALL="New Install"
COM_INSTALLER_NEW_VERSION="Available"
COM_INSTALLER_NO_INSTALL_TYPE_FOUND="No Install Type Found"
Expand Down

0 comments on commit 84d9c75

Please sign in to comment.