[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Console/ -> SiteUpCommand.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\Console\Command\AbstractCommand;
  13  use Symfony\Component\Console\Input\ArrayInput;
  14  use Symfony\Component\Console\Input\InputInterface;
  15  use Symfony\Component\Console\Output\OutputInterface;
  16  use Symfony\Component\Console\Style\SymfonyStyle;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('JPATH_PLATFORM') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Console command wrapper for getting the site into offline mode
  24   *
  25   * @since  4.0.0
  26   */
  27  class SiteUpCommand extends AbstractCommand
  28  {
  29      /**
  30       * The default command name
  31       *
  32       * @var    string
  33       * @since  4.0.0
  34       */
  35      protected static $defaultName = 'site:up';
  36  
  37      /**
  38       * SymfonyStyle Object
  39       * @var SymfonyStyle
  40       * @since 4.0.0
  41       */
  42      private $ioStyle;
  43  
  44      /**
  45       * Return code if site:up failed
  46       * @since 4.0.0
  47       */
  48      public const SITE_UP_FAILED = 1;
  49  
  50      /**
  51       * Return code if site:up was successful
  52       * @since 4.0.0
  53       */
  54      public const SITE_UP_SUCCESSFUL = 0;
  55  
  56      /**
  57       * Configures the IO
  58       *
  59       * @param   InputInterface   $input   Console Input
  60       * @param   OutputInterface  $output  Console Output
  61       *
  62       * @return void
  63       *
  64       * @since 4.0.0
  65       *
  66       */
  67      private function configureIO(InputInterface $input, OutputInterface $output)
  68      {
  69          $this->ioStyle = new SymfonyStyle($input, $output);
  70      }
  71  
  72      /**
  73       * Initialise the command.
  74       *
  75       * @return  void
  76       *
  77       * @since   4.0.0
  78       */
  79      protected function configure(): void
  80      {
  81          $help = "<info>%command.name%</info> puts the site into online mode
  82                  \nUsage: <info>php %command.full_name%</info>";
  83  
  84          $this->setDescription('Put the site into online mode');
  85          $this->setHelp($help);
  86      }
  87  
  88      /**
  89       * Internal function to execute the command.
  90       *
  91       * @param   InputInterface   $input   The input to inject into the command.
  92       * @param   OutputInterface  $output  The output to inject into the command.
  93       *
  94       * @return  integer  The command exit code
  95       *
  96       * @since   4.0.0
  97       */
  98      protected function doExecute(InputInterface $input, OutputInterface $output): int
  99      {
 100          $this->configureIO($input, $output);
 101          $this->ioStyle->title('Site Online');
 102  
 103          $returnCode = $this->getApplication()->getCommand(SetConfigurationCommand::getDefaultName())->execute(
 104              new ArrayInput(['options' => ['offline=false']]),
 105              $output
 106          );
 107  
 108          if ($returnCode === 0) {
 109              $this->ioStyle->success("Website is now online");
 110  
 111              return self::SITE_UP_SUCCESSFUL;
 112          }
 113  
 114          return self::SITE_UP_FAILED;
 115      }
 116  }


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