[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2020 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\Component\Joomlaupdate\Administrator\Model\UpdateModel;
  13  use Joomla\Console\Command\AbstractCommand;
  14  use Symfony\Component\Console\Command\Command;
  15  use Symfony\Component\Console\Input\InputInterface;
  16  use Symfony\Component\Console\Output\OutputInterface;
  17  use Symfony\Component\Console\Style\SymfonyStyle;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('JPATH_PLATFORM') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Console command for checking if there are pending extension updates
  25   *
  26   * @since  4.0.0
  27   */
  28  class CheckJoomlaUpdatesCommand extends AbstractCommand
  29  {
  30      /**
  31       * The default command name
  32       *
  33       * @var    string
  34       * @since  4.0.0
  35       */
  36      protected static $defaultName = 'core:check-updates';
  37  
  38      /**
  39       * Stores the Update Information
  40       *
  41       * @var    UpdateModel
  42       * @since  4.0.0
  43       */
  44      private $updateInfo;
  45  
  46      /**
  47       * Initialise the command.
  48       *
  49       * @return  void
  50       *
  51       * @since   4.0.0
  52       */
  53      protected function configure(): void
  54      {
  55          $help = "<info>%command.name%</info> will check for Joomla updates
  56          \nUsage: <info>php %command.full_name%</info>";
  57  
  58          $this->setDescription('Check for Joomla updates');
  59          $this->setHelp($help);
  60      }
  61  
  62      /**
  63       * Retrieves Update Information
  64       *
  65       * @return mixed
  66       *
  67       * @since 4.0.0
  68       */
  69      private function getUpdateInformationFromModel()
  70      {
  71          $app = $this->getApplication();
  72          $updatemodel = $app->bootComponent('com_joomlaupdate')->getMVCFactory($app)->createModel('Update', 'Administrator');
  73          $updatemodel->purge();
  74          $updatemodel->refreshUpdates(true);
  75  
  76          return $updatemodel;
  77      }
  78  
  79      /**
  80       * Gets the Update Information
  81       *
  82       * @return mixed
  83       *
  84       * @since 4.0.0
  85       */
  86      public function getUpdateInfo()
  87      {
  88          if (!$this->updateInfo) {
  89              $this->setUpdateInfo();
  90          }
  91  
  92          return $this->updateInfo;
  93      }
  94  
  95      /**
  96       * Sets the Update Information
  97       *
  98       * @param   null  $info  stores update Information
  99       *
 100       * @return void
 101       *
 102       * @since 4.0.0
 103       */
 104      public function setUpdateInfo($info = null): void
 105      {
 106          if (!$info) {
 107              $this->updateInfo = $this->getUpdateInformationFromModel();
 108          } else {
 109              $this->updateInfo = $info;
 110          }
 111      }
 112  
 113      /**
 114       * Internal function to execute the command.
 115       *
 116       * @param   InputInterface   $input   The input to inject into the command.
 117       * @param   OutputInterface  $output  The output to inject into the command.
 118       *
 119       * @return  integer  The command exit code
 120       *
 121       * @since   4.0.0
 122       */
 123      protected function doExecute(InputInterface $input, OutputInterface $output): int
 124      {
 125          $symfonyStyle = new SymfonyStyle($input, $output);
 126  
 127          $model = $this->getUpdateInfo();
 128          $data  = $model->getUpdateInformation();
 129          $symfonyStyle->title('Joomla! Updates');
 130  
 131          if (!$data['hasUpdate']) {
 132              $symfonyStyle->success('You already have the latest Joomla version ' . $data['latest']);
 133  
 134              return Command::SUCCESS;
 135          }
 136  
 137          $symfonyStyle->note('New Joomla Version ' . $data['latest'] . ' is available.');
 138  
 139          if (!isset($data['object']->downloadurl->_data)) {
 140              $symfonyStyle->warning('We cannot find an update URL');
 141          }
 142  
 143          return Command::SUCCESS;
 144      }
 145  }


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