- md5
- a596e11e3cbe01b4c6e948a765d52006
- sha1
- 0a5a51b2996207903b8bae0e471d405eca0e0295
- sha256
- 305840a2d620a5389a74615b985c9dd97945e187311eedf47f39b5fce9fe3dc6
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Installer\Administrator\Model;
\defined('_JEXEC') or die;
use Joomla\CMS\Changelog\Changelog;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Extension;
use Joomla\Component\Templates\Administrator\Table\StyleTable;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
/**
* Installer Manage Model
*
* @since 1.5
*/
class ManageModel extends InstallerModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
*
* @see \Joomla\CMS\MVC\Model\ListModel
* @since 1.6
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'status',
'name',
'client_id',
'client', 'client_translated',
'type', 'type_translated',
'folder', 'folder_translated',
'package_id',
'extension_id',
);
}
parent::__construct($config, $factory);
}
/**
* 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
*
* @throws \Exception
*
* @since 1.6
*/
protected function populateState($ordering = 'name', $direction = 'asc')
{
$app = Factory::getApplication();
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.status', $this->getUserStateFromRequest($this->context . '.filter.status', 'filter_status', '', 'string'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));
$this->setState('filter.core', $this->getUserStateFromRequest($this->context . '.filter.core', 'filter_core', '', 'string'));
$this->setState('message', $app->getUserState('com_installer.message'));
$this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
$app->setUserState('com_installer.message', '');
$app->setUserState('com_installer.extension_message', '');
parent::populateState($ordering, $direction);
}
/**
* Enable/Disable an extension.
*
* @param array $eid Extension ids to un/publish
* @param int $value Publish value
*
* @return boolean True on success
*
* @throws \Exception
*
* @since 1.5
*/
public function publish(&$eid = array(), $value = 1)
{
if (!Factory::getUser()->authorise('core.edit.state', 'com_installer'))
{
Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error');
return false;
}
$result = true;
/*
* Ensure eid is an array of extension ids
* TODO: If it isn't an array do we want to set an error and fail?
*/
if (!is_array($eid))
{
$eid = array($eid);
}
// Get a table object for the extension type
$table = new Extension($this->getDbo());
// Enable the extension in the table and store it in the database
foreach ($eid as $i => $id)
{
$table->load($id);
if ($table->type == 'template')
{
$style = new StyleTable($this->getDbo());
if ($style->load(array('template' => $table->element, 'client_id' => $table->client_id, 'home' => 1)))
{
Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED'), 'notice');
unset($eid[$i]);
continue;
}
}
if ($table->protected == 1)
{
$result = false;
Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error');
}
else
{
$table->enabled = $value;
}
$context = $this->option . '.' . $this->name;
PluginHelper::importPlugin('extension');
Factory::getApplication()->triggerEvent('onExtensionChangeState', array($context, $eid, $value));
if (!$table->store())
{
$this->setError($table->getError());
$result = false;
}
}
// Clear the cached extension data and menu cache
$this->cleanCache('_system', 0);
$this->cleanCache('_system', 1);
$this->cleanCache('com_modules', 0);
$this->cleanCache('com_modules', 1);
$this->cleanCache('mod_menu', 0);
$this->cleanCache('mod_menu', 1);
return $result;
}
/**
* Refreshes the cached manifest information for an extension.
*
* @param int|int[] $eid extension identifier (key in #__extensions)
*
* @return boolean result of refresh
*
* @since 1.6
*/
public function refresh($eid)
{
if (!is_array($eid))
{
$eid = array($eid => 0);
}
// Get an installer object for the extension type
$installer = Installer::getInstance();
$result = 0;
// Uninstall the chosen extensions
foreach ($eid as $id)
{
$result |= $installer->refreshManifestCache($id);
}
return $result;
}
/**
* Remove (uninstall) an extension
*
* @param array $eid An array of identifiers
*
* @return boolean True on success
*
* @throws \Exception
*
* @since 1.5
*/
public function remove($eid = array())
{
if (!Factory::getUser()->authorise('core.delete', 'com_installer'))
{
Factory::getApplication()->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'error');
return false;
}
/*
* Ensure eid is an array of extension ids in the form id => client_id
* TODO: If it isn't an array do we want to set an error and fail?
*/
if (!is_array($eid))
{
$eid = array($eid => 0);
}
// Get an installer object for the extension type
$installer = Installer::getInstance();
$row = new \Joomla\CMS\Table\Extension($this->getDbo());
// Uninstall the chosen extensions
$msgs = array();
$result = false;
foreach ($eid as $id)
{
$id = trim($id);
$row->load($id);
$result = false;
// Do not allow to uninstall locked extensions.
if ((int) $row->locked === 1)
{
$msgs[] = Text::sprintf('COM_INSTALLER_UNINSTALL_ERROR_LOCKED_EXTENSION', $row->name, $id);
continue;
}
$langstring = 'COM_INSTALLER_TYPE_TYPE_' . strtoupper($row->type);
$rowtype = Text::_($langstring);
if (strpos($rowtype, $langstring) !== false)
{
$rowtype = $row->type;
}
if ($row->type)
{
$result = $installer->uninstall($row->type, $id);
// Build an array of extensions that failed to uninstall
if ($result === false)
{
// There was an error in uninstalling the package
$msgs[] = Text::sprintf('COM_INSTALLER_UNINSTALL_ERROR', $rowtype);
continue;
}
// Package uninstalled successfully
$msgs[] = Text::sprintf('COM_INSTALLER_UNINSTALL_SUCCESS', $rowtype);
$result = true;
continue;
}
// There was an error in uninstalling the package
$msgs[] = Text::sprintf('COM_INSTALLER_UNINSTALL_ERROR', $rowtype);
}
$msg = implode('<br>', $msgs);
$app = Factory::getApplication();
$app->enqueueMessage($msg);
$this->setState('action', 'remove');
$this->setState('name', $installer->get('name'));
$app->setUserState('com_installer.message', $installer->message);
$app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
// Clear the cached extension data and menu cache
$this->cleanCache('_system', 0);
$this->cleanCache('_system', 1);
$this->cleanCache('com_modules', 0);
$this->cleanCache('com_modules', 1);
$this->cleanCache('com_plugins', 0);
$this->cleanCache('com_plugins', 1);
$this->cleanCache('mod_menu', 0);
$this->cleanCache('mod_menu', 1);
return $result;
}
/**
* Method to get the database query
*
* @return DatabaseQuery The database query
*
* @since 1.6
*/
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('*')
->select('2*protected+(1-protected)*enabled AS status')
->from('#__extensions')
->where('state = 0');
// Process select filters.
$status = $this->getState('filter.status');
$type = $this->getState('filter.type');
$clientId = $this->getState('filter.client_id');
$folder = $this->getState('filter.folder');
$core = $this->getState('filter.core');
if ($status !== '')
{
if ($status === '2')
{
$query->where('protected = 1');
}
elseif ($status === '3')
{
$query->where('protected = 0');
}
else
{
$status = (int) $status;
$query->where($db->quoteName('protected') . ' = 0')
->where($db->quoteName('enabled') . ' = :status')
->bind(':status', $status, ParameterType::INTEGER);
}
}
if ($type)
{
$query->where($db->quoteName('type') . ' = :type')
->bind(':type', $type);
}
if ($clientId !== '')
{
$clientId = (int) $clientId;
$query->where($db->quoteName('client_id') . ' = :clientid')
->bind(':clientid', $clientId, ParameterType::INTEGER);
}
if ($folder !== '')
{
$folder = $folder === '*' ? '' : $folder;
$query->where($db->quoteName('folder') . ' = :folder')
->bind(':folder', $folder);
}
if ($core !== '')
{
$coreExtensions = ExtensionHelper::getCoreExtensions();
$elements = array();
foreach ($coreExtensions as $extension)
{
$elements[] = $extension[1];
}
if ($elements)
{
if ($core === '1')
{
$query->whereIn($db->quoteName('element'), $elements, ParameterType::STRING);
}
elseif ($core === '0')
{
$query->whereNotIn($db->quoteName('element'), $elements, ParameterType::STRING);
}
}
}
// Process search filter (extension id).
$search = $this->getState('filter.search');
if (!empty($search) && stripos($search, 'id:') === 0)
{
$ids = (int) substr($search, 3);
$query->where($db->quoteName('extension_id') . ' = :eid')
->bind(':eid', $ids, ParameterType::INTEGER);
}
// Note: The search for name, ordering and pagination are processed by the parent InstallerModel class (in extension.php).
return $query;
}
/**
* Load the changelog details for a given extension.
*
* @param integer $eid The extension ID
* @param string $source The view the changelog is for, this is used to determine which version number to show
*
* @return string The output to show in the modal.
*
* @since 4.0.0
*/
public function loadChangelog($eid, $source)
{
// Get the changelog URL
$eid = (int) $eid;
$db = $this->getDbo();
$query = $db->getQuery(true)
->select(
$db->quoteName(
[
'extensions.element',
'extensions.type',
'extensions.folder',
'extensions.changelogurl',
'extensions.manifest_cache',
'extensions.client_id'
]
)
)
->select($db->quoteName('updates.version', 'updateVersion'))
->from($db->quoteName('#__extensions', 'extensions'))
->join(
'LEFT',
$db->quoteName('#__updates', 'updates'),
$db->quoteName('updates.extension_id') . ' = ' . $db->quoteName('extensions.extension_id')
)
->where($db->quoteName('extensions.extension_id') . ' = :eid')
->bind(':eid', $eid, ParameterType::INTEGER);
$db->setQuery($query);
$extensions = $db->loadObjectList();
$this->translate($extensions);
$extension = array_shift($extensions);
if (!$extension->changelogurl)
{
return '';
}
$changelog = new Changelog;
$changelog->setVersion($source === 'manage' ? $extension->version : $extension->updateVersion);
$changelog->loadFromXml($extension->changelogurl);
// Read all the entries
$entries = array(
'security' => array(),
'fix' => array(),
'addition' => array(),
'change' => array(),
'remove' => array(),
'language' => array(),
'note' => array()
);
array_walk(
$entries,
function (&$value, $name) use ($changelog) {
if ($field = $changelog->get($name))
{
$value = $changelog->get($name)->data;
}
}
);
$layout = new FileLayout('joomla.installer.changelog');
$output = $layout->render($entries);
return $output;
}
}
No other release has this exact content. See every version of this file.