- md5
- b923e1f186e2894bc62e3db81b031afa
- sha1
- 8f0182e68824ddebfaabcec24348c40c4cc36d42
- sha256
- dc8eae014adb6e30f9bd3352b59711ec89be1fb1bebfcda117eafbf8cc377481
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
<?php
/**
* @package Joomla.Administrator
* @subpackage com_cpanel
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Cpanel\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Updater\Updater;
/**
* Cpanel System Controller
*
* @since 4.0.0
*/
class SystemController extends BaseController
{
/**
* Ajax target point for reading the specific information
*
* @throws \Exception
*
* @return void
*
* @since 4.0.0
*/
public function loadSystemInfo()
{
$type = $this->input->get('type');
$count = 0;
switch ($type)
{
case 'postinstall':
$count = $this->countItems('com_postinstall', 'Messages');
break;
case 'installationwarnings':
$count = $this->countItems('com_installer', 'Warnings');
break;
case 'checkins':
$count = $this->countItems('com_checkin', 'Checkin');
break;
case 'databaseupdate':
$count = $this->countDatabaseUpdates();
break;
case 'systemupdate':
$count = $this->countSystemUpdates();
break;
case 'extensionupdate':
$count = $this->countExtensionUpdates();
break;
case 'extensiondiscover':
$count = $this->countExtensionDiscover();
break;
default:
/**
* @TODO: Plugin event to allow custom sections to be added (see SystemModel)
*/
throw new \Exception(Text::_('COM_CPANEL_ERROR_DASHBOARD_TYPE_NOT_SUPPORTED'));
}
echo new JsonResponse($count);
}
/**
* Returns the existing database errors of the table structur
*
* @return integer Number of database table errors
*
* @throws \Exception
* @since 4.0.0
*/
protected function countDatabaseUpdates()
{
if (!Factory::getUser()->authorise('core.manage', 'com_installer'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$boot = Factory::getApplication()->bootComponent('com_installer');
$model = $boot->getMVCFactory()->createModel('Database', 'Administrator', ['ignore_request' => true]);
$changeSet = $model->getItems();
$changeSetCount = 0;
foreach ($changeSet as $item)
{
$changeSetCount += $item['errorsCount'];
}
return $changeSetCount;
}
/**
* Returns the version number of the latest update or empty string if system is uptodate
*
* @return string The version number or empty string
*
* @throws \Exception
* @since 4.0.0
*/
protected function countSystemUpdates()
{
if (!Factory::getUser()->authorise('core.manage', 'com_joomlaupdate'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$boot = Factory::getApplication()->bootComponent('com_joomlaupdate');
$model = $boot->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);
$model->refreshUpdates(true);
$joomlaUpdate = $model->getUpdateInformation();
$hasUpdate = $joomlaUpdate['hasUpdate'] ? '‎' . $joomlaUpdate['latest'] : '';
return $hasUpdate;
}
/**
* Returns the number of outdates extensions installed in the system
*
* @return integer Number of available updates
*
* @throws \Exception
* @since 4.0.0
*/
protected function countExtensionUpdates()
{
if (!Factory::getUser()->authorise('core.manage', 'com_installer'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$boot = Factory::getApplication()->bootComponent('com_installer');
$model = $boot->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);
$model->findUpdates();
$items = count($model->getItems());
return $items;
}
/**
* Returns the number of available extensions for installation
*
* @return integer Number of available updates
*
* @throws \Exception
*/
protected function countExtensionDiscover()
{
if (!Factory::getUser()->authorise('core.manage', 'com_installer'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$boot = Factory::getApplication()->bootComponent('com_installer');
$model = $boot->getMVCFactory()->createModel('Discover', 'Administrator', ['ignore_request' => true]);
$model->discover();
$items = count($model->getItems());
return $items;
}
/**
* Generic getItems counter for different calls
*
* @param string $extension The extension to check and authorise for
* @param string $modelName The Model to load
*
* @return integer The number of items
*
* @throws \Exception
* @since 4.0.0
*/
protected function countItems($extension, $modelName)
{
if (!Factory::getUser()->authorise('core.manage', $extension))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$boot = Factory::getApplication()->bootComponent($extension);
$model = $boot->getMVCFactory()->createModel($modelName, 'Administrator', ['ignore_request' => true]);
$items = count($model->getItems());
return $items;
}
}
No other release has this exact content. See every version of this file.