[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/console/command/update/ -> check.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\console\command\update;
  15  
  16  use phpbb\config\config;
  17  use phpbb\exception\exception_interface;
  18  use phpbb\language\language;
  19  use phpbb\user;
  20  use Symfony\Component\Console\Input\InputInterface;
  21  use Symfony\Component\Console\Input\InputArgument;
  22  use Symfony\Component\Console\Input\InputOption;
  23  use Symfony\Component\Console\Output\OutputInterface;
  24  use Symfony\Component\Console\Style\SymfonyStyle;
  25  use Symfony\Component\DependencyInjection\ContainerInterface;
  26  
  27  class check extends \phpbb\console\command\command
  28  {
  29      /** @var \phpbb\config\config */
  30      protected $config;
  31  
  32      /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */
  33      protected $phpbb_container;
  34      /**
  35       * @var language
  36       */
  37      private $language;
  38  
  39      /**
  40      * Construct method
  41      */
  42  	public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language)
  43      {
  44          $this->config = $config;
  45          $this->phpbb_container = $phpbb_container;
  46          $this->language = $language;
  47  
  48          $this->language->add_lang(array('acp/common', 'acp/extensions'));
  49  
  50          parent::__construct($user);
  51      }
  52  
  53      /**
  54      * Configures the service.
  55      *
  56      * Sets the name and description of the command.
  57      *
  58      * @return null
  59      */
  60  	protected function configure()
  61      {
  62          $this
  63              ->setName('update:check')
  64              ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK'))
  65              ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1'))
  66              ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY'))
  67              ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE'))
  68          ;
  69      }
  70  
  71      /**
  72      * Executes the command.
  73      *
  74      * Checks if an update is available.
  75      * If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed.
  76      * If their is none, nothing is printed unless verbose mode is set.
  77      *
  78      * @param InputInterface $input Input stream, used to get the options.
  79      * @param OutputInterface $output Output stream, used to print messages.
  80      * @return int 0 if the board is up to date, 1 if it is not and 2 if an error occured.
  81      * @throws \RuntimeException
  82      */
  83  	protected function execute(InputInterface $input, OutputInterface $output)
  84      {
  85          $io = new SymfonyStyle($input, $output);
  86  
  87          $recheck = true;
  88          if ($input->getOption('cache'))
  89          {
  90              $recheck = false;
  91          }
  92  
  93          $stability = null;
  94          if ($input->getOption('stability'))
  95          {
  96              $stability = $input->getOption('stability');
  97              if (!($stability == 'stable') && !($stability == 'unstable'))
  98              {
  99                  $io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability));
 100                  return 3;
 101              }
 102          }
 103  
 104          $ext_name = $input->getArgument('ext-name');
 105          if ($ext_name != null)
 106          {
 107              if ($ext_name == 'all')
 108              {
 109                  return $this->check_all_ext($io, $stability, $recheck);
 110              }
 111              else
 112              {
 113                  return $this->check_ext($input, $io, $stability, $recheck, $ext_name);
 114              }
 115          }
 116          else
 117          {
 118              return $this->check_core($input, $io, $stability, $recheck);
 119          }
 120      }
 121  
 122      /**
 123       * Check if a given extension is up to date
 124       *
 125       * @param InputInterface    $input        Input stream, used to get the options.
 126       * @param SymfonyStyle        $io            IO handler, for formatted and unified IO
 127       * @param string            $stability    Force a given stability
 128       * @param bool                $recheck    Disallow the use of the cache
 129       * @param string            $ext_name    The extension name
 130       * @return int
 131       */
 132  	protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name)
 133      {
 134          try
 135          {
 136              $ext_manager = $this->phpbb_container->get('ext.manager');
 137              $md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
 138              $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
 139  
 140              $metadata = $md_manager->get_metadata('all');
 141              if ($input->getOption('verbose'))
 142              {
 143                  $io->title($md_manager->get_metadata('display-name'));
 144  
 145                  $io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']);
 146              }
 147  
 148              if (!empty($updates_available))
 149              {
 150                  if ($input->getOption('verbose'))
 151                  {
 152                      $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name']));
 153  
 154                      $this->display_versions($io, $updates_available);
 155                  }
 156  
 157                  return 1;
 158              }
 159              else
 160              {
 161                  if ($input->getOption('verbose'))
 162                  {
 163                      $io->success($this->language->lang('UPDATE_NOT_NEEDED'));
 164                  }
 165  
 166                  return 0;
 167              }
 168          }
 169          catch (\RuntimeException $e)
 170          {
 171              $io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name));
 172  
 173              return 1;
 174          }
 175      }
 176  
 177      /**
 178       * Check if the core is up to date
 179       *
 180       * @param InputInterface    $input        Input stream, used to get the options.
 181       * @param SymfonyStyle        $io            IO handler, for formatted and unified IO
 182       * @param string            $stability    Force a given stability
 183       * @param bool                $recheck    Disallow the use of the cache
 184       * @return int
 185       */
 186  	protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck)
 187      {
 188          $version_helper = $this->phpbb_container->get('version_helper');
 189          $version_helper->force_stability($stability);
 190  
 191          $updates_available = $version_helper->get_suggested_updates($recheck);
 192  
 193          if ($input->getOption('verbose'))
 194          {
 195              $io->title('phpBB core');
 196  
 197              $io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']);
 198          }
 199  
 200          if (!empty($updates_available))
 201          {
 202              $io->caution($this->language->lang('UPDATE_NEEDED'));
 203  
 204              if ($input->getOption('verbose'))
 205              {
 206                  $this->display_versions($io, $updates_available);
 207              }
 208  
 209              return 1;
 210          }
 211          else
 212          {
 213              if ($input->getOption('verbose'))
 214              {
 215                  $io->success($this->language->lang('UPDATE_NOT_NEEDED'));
 216              }
 217  
 218              return 0;
 219          }
 220      }
 221  
 222      /**
 223      * Check if all the available extensions are up to date
 224      *
 225      * @param SymfonyStyle    $io            IO handler, for formatted and unified IO
 226      * @param bool            $recheck    Disallow the use of the cache
 227      * @return int
 228      */
 229  	protected function check_all_ext(SymfonyStyle $io, $stability, $recheck)
 230      {
 231          /** @var \phpbb\extension\manager $ext_manager */
 232          $ext_manager = $this->phpbb_container->get('ext.manager');
 233  
 234          $rows = [];
 235  
 236          foreach ($ext_manager->all_available() as $ext_name => $ext_path)
 237          {
 238              $row = [];
 239              $row[] = sprintf("<info>%s</info>", $ext_name);
 240              $md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
 241              try
 242              {
 243                  $metadata = $md_manager->get_metadata('all');
 244                  if (isset($metadata['extra']['version-check']))
 245                  {
 246                      try {
 247                          $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
 248                          if (!empty($updates_available))
 249                          {
 250                              $versions = array_map(function($entry)
 251                              {
 252                                  return $entry['current'];
 253                              }, $updates_available);
 254  
 255                              $row[] = sprintf("<comment>%s</comment>", $metadata['version']);
 256                              $row[] = implode(', ', $versions);
 257                          }
 258                          else
 259                          {
 260                              $row[] = sprintf("<info>%s</info>", $metadata['version']);
 261                              $row[] = '';
 262                          }
 263                      } catch (\RuntimeException $e) {
 264                          $row[] = $metadata['version'];
 265                          $row[] = '';
 266                      }
 267                  }
 268                  else
 269                  {
 270                      $row[] = $metadata['version'];
 271                      $row[] = '';
 272                  }
 273              }
 274              catch (exception_interface $e)
 275              {
 276                  $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 277                  $row[] = '<error>' . $exception_message . '</error>';
 278              }
 279              catch (\RuntimeException $e)
 280              {
 281                  $row[] = '<error>' . $e->getMessage() . '</error>';
 282              }
 283  
 284              $rows[] = $row;
 285          }
 286  
 287          $io->table([
 288              $this->language->lang('EXTENSION_NAME'),
 289              $this->language->lang('CURRENT_VERSION'),
 290              $this->language->lang('LATEST_VERSION'),
 291          ], $rows);
 292  
 293          return 0;
 294      }
 295  
 296      /**
 297      * Display the details of the available updates
 298      *
 299      * @param SymfonyStyle    $io                    IO handler, for formatted and unified IO
 300      * @param array            $updates_available    The list of the available updates
 301      */
 302  	protected function display_versions(SymfonyStyle $io, $updates_available)
 303      {
 304          $io->section($this->language->lang('UPDATES_AVAILABLE'));
 305  
 306          $rows = [];
 307          foreach ($updates_available as $version_data)
 308          {
 309              $row = ['', '', ''];
 310              $row[0] = $version_data['current'];
 311  
 312              if (isset($version_data['announcement']))
 313              {
 314                  $row[1] = $version_data['announcement'];
 315              }
 316  
 317              if (isset($version_data['download']))
 318              {
 319                  $row[2] = $version_data['download'];
 320              }
 321  
 322              $rows[] = $row;
 323          }
 324  
 325          $io->table([
 326              $this->language->lang('VERSION'),
 327              $this->language->lang('ANNOUNCEMENT_TOPIC'),
 328              $this->language->lang('DOWNLOAD_LATEST'),
 329          ], $rows);
 330      }
 331  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1