primo commit
This commit is contained in:
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Component\Installer\Administrator\Model\DatabaseModel;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer Database Controller
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
class DatabaseController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Tries to fix missing database updates
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 2.5
|
||||
* @todo Purge updates has to be replaced with an events system
|
||||
*/
|
||||
public function fix()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Get items to fix the database.
|
||||
$cid = (array) $this->input->get('cid', [], 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$cid = array_filter($cid);
|
||||
|
||||
if (empty($cid)) {
|
||||
$this->app->getLogger()->warning(
|
||||
Text::_(
|
||||
'COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'
|
||||
),
|
||||
['category' => 'jerror']
|
||||
);
|
||||
} else {
|
||||
/** @var DatabaseModel $model */
|
||||
$model = $this->getModel('Database');
|
||||
$model->fix($cid);
|
||||
|
||||
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $updateModel */
|
||||
$updateModel = $this->app->bootComponent('com_joomlaupdate')
|
||||
->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);
|
||||
$updateModel->purge();
|
||||
|
||||
// Refresh versionable assets cache
|
||||
$this->app->flushAssets();
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=database', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the data for a badge in a menu item via JSON
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMenuBadgeData()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
|
||||
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
|
||||
}
|
||||
|
||||
$model = $this->getModel('Database');
|
||||
|
||||
$changeSet = $model->getItems();
|
||||
|
||||
$changeSetCount = 0;
|
||||
|
||||
foreach ($changeSet as $item) {
|
||||
$changeSetCount += $item['errorsCount'];
|
||||
}
|
||||
|
||||
echo new JsonResponse($changeSetCount);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Discover Installation Controller
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class DiscoverController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Refreshes the cache of discovered extensions.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
$this->checkToken('request');
|
||||
|
||||
/** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */
|
||||
$model = $this->getModel('discover');
|
||||
$model->discover();
|
||||
|
||||
if (!$model->getTotal()) {
|
||||
$this->setMessage(Text::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_DISCOVERED'), 'info');
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=discover', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a discovered extension.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$this->checkToken();
|
||||
|
||||
/** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */
|
||||
$model = $this->getModel('discover');
|
||||
$model->discover_install();
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=discover', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean out the discovered extension cache.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function purge()
|
||||
{
|
||||
$this->checkToken('request');
|
||||
|
||||
/** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */
|
||||
$model = $this->getModel('discover');
|
||||
$model->purge();
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=discover', false), $model->_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the data for a badge in a menu item via JSON
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getMenuBadgeData()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
|
||||
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
|
||||
}
|
||||
|
||||
$model = $this->getModel('Discover');
|
||||
|
||||
echo new JsonResponse($model->getTotal());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached
|
||||
* @param array $urlparams An array of safe URL parameters and their variable types.
|
||||
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
|
||||
*
|
||||
* @return static This object to support chaining.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = false)
|
||||
{
|
||||
// Get the document object.
|
||||
$document = $this->app->getDocument();
|
||||
|
||||
// Set the default view name and format from the Request.
|
||||
$vName = $this->input->get('view', 'install');
|
||||
$vFormat = $document->getType();
|
||||
$lName = $this->input->get('layout', 'default', 'string');
|
||||
$id = $this->input->getInt('update_site_id');
|
||||
|
||||
// Check for edit form.
|
||||
if ($vName === 'updatesite' && $lName === 'edit' && !$this->checkEditId('com_installer.edit.updatesite', $id)) {
|
||||
// Somehow the person just went to the form - we don't allow that.
|
||||
if (!\count($this->app->getMessageQueue())) {
|
||||
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=updatesites', false));
|
||||
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
// Get and render the view.
|
||||
if ($view = $this->getView($vName, $vFormat)) {
|
||||
// Get the model for the view.
|
||||
$model = $this->getModel($vName);
|
||||
|
||||
// Push the model into the view (as default).
|
||||
$view->setModel($model, true);
|
||||
$view->setLayout($lName);
|
||||
|
||||
// Push document object into the view.
|
||||
$view->document = $document;
|
||||
|
||||
$view->display();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the data for a badge in a menu item via JSON
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMenuBadgeData()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
|
||||
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
|
||||
}
|
||||
|
||||
$model = $this->getModel('Warnings');
|
||||
|
||||
echo new JsonResponse(\count($model->getItems()));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Access\Exception\NotAllowed;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer controller for Joomla! installer class.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class InstallController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Install an extension.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
if (!$this->app->getIdentity()->authorise('core.admin')) {
|
||||
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
/** @var \Joomla\Component\Installer\Administrator\Model\InstallModel $model */
|
||||
$model = $this->getModel('install');
|
||||
|
||||
// @todo: Reset the users acl here as well to kill off any missing bits.
|
||||
$result = $model->install();
|
||||
|
||||
$app = $this->app;
|
||||
$redirect_url = $app->getUserState('com_installer.redirect_url');
|
||||
$return = $this->input->getBase64('return');
|
||||
|
||||
if (!$redirect_url && $return) {
|
||||
$redirect_url = base64_decode($return);
|
||||
}
|
||||
|
||||
// Don't redirect to an external URL.
|
||||
if ($redirect_url && !Uri::isInternal($redirect_url)) {
|
||||
$redirect_url = '';
|
||||
}
|
||||
|
||||
if (empty($redirect_url)) {
|
||||
$redirect_url = Route::_('index.php?option=com_installer&view=install', false);
|
||||
} else {
|
||||
// Wipe out the user state when we're going to redirect.
|
||||
$app->setUserState('com_installer.redirect_url', '');
|
||||
$app->setUserState('com_installer.message', '');
|
||||
$app->setUserState('com_installer.extension_message', '');
|
||||
}
|
||||
|
||||
$this->setRedirect($redirect_url);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install an extension from drag & drop ajax upload.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function ajax_upload()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
|
||||
|
||||
if (!$this->app->getIdentity()->authorise('core.admin')) {
|
||||
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
$message = $this->app->getUserState('com_installer.message');
|
||||
|
||||
// Do install
|
||||
$result = $this->install();
|
||||
|
||||
// Get redirect URL
|
||||
$redirect = $this->redirect;
|
||||
|
||||
// Push message queue to session because we will redirect page by \Javascript, not $app->redirect().
|
||||
// The "application.queue" is only set in redirect() method, so we must manually store it.
|
||||
$this->app->getSession()->set('application.queue', $this->app->getMessageQueue());
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo new JsonResponse(['redirect' => $redirect], $message, !$result);
|
||||
|
||||
$this->app->close();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Component\Installer\Administrator\Model\ManageModel;
|
||||
use Joomla\Input\Input;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer Manage Controller
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class ManageController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?Input $input Input
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
|
||||
$this->registerTask('unpublish', 'publish');
|
||||
$this->registerTask('publish', 'publish');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable an extension (if supported).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function publish()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$ids = (array) $this->input->get('cid', [], 'int');
|
||||
$values = ['publish' => 1, 'unpublish' => 0];
|
||||
$task = $this->getTask();
|
||||
$value = ArrayHelper::getValue($values, $task, 0, 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$ids = array_filter($ids);
|
||||
|
||||
if (empty($ids)) {
|
||||
$this->setMessage(Text::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'), 'warning');
|
||||
} else {
|
||||
/** @var ManageModel $model */
|
||||
$model = $this->getModel('manage');
|
||||
|
||||
// Change the state of the records.
|
||||
if (!$model->publish($ids, $value)) {
|
||||
$this->setMessage(implode('<br>', $model->getErrors()), 'warning');
|
||||
} else {
|
||||
if ($value == 1) {
|
||||
$ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED';
|
||||
} else {
|
||||
$ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED';
|
||||
}
|
||||
|
||||
$this->setMessage(Text::plural($ntext, \count($ids)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an extension (Uninstall).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$eid = (array) $this->input->get('cid', [], 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$eid = array_filter($eid);
|
||||
|
||||
if (!empty($eid)) {
|
||||
/** @var ManageModel $model */
|
||||
$model = $this->getModel('manage');
|
||||
|
||||
$model->remove($eid);
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the cached metadata about an extension.
|
||||
*
|
||||
* Useful for debugging and testing purposes when the XML file might change.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$uid = (array) $this->input->get('cid', [], 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$uid = array_filter($uid);
|
||||
|
||||
if (!empty($uid)) {
|
||||
/** @var ManageModel $model */
|
||||
$model = $this->getModel('manage');
|
||||
|
||||
$model->refresh($uid);
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the changelog for a given extension. Outputs HTML encoded in JSON.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function loadChangelog()
|
||||
{
|
||||
/** @var ManageModel $model */
|
||||
$model = $this->getModel('manage');
|
||||
|
||||
$eid = $this->input->get('eid', 0, 'int');
|
||||
$source = $this->input->get('source', 'manage', 'string');
|
||||
|
||||
if (!$eid) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = $model->loadChangelog($eid, $source);
|
||||
|
||||
echo (new JsonResponse($output));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the changelog for a given extension. Outputs HTML.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function loadChangelogRaw()
|
||||
{
|
||||
/** @var ManageModel $model */
|
||||
$model = $this->getModel('manage');
|
||||
|
||||
$eid = $this->input->get('eid', 0, 'int');
|
||||
$source = $this->input->get('source', 'manage', 'string');
|
||||
|
||||
if (!$eid) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo $model->loadChangelog($eid, $source);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Updater\Updater;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Installer\Administrator\Model\UpdateModel;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer Update Controller
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class UpdateController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Update a set of extensions.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
/** @var UpdateModel $model */
|
||||
$model = $this->getModel('update');
|
||||
|
||||
$uid = (array) $this->input->get('cid', [], 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$uid = array_filter($uid);
|
||||
|
||||
// Get the minimum stability.
|
||||
$params = ComponentHelper::getComponent('com_installer')->getParams();
|
||||
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
|
||||
|
||||
$model->update($uid, $minimum_stability);
|
||||
|
||||
$app = $this->app;
|
||||
$redirect_url = $app->getUserState('com_installer.redirect_url');
|
||||
|
||||
// Don't redirect to an external URL.
|
||||
if ($redirect_url && !Uri::isInternal($redirect_url)) {
|
||||
$redirect_url = '';
|
||||
}
|
||||
|
||||
if (empty($redirect_url)) {
|
||||
$redirect_url = Route::_('index.php?option=com_installer&view=update', false);
|
||||
} else {
|
||||
// Wipe out the user state when we're going to redirect.
|
||||
$app->setUserState('com_installer.redirect_url', '');
|
||||
$app->setUserState('com_installer.message', '');
|
||||
$app->setUserState('com_installer.extension_message', '');
|
||||
}
|
||||
|
||||
$this->setRedirect($redirect_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find new updates.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function find()
|
||||
{
|
||||
$this->checkToken('request');
|
||||
|
||||
// Get the caching duration.
|
||||
$params = ComponentHelper::getComponent('com_installer')->getParams();
|
||||
$cache_timeout = (int) $params->get('cachetimeout', 6);
|
||||
$cache_timeout = 3600 * $cache_timeout;
|
||||
|
||||
// Get the minimum stability.
|
||||
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
|
||||
|
||||
// Find updates.
|
||||
/** @var UpdateModel $model */
|
||||
$model = $this->getModel('update');
|
||||
|
||||
// Purge the table before checking again
|
||||
$model->purge();
|
||||
|
||||
$disabledUpdateSites = $model->getDisabledUpdateSites();
|
||||
|
||||
if ($disabledUpdateSites) {
|
||||
$updateSitesUrl = Route::_('index.php?option=com_installer&view=updatesites');
|
||||
$this->app->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_UPDATE_SITES_COUNT_CHECK', $updateSitesUrl), 'warning');
|
||||
}
|
||||
|
||||
$model->findUpdates(0, $cache_timeout, $minimum_stability);
|
||||
|
||||
if (0 === $model->getTotal()) {
|
||||
$this->app->enqueueMessage(Text::_('COM_INSTALLER_MSG_UPDATE_NOUPDATES'), 'info');
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=update', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and report updates in \JSON format, for AJAX requests
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function ajax()
|
||||
{
|
||||
$app = $this->app;
|
||||
|
||||
if (!Session::checkToken('get')) {
|
||||
$app->setHeader('status', 403, true);
|
||||
$app->sendHeaders();
|
||||
echo Text::_('JINVALID_TOKEN_NOTICE');
|
||||
$app->close();
|
||||
}
|
||||
|
||||
// Close the session before we make a long running request
|
||||
$app->getSession()->abort();
|
||||
|
||||
$eid = $this->input->getInt('eid', 0);
|
||||
$skip = $this->input->get('skip', [], 'array');
|
||||
$cache_timeout = $this->input->getInt('cache_timeout', 0);
|
||||
$minimum_stability = $this->input->getInt('minimum_stability', -1);
|
||||
|
||||
$params = ComponentHelper::getComponent('com_installer')->getParams();
|
||||
|
||||
if ($cache_timeout == 0) {
|
||||
$cache_timeout = (int) $params->get('cachetimeout', 6);
|
||||
$cache_timeout = 3600 * $cache_timeout;
|
||||
}
|
||||
|
||||
if ($minimum_stability < 0) {
|
||||
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
|
||||
}
|
||||
|
||||
/** @var UpdateModel $model */
|
||||
$model = $this->getModel('update');
|
||||
$model->findUpdates($eid, $cache_timeout, $minimum_stability);
|
||||
|
||||
$model->setState('list.start', 0);
|
||||
$model->setState('list.limit', 0);
|
||||
|
||||
if ($eid != 0) {
|
||||
$model->setState('filter.extension_id', $eid);
|
||||
}
|
||||
|
||||
$updates = $model->getItems();
|
||||
|
||||
if (!empty($skip)) {
|
||||
$unfiltered_updates = $updates;
|
||||
$updates = [];
|
||||
|
||||
foreach ($unfiltered_updates as $update) {
|
||||
if (!\in_array($update->extension_id, $skip)) {
|
||||
$updates[] = $update;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($updates);
|
||||
|
||||
$app->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the data for a badge in a menu item via JSON
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMenuBadgeData()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
|
||||
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
|
||||
}
|
||||
|
||||
$model = $this->getModel('Update');
|
||||
|
||||
echo new JsonResponse($model->getTotal());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Controller for a single update site
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class UpdatesiteController extends FormController
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
*
|
||||
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Installer\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\AdminController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Input\Input;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Installer Update Sites Controller
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_installer
|
||||
* @since 3.4
|
||||
*/
|
||||
class UpdatesitesController extends AdminController
|
||||
{
|
||||
/**
|
||||
* The prefix to use with controller messages.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $text_prefix = 'COM_INSTALLER_UPDATESITES';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?Input $input Input
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
|
||||
$this->registerTask('unpublish', 'publish');
|
||||
$this->registerTask('publish', 'publish');
|
||||
$this->registerTask('delete', 'delete');
|
||||
$this->registerTask('rebuild', 'rebuild');
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy for getModel.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config The array of possible config values. Optional.
|
||||
*
|
||||
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getModel($name = 'Updatesite', $prefix = 'Administrator', $config = ['ignore_request' => true])
|
||||
{
|
||||
return parent::getModel($name, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable an extension (if supported).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @throws \Exception on error
|
||||
*/
|
||||
public function publish()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$ids = (array) $this->input->get('cid', [], 'int');
|
||||
$values = ['publish' => 1, 'unpublish' => 0];
|
||||
$task = $this->getTask();
|
||||
$value = ArrayHelper::getValue($values, $task, 0, 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$ids = array_filter($ids);
|
||||
|
||||
if (empty($ids)) {
|
||||
throw new \Exception(Text::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500);
|
||||
}
|
||||
|
||||
// Get the model.
|
||||
/** @var \Joomla\Component\Installer\Administrator\Model\UpdatesitesModel $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(Text::plural($ntext, \count($ids)));
|
||||
|
||||
$this->setRedirect(Route::_('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.
|
||||
$this->checkToken();
|
||||
|
||||
$ids = (array) $this->input->get('cid', [], 'int');
|
||||
|
||||
// Remove zero values resulting from input filter
|
||||
$ids = array_filter($ids);
|
||||
|
||||
if (empty($ids)) {
|
||||
throw new \Exception(Text::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500);
|
||||
}
|
||||
|
||||
// Delete the records.
|
||||
$this->getModel('Updatesites')->delete($ids);
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=updatesites', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild update sites tables.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
public function rebuild()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Rebuild the update sites.
|
||||
$this->getModel('Updatesites')->rebuild();
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_installer&view=updatesites', false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user