[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/install/module/requirements/task/ -> check_update.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\install\module\requirements\task;
  15  
  16  use phpbb\filesystem\filesystem;
  17  use phpbb\install\helper\config;
  18  use phpbb\install\helper\container_factory;
  19  use phpbb\install\helper\iohandler\iohandler_interface;
  20  use phpbb\install\helper\update_helper;
  21  use phpbb\install\task_base;
  22  
  23  /**
  24   * Check the availability of updater files and update version
  25   */
  26  class check_update extends task_base
  27  {
  28      /**
  29       * @var \phpbb\config\db
  30       */
  31      protected $config;
  32  
  33      /**
  34       * @var filesystem
  35       */
  36      protected $filesystem;
  37  
  38      /**
  39       * @var config
  40       */
  41      protected $installer_config;
  42  
  43      /**
  44       * @var iohandler_interface
  45       */
  46      protected $iohandler;
  47  
  48      /**
  49       * @var update_helper
  50       */
  51      protected $update_helper;
  52  
  53      /**
  54       * @var \phpbb\version_helper
  55       */
  56      protected $version_helper;
  57  
  58      /**
  59       * @var string
  60       */
  61      protected $phpbb_root_path;
  62  
  63      /**
  64       * @var string
  65       */
  66      protected $php_ext;
  67  
  68      /**
  69       * @var bool
  70       */
  71      protected $tests_passed;
  72  
  73      /**
  74       * Constructor
  75       *
  76       * @param container_factory        $container
  77       * @param filesystem            $filesystem
  78       * @param config                $config
  79       * @param iohandler_interface    $iohandler
  80       * @param update_helper            $update_helper
  81       * @param string                $phpbb_root_path
  82       * @param string                $php_ext
  83       */
  84  	public function __construct(container_factory $container, filesystem $filesystem, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext)
  85      {
  86          $this->filesystem        = $filesystem;
  87          $this->installer_config    = $config;
  88          $this->iohandler        = $iohandler;
  89          $this->update_helper    = $update_helper;
  90          $this->phpbb_root_path    = $phpbb_root_path;
  91          $this->php_ext            = $php_ext;
  92          $this->tests_passed        = true;
  93  
  94          $this->config            = $container->get('config');
  95          $this->version_helper    = $container->get('version_helper');
  96  
  97          parent::__construct(true);
  98      }
  99  
 100      /**
 101       * Sets $this->tests_passed
 102       *
 103       * @param    bool    $is_passed
 104       */
 105  	protected function set_test_passed($is_passed)
 106      {
 107          // If one test failed, tests_passed should be false
 108          $this->tests_passed = $this->tests_passed && $is_passed;
 109      }
 110  
 111      /**
 112       * {@inheritdoc}
 113       */
 114  	public function run()
 115      {
 116          // Array of update files
 117          $update_files = array(
 118              $this->phpbb_root_path . 'install/update',
 119              $this->phpbb_root_path . 'install/update/index.' . $this->php_ext,
 120          );
 121  
 122          // Check for a valid update directory
 123          if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files))
 124          {
 125              if ($this->iohandler->get_input('update_type', 'all') === 'all')
 126              {
 127                  $this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND');
 128                  $this->set_test_passed(false);
 129              }
 130  
 131              // If there are no update files, we can't check the version etc
 132              // However, we can let the users run migrations if they really want to...
 133              $this->installer_config->set('disable_filesystem_update', true);
 134              return true;
 135          }
 136  
 137          // Recover version numbers
 138          $update_info = array();
 139          @include($this->phpbb_root_path . 'install/update/index.' . $this->php_ext);
 140          $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
 141          $update_version = false;
 142  
 143          if ($info !== false)
 144          {
 145              $update_version = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false;
 146          }
 147  
 148          // Get current and latest version
 149          try
 150          {
 151              $latest_version = $this->version_helper->get_latest_on_current_branch(true);
 152          }
 153          catch (\RuntimeException $e)
 154          {
 155              $latest_version = $update_version;
 156          }
 157  
 158          $current_version = (!empty($this->config['version_update_from'])) ? $this->config['version_update_from'] : $this->config['version'];
 159  
 160          // Check if the update package
 161          if (!$this->update_helper->phpbb_version_compare($current_version, $update_version, '<'))
 162          {
 163              $this->iohandler->add_error_message('NO_UPDATE_FILES_UP_TO_DATE');
 164              $this->tests_passed = false;
 165          }
 166  
 167          // Check if the update package works with the installed version
 168          if (empty($info['version']['from']) || $info['version']['from'] !== $current_version)
 169          {
 170              $this->iohandler->add_error_message(array('INCOMPATIBLE_UPDATE_FILES', $current_version, $info['version']['from'], $update_version));
 171              $this->tests_passed = false;
 172          }
 173  
 174          // check if this is the latest update package
 175          if ($this->update_helper->phpbb_version_compare($update_version, $latest_version, '<'))
 176          {
 177              $this->iohandler->add_warning_message(array('OLD_UPDATE_FILES', $info['version']['from'], $update_version, $latest_version));
 178          }
 179  
 180          return $this->tests_passed;
 181      }
 182  
 183      /**
 184       * {@inheritdoc}
 185       */
 186  	static public function get_step_count()
 187      {
 188          return 0;
 189      }
 190  
 191      /**
 192       * {@inheritdoc}
 193       */
 194  	public function get_task_lang_name()
 195      {
 196          return '';
 197      }
 198  }


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