Skip to content
Closed
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 @@ -94,7 +94,11 @@ public function purge()
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$model = $this->getModel('update');
$model->purge();
$model->enableSites();

// We no longer need to enable update sites in Joomla! 3.4 as we now allow the users to manage update sites
// themselves.
// $model->enableSites();

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

Expand Down
76 changes: 76 additions & 0 deletions administrator/components/com_installer/controllers/updatesites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* Installer Update Sites Controller
*
* @package Joomla.Administrator
* @subpackage com_installer
* @since 3.4
*/
class InstallerControllerUpdatesites extends JControllerLegacy
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 3.4
*/
public function __construct($config = array())
{
parent::__construct($config);

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

/**
* 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 = JArrayHelper::getValue($values, $task, 0, 'int');

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

// Get the 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_EXTENSIONS_UNPUBLISHED' : 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED';

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

$this->setRedirect(JRoute::_('index.php?option=com_installer&view=updatesites', false));
}
}
5 changes: 5 additions & 0 deletions administrator/components/com_installer/helpers/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static function addSubmenu($vName = 'install')
'index.php?option=com_installer&view=languages',
$vName == 'languages'
);
JHtmlSidebar::addEntry(
JText::_('COM_INSTALLER_SUBMENU_UPDATESITES'),
'index.php?option=com_installer&view=updatesites',
$vName == 'updatesites'
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
*
* @return array The array of translated objects
*/
private function translate(&$items)
protected function translate(&$items)
{
$lang = JFactory::getLanguage();
foreach ($items as &$item)
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_installer/models/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ public function purge()
->set($db->quoteName('last_check_timestamp') . ' = ' . $db->quote(0));
$db->setQuery($query);
$db->execute();
$this->_message = JText::_('COM_INSTALLER_PURGED_UPDATES');
$this->_message = JText::_('JLIB_INSTALLER_PURGED_UPDATES');
return true;
}
else
{
$this->_message = JText::_('COM_INSTALLER_FAILED_TO_PURGE_UPDATES');
$this->_message = JText::_('JLIB_INSTALLER_FAILED_TO_PURGE_UPDATES');
return false;
}
}
Expand Down
249 changes: 249 additions & 0 deletions administrator/components/com_installer/models/updatesites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

require_once __DIR__ . '/extension.php';

/**
* Installer Update Sites Model
*
* @package Joomla.Administrator
* @subpackage com_installer
* @since 3.4
*/
class InstallerModelUpdatesites extends InstallerModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 3.4
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'update_site_name', 'name', 'client_id',
'status', 'type', 'folder', 'update_site_id',
'enabled'
);
}

parent::__construct($config);
}

/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 3.4
*/
protected function populateState($ordering = null, $direction = null)
{
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$clientId = $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', '');
$this->setState('filter.client_id', $clientId);

$status = $this->getUserStateFromRequest($this->context . '.filter.enabled', 'filter_enabled', '');
$this->setState('filter.enabled', $status);

$categoryId = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '');
$this->setState('filter.type', $categoryId);

$group = $this->getUserStateFromRequest($this->context . '.filter.group', 'filter_group', '');
$this->setState('filter.group', $group);

parent::populateState('name', 'asc');
}

/**
* Enable/Disable an extension.
*
* @param array &$eid Extension ids to un/publish
* @param int $value Publish value
*
* @return boolean True on success
*
* @since 3.4
*
* @throws Exception on ACL error
*/
public function publish(&$eid = array(), $value = 1)
{
$user = JFactory::getUser();

if (!$user->authorise('core.edit.state', 'com_installer'))
{
throw new Exception(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 403);
}

$result = true;

/*
* Ensure eid is an array of extension ids
*/
if (!is_array($eid))
{
$eid = array($eid);
}

// Get a table object for the extension type
$table = JTable::getInstance('Updatesite');

// Enable the update site in the table and store it in the database
foreach ($eid as $i => $id)
{
$table->load($id);
$table->enabled = $value;

if (!$table->store())
{
$this->setError($table->getError());
$result = false;
}
}

return $result;
}

/**
* Method to get the database query
*
* @return JDatabaseQuery The database query
*
* @since 3.4
*/
protected function getListQuery()
{
$enabled = $this->getState('filter.enabled');
$type = $this->getState('filter.type');
$client = $this->getState('filter.client_id');
$group = $this->getState('filter.group');

$query = JFactory::getDbo()->getQuery(true)
->select(array(
's.update_site_id',
's.name as update_site_name',
's.type as update_site_type',
's.location',
's.enabled',
'e.extension_id',
'e.name',
'e.type',
'e.element',
'e.folder',
'e.client_id',
'e.state',
'e.manifest_cache',
))
->from('#__update_sites AS s')
->innerJoin('#__update_sites_extensions AS se on(se.update_site_id = s.update_site_id)')
->innerJoin('#__extensions AS e ON(e.extension_id = se.extension_id)')
->where('state=0');

if ($enabled != '')
{
$query->where('s.enabled=' . (int)$enabled);
}

if ($type)
{
$query->where('e.type=' . $this->_db->quote($type));
}

if ($client != '')
{
$query->where('client_id=' . (int)$client);
}

if ($group != '' && in_array($type, array('plugin', 'library', '')))
{
$query->where('folder=' . $this->_db->quote($group == '*' ? '' : $group));
}

// Filter by search in id
$search = $this->getState('filter.search');

if (!empty($search) && stripos($search, 'id:') === 0)
{
$query->where('s.update_site_id = ' . (int)substr($search, 3));
}

return $query;
}

/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$ordering = $this->getState('list.ordering');
$search = $this->getState('filter.search');

// Replace slashes so preg_match will work
$search = str_replace('/', ' ', $search);
$db = $this->getDbo();

if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0))
{
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);

if (!empty($search) && (stripos($search, 'id:') !== 0))
{
foreach ($result as $i => $item)
{
if (!preg_match("/$search/i", $item->name) && !preg_match("/$search/i", $item->update_site_name))
{
unset($result[$i]);
}
}
}

JArrayHelper::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, true);

$total = count($result);
$this->cache[$this->getStoreId('getTotal')] = $total;

if ($total < $limitstart)
{
$limitstart = 0;
$this->setState('list.start', 0);
}

return array_slice($result, $limitstart, $limit ? $limit : null);
}

$query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected function addToolbar()
{
JToolbarHelper::custom('update.update', 'upload', 'upload', 'COM_INSTALLER_TOOLBAR_UPDATE', true, false);
JToolbarHelper::custom('update.find', 'refresh', 'refresh', 'COM_INSTALLER_TOOLBAR_FIND_UPDATES', false, false);
JToolbarHelper::custom('update.purge', 'purge', 'purge', 'COM_INSTALLER_TOOLBAR_PURGE', false, false);
JToolbarHelper::divider();

JToolbarHelper::help('JHELP_EXTENSIONS_EXTENSION_MANAGER_UPDATE');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
Loading