[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_installer/src/Controller/ -> UpdateController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_installer
   6   *
   7   * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Installer\Administrator\Controller;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\Controller\BaseController;
  16  use Joomla\CMS\Response\JsonResponse;
  17  use Joomla\CMS\Router\Route;
  18  use Joomla\CMS\Session\Session;
  19  use Joomla\CMS\Updater\Updater;
  20  use Joomla\CMS\Uri\Uri;
  21  use Joomla\Component\Installer\Administrator\Model\UpdateModel;
  22  
  23  // phpcs:disable PSR1.Files.SideEffects
  24  \defined('_JEXEC') or die;
  25  // phpcs:enable PSR1.Files.SideEffects
  26  
  27  /**
  28   * Installer Update Controller
  29   *
  30   * @since  1.6
  31   */
  32  class UpdateController extends BaseController
  33  {
  34      /**
  35       * Update a set of extensions.
  36       *
  37       * @return  void
  38       *
  39       * @since   1.6
  40       */
  41      public function update()
  42      {
  43          // Check for request forgeries.
  44          $this->checkToken();
  45  
  46          /** @var UpdateModel $model */
  47          $model = $this->getModel('update');
  48  
  49          $uid = (array) $this->input->get('cid', array(), 'int');
  50  
  51          // Remove zero values resulting from input filter
  52          $uid = array_filter($uid);
  53  
  54          // Get the minimum stability.
  55          $params        = ComponentHelper::getComponent('com_installer')->getParams();
  56          $minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
  57  
  58          $model->update($uid, $minimum_stability);
  59  
  60          $app          = $this->app;
  61          $redirect_url = $app->getUserState('com_installer.redirect_url');
  62  
  63          // Don't redirect to an external URL.
  64          if (!Uri::isInternal($redirect_url)) {
  65              $redirect_url = '';
  66          }
  67  
  68          if (empty($redirect_url)) {
  69              $redirect_url = Route::_('index.php?option=com_installer&view=update', false);
  70          } else {
  71              // Wipe out the user state when we're going to redirect.
  72              $app->setUserState('com_installer.redirect_url', '');
  73              $app->setUserState('com_installer.message', '');
  74              $app->setUserState('com_installer.extension_message', '');
  75          }
  76  
  77          $this->setRedirect($redirect_url);
  78      }
  79  
  80      /**
  81       * Find new updates.
  82       *
  83       * @return  void
  84       *
  85       * @since   1.6
  86       */
  87      public function find()
  88      {
  89          $this->checkToken('request');
  90  
  91          // Get the caching duration.
  92          $params        = ComponentHelper::getComponent('com_installer')->getParams();
  93          $cache_timeout = (int) $params->get('cachetimeout', 6);
  94          $cache_timeout = 3600 * $cache_timeout;
  95  
  96          // Get the minimum stability.
  97          $minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
  98  
  99          // Find updates.
 100          /** @var UpdateModel $model */
 101          $model = $this->getModel('update');
 102  
 103          // Purge the table before checking again
 104          $model->purge();
 105  
 106          $disabledUpdateSites = $model->getDisabledUpdateSites();
 107  
 108          if ($disabledUpdateSites) {
 109              $updateSitesUrl = Route::_('index.php?option=com_installer&view=updatesites');
 110              $this->app->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_UPDATE_SITES_COUNT_CHECK', $updateSitesUrl), 'warning');
 111          }
 112  
 113          $model->findUpdates(0, $cache_timeout, $minimum_stability);
 114  
 115          if (0 === $model->getTotal()) {
 116              $this->app->enqueueMessage(Text::_('COM_INSTALLER_MSG_UPDATE_NOUPDATES'), 'info');
 117          }
 118  
 119          $this->setRedirect(Route::_('index.php?option=com_installer&view=update', false));
 120      }
 121  
 122      /**
 123       * Fetch and report updates in \JSON format, for AJAX requests
 124       *
 125       * @return void
 126       *
 127       * @since 2.5
 128       */
 129      public function ajax()
 130      {
 131          $app = $this->app;
 132  
 133          if (!Session::checkToken('get')) {
 134              $app->setHeader('status', 403, true);
 135              $app->sendHeaders();
 136              echo Text::_('JINVALID_TOKEN_NOTICE');
 137              $app->close();
 138          }
 139  
 140          // Close the session before we make a long running request
 141          $app->getSession()->abort();
 142  
 143          $eid               = $this->input->getInt('eid', 0);
 144          $skip              = $this->input->get('skip', array(), 'array');
 145          $cache_timeout     = $this->input->getInt('cache_timeout', 0);
 146          $minimum_stability = $this->input->getInt('minimum_stability', -1);
 147  
 148          $params        = ComponentHelper::getComponent('com_installer')->getParams();
 149  
 150          if ($cache_timeout == 0) {
 151              $cache_timeout = (int) $params->get('cachetimeout', 6);
 152              $cache_timeout = 3600 * $cache_timeout;
 153          }
 154  
 155          if ($minimum_stability < 0) {
 156              $minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
 157          }
 158  
 159          /** @var UpdateModel $model */
 160          $model = $this->getModel('update');
 161          $model->findUpdates($eid, $cache_timeout, $minimum_stability);
 162  
 163          $model->setState('list.start', 0);
 164          $model->setState('list.limit', 0);
 165  
 166          if ($eid != 0) {
 167              $model->setState('filter.extension_id', $eid);
 168          }
 169  
 170          $updates = $model->getItems();
 171  
 172          if (!empty($skip)) {
 173              $unfiltered_updates = $updates;
 174              $updates            = array();
 175  
 176              foreach ($unfiltered_updates as $update) {
 177                  if (!in_array($update->extension_id, $skip)) {
 178                      $updates[] = $update;
 179                  }
 180              }
 181          }
 182  
 183          echo json_encode($updates);
 184  
 185          $app->close();
 186      }
 187  
 188      /**
 189       * Provide the data for a badge in a menu item via JSON
 190       *
 191       * @return  void
 192       *
 193       * @since   4.0.0
 194       * @throws  \Exception
 195       */
 196      public function getMenuBadgeData()
 197      {
 198          if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
 199              throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
 200          }
 201  
 202          $model = $this->getModel('Update');
 203  
 204          echo new JsonResponse($model->getTotal());
 205      }
 206  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer