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 @@ -71,10 +71,6 @@ public function publish()
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));
}

Expand Down
82 changes: 60 additions & 22 deletions administrator/components/com_installer/models/updatesites.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected function populateState($ordering = 'name', $direction = 'asc')
}

/**
* Enable/Disable an extension.
* Enable/Disable an update site.
*
* @param array &$eid Extension ids to un/publish
* @param array &$ids Update site ids to un/publish
* @param int $value Publish value
*
* @return boolean True on success
Expand All @@ -82,7 +82,7 @@ protected function populateState($ordering = 'name', $direction = 'asc')
*
* @throws Exception on ACL error
*/
public function publish(&$eid = array(), $value = 1)
public function publish(&$ids = array(), $value = 1)
{
if (!JFactory::getUser()->authorise('core.edit.state', 'com_installer'))
{
Expand All @@ -91,26 +91,56 @@ public function publish(&$eid = array(), $value = 1)

$result = true;

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

// Get a table object for the extension type
$table = JTable::getInstance('Updatesite');
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$count = 0;

// Gets the update site extensions.
$query = $db->getQuery(true)
->select($db->qn(array('update_site_id', 'extension_id')))
->from($db->qn('#__update_sites_extensions'))
->where($db->qn('update_site_id') . ' IN (' . implode(', ', $ids) . ')');
$db->setQuery($query);
$updateSitesExtensions = $db->loadObjectList('update_site_id');

// Get the table object for the extension and update site.
$extensionTable = JTable::getInstance('Extension');
$updateSiteTable = JTable::getInstance('Updatesite');

// Enable the update site in the table and store it in the database
foreach ($eid as $i => $id)
foreach ($ids as $i => $id)
{
$table->load($id);
$table->enabled = $value;
// Don't allow to (un)published protected extensions update sites.
if ($extensionTable->load($updateSitesExtensions[$id]->extension_id) && $extensionTable->protected)
{
$app->enqueueMessage(JText::sprintf('COM_INSTALLER_MSG_UPDATESITES_CANNOT_DISABLE_PROTECTED', $extensionTable->name), 'error');
unset($ids[$i]);
continue;
}

$updateSiteTable->load($id);
$updateSiteTable->enabled = $value;

if (!$table->store())
if (!$updateSiteTable->store())
{
$this->setError($table->getError());
$result = false;
$app->enqueueMessage($updateSiteTable->getError(), 'error');
unset($ids[$i]);
continue;
}

$count++;
}

if ($count > 0)
{
$ntext = ($value == 0) ? 'COM_INSTALLER_N_UPDATESITES_UNPUBLISHED' : 'COM_INSTALLER_N_UPDATESITES_PUBLISHED';
$app->enqueueMessage(JText::plural($ntext, count($ids)), 'message');
}

return $result;
Expand Down Expand Up @@ -140,9 +170,8 @@ public function delete($ids = array())
$ids = array($ids);
}

$db = JFactory::getDbo();
$app = JFactory::getApplication();

$db = JFactory::getDbo();
$app = JFactory::getApplication();
$count = 0;

// Gets the update site names.
Expand All @@ -153,16 +182,24 @@ public function delete($ids = array())
$db->setQuery($query);
$updateSitesNames = $db->loadObjectList('update_site_id');

// Gets Joomla core update sites Ids.
$joomlaUpdateSitesIds = $this->getJoomlaUpdateSitesIds(0);
// Gets the update site extensions.
$query = $db->getQuery(true)
->select($db->qn(array('update_site_id', 'extension_id')))
->from($db->qn('#__update_sites_extensions'))
->where($db->qn('update_site_id') . ' IN (' . implode(', ', $ids) . ')');
$db->setQuery($query);
$updateSitesExtensions = $db->loadObjectList('update_site_id');

// Get the table object for the extension and update site.
$extensionTable = JTable::getInstance('Extension');

// Enable the update site in the table and store it in the database
foreach ($ids as $i => $id)
{
// Don't allow to delete Joomla Core update sites.
if (in_array((int) $id, $joomlaUpdateSitesIds))
// Don't allow to delete protected extensions update sites.
if ($extensionTable->load($updateSitesExtensions[$id]->extension_id) && $extensionTable->protected)
{
$app->enqueueMessage(JText::sprintf('COM_INSTALLER_MSG_UPDATESITES_DELETE_CANNOT_DELETE', $updateSitesNames[$id]->name), 'error');
$app->enqueueMessage(JText::sprintf('COM_INSTALLER_MSG_UPDATESITES_CANNOT_DELETE_PROTECTED', $extensionTable->name), 'error');
continue;
}

Expand Down Expand Up @@ -419,6 +456,7 @@ protected function getListQuery()
'e.folder',
'e.client_id',
'e.state',
'e.protected',
'e.manifest_cache',
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@
<?php if (!$item->element) : ?>
<strong>X</strong>
<?php else : ?>
<?php echo JHtml::_('InstallerHtml.Updatesites.state', $item->enabled, $i, $item->enabled < 2, 'cb'); ?>
<?php if ($item->protected) : ?>
<a class="btn btn-micro disabled"><span class="icon-lock"></span></a>
<?php else : ?>
<?php echo JHtml::_('InstallerHtml.Updatesites.state', $item->enabled, $i, $item->enabled < 2, 'cb'); ?>
<?php endif; ?>
<?php endif; ?>
</td>
<td>
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ COM_INSTALLER_MSG_UPDATE_NOUPDATES="There are no updates available at the moment
COM_INSTALLER_MSG_UPDATE_SITES_COUNT_CHECK="Some update sites are disabled. You may want to check the <a href="_QQ_"%s"_QQ_">Update Sites Manager</a>."
COM_INSTALLER_MSG_UPDATE_SUCCESS="Updating %s was successful."
COM_INSTALLER_MSG_UPDATE_UPDATE="Update"
COM_INSTALLER_MSG_UPDATESITES_CANNOT_DELETE_PROTECTED="Cannot delete update sites of protected extensions: %s."
COM_INSTALLER_MSG_UPDATESITES_CANNOT_DISABLE_PROTECTED="Cannot enable or disable update sites of protected extensions: %s."
COM_INSTALLER_MSG_UPDATESITES_DELETE_ERROR="An error has occurred while trying to delete "_QQ_"%s"_QQ_" update site: %s."
COM_INSTALLER_MSG_UPDATESITES_DELETE_CANNOT_DELETE="%s update site cannot be deleted."
COM_INSTALLER_MSG_UPDATESITES_N_DELETE_UPDATESITES_DELETED="%s update sites have been deleted."
Expand Down