[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_installer
   6   *
   7   * @copyright   (C) 2011 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\Language\Text;
  14  use Joomla\CMS\MVC\Controller\BaseController;
  15  use Joomla\CMS\Response\JsonResponse;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\Component\Installer\Administrator\Model\DatabaseModel;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Installer Database Controller
  25   *
  26   * @since  2.5
  27   */
  28  class DatabaseController extends BaseController
  29  {
  30      /**
  31       * Tries to fix missing database updates
  32       *
  33       * @return  void
  34       *
  35       * @throws  \Exception
  36       *
  37       * @since   2.5
  38       * @todo    Purge updates has to be replaced with an events system
  39       */
  40      public function fix()
  41      {
  42          // Check for request forgeries.
  43          $this->checkToken();
  44  
  45          // Get items to fix the database.
  46          $cid = (array) $this->input->get('cid', array(), 'int');
  47  
  48          // Remove zero values resulting from input filter
  49          $cid = array_filter($cid);
  50  
  51          if (empty($cid)) {
  52              $this->app->getLogger()->warning(
  53                  Text::_(
  54                      'COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'
  55                  ),
  56                  array('category' => 'jerror')
  57              );
  58          } else {
  59              /** @var DatabaseModel $model */
  60              $model = $this->getModel('Database');
  61              $model->fix($cid);
  62  
  63              /** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $updateModel */
  64              $updateModel = $this->app->bootComponent('com_joomlaupdate')
  65                  ->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);
  66              $updateModel->purge();
  67  
  68              // Refresh versionable assets cache
  69              $this->app->flushAssets();
  70          }
  71  
  72          $this->setRedirect(Route::_('index.php?option=com_installer&view=database', false));
  73      }
  74  
  75      /**
  76       * Provide the data for a badge in a menu item via JSON
  77       *
  78       * @return  void
  79       *
  80       * @since   4.0.0
  81       * @throws  \Exception
  82       */
  83      public function getMenuBadgeData()
  84      {
  85          if (!$this->app->getIdentity()->authorise('core.manage', 'com_installer')) {
  86              throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
  87          }
  88  
  89          $model = $this->getModel('Database');
  90  
  91          $changeSet = $model->getItems();
  92  
  93          $changeSetCount = 0;
  94  
  95          foreach ($changeSet as $item) {
  96              $changeSetCount += $item['errorsCount'];
  97          }
  98  
  99          echo new JsonResponse($changeSetCount);
 100      }
 101  }


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