[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Console/ -> CleanCacheCommand.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Console;
  11  
  12  use Joomla\CMS\Factory;
  13  use Joomla\Console\Command\AbstractCommand;
  14  use Symfony\Component\Console\Command\Command;
  15  use Symfony\Component\Console\Input\InputArgument;
  16  use Symfony\Component\Console\Input\InputInterface;
  17  use Symfony\Component\Console\Output\OutputInterface;
  18  use Symfony\Component\Console\Style\SymfonyStyle;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('JPATH_PLATFORM') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Console command for cleaning the system cache
  26   *
  27   * @since  4.0.0
  28   */
  29  class CleanCacheCommand extends AbstractCommand
  30  {
  31      /**
  32       * The default command name
  33       *
  34       * @var    string
  35       * @since  4.0.0
  36       */
  37      protected static $defaultName = 'cache:clean';
  38  
  39      /**
  40       * Internal function to execute the command.
  41       *
  42       * @param   InputInterface   $input   The input to inject into the command.
  43       * @param   OutputInterface  $output  The output to inject into the command.
  44       *
  45       * @return  integer  The command exit code
  46       *
  47       * @since   4.0.0
  48       */
  49      protected function doExecute(InputInterface $input, OutputInterface $output): int
  50      {
  51          $symfonyStyle = new SymfonyStyle($input, $output);
  52  
  53          $symfonyStyle->title('Cleaning System Cache');
  54  
  55          $cache = $this->getApplication()->bootComponent('com_cache')->getMVCFactory();
  56          /** @var Joomla\Component\Cache\Administrator\Model\CacheModel $model */
  57          $model = $cache->createModel('Cache', 'Administrator', ['ignore_request' => true]);
  58  
  59          if ($input->getArgument('expired')) {
  60              if (!$model->purge()) {
  61                  $symfonyStyle->error('Expired Cache not cleaned');
  62  
  63                  return Command::FAILURE;
  64              }
  65  
  66              $symfonyStyle->success('Expired Cache cleaned');
  67  
  68              return Command::SUCCESS;
  69          }
  70  
  71          if (!$model->clean()) {
  72              $symfonyStyle->error('Cache not cleaned');
  73  
  74              return Command::FAILURE;
  75          }
  76  
  77          $symfonyStyle->success('Cache cleaned');
  78  
  79          return Command::SUCCESS;
  80      }
  81  
  82      /**
  83       * Configure the command.
  84       *
  85       * @return  void
  86       *
  87       * @since   4.0.0
  88       */
  89      protected function configure(): void
  90      {
  91          $help = "<info>%command.name%</info> will clear entries from the system cache
  92          \nUsage: <info>php %command.full_name%</info>";
  93  
  94          $this->addArgument('expired', InputArgument::OPTIONAL, 'will clear expired entries from the system cache');
  95          $this->setDescription('Clean cache entries');
  96          $this->setHelp($help);
  97      }
  98  }


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