[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/phpbb/install/module/update_filesystem/task/ -> update_files.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\update_filesystem\task;
  15  
  16  use phpbb\exception\runtime_exception;
  17  use phpbb\install\exception\resource_limit_reached_exception;
  18  use phpbb\install\helper\config;
  19  use phpbb\install\helper\container_factory;
  20  use phpbb\install\helper\file_updater\factory;
  21  use phpbb\install\helper\file_updater\file_updater_interface;
  22  use phpbb\install\helper\iohandler\iohandler_interface;
  23  use phpbb\install\helper\update_helper;
  24  use phpbb\install\task_base;
  25  
  26  /**
  27   * File updater task
  28   */
  29  class update_files extends task_base
  30  {
  31      /**
  32       * @var \phpbb\cache\driver\driver_interface
  33       */
  34      protected $cache;
  35  
  36      /**
  37       * @var config
  38       */
  39      protected $installer_config;
  40  
  41      /**
  42       * @var iohandler_interface
  43       */
  44      protected $iohandler;
  45  
  46      /**
  47       * @var factory
  48       */
  49      protected $factory;
  50  
  51      /**
  52       * @var file_updater_interface
  53       */
  54      protected $file_updater;
  55  
  56      /**
  57       * @var update_helper
  58       */
  59      protected $update_helper;
  60  
  61      /**
  62       * @var string
  63       */
  64      protected $phpbb_root_path;
  65  
  66      /**
  67       * Constructor
  68       *
  69       * @param container_factory        $container
  70       * @param config                $config
  71       * @param iohandler_interface    $iohandler
  72       * @param factory                $file_updater_factory
  73       * @param update_helper            $update_helper
  74       * @param string                $phpbb_root_path
  75       */
  76  	public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, factory $file_updater_factory, update_helper $update_helper, $phpbb_root_path)
  77      {
  78          $this->factory            = $file_updater_factory;
  79          $this->installer_config    = $config;
  80          $this->iohandler        = $iohandler;
  81          $this->update_helper    = $update_helper;
  82          $this->phpbb_root_path    = $phpbb_root_path;
  83  
  84          $this->cache            = $container->get('cache.driver');
  85          $this->file_updater        = null;
  86  
  87          parent::__construct(false);
  88      }
  89  
  90      /**
  91       * {@inheritdoc}
  92       */
  93  	public function check_requirements()
  94      {
  95          return $this->installer_config->get('do_update_files', false);
  96      }
  97  
  98      /**
  99       * {@inheritdoc}
 100       */
 101  	public function run()
 102      {
 103          $new_path = $this->update_helper->get_path_to_new_update_files();
 104  
 105          $file_update_info = $this->installer_config->get('update_files', array());
 106  
 107          $update_type_progress = $this->installer_config->get('file_updater_type_progress', '');
 108          $update_elem_progress = $this->installer_config->get('file_updater_elem_progress', '');
 109          $type_progress_found = false;
 110          $elem_progress_found = false;
 111  
 112          // Progress bar
 113          $task_count = 0;
 114          foreach ($file_update_info as $sub_array)
 115          {
 116              $task_count += count($sub_array);
 117          }
 118  
 119          // Everything is up to date, so just continue
 120          if ($task_count === 0)
 121          {
 122              return;
 123          }
 124  
 125          $progress_count = $this->installer_config->get('file_update_progress_count', 0);
 126          $this->iohandler->set_task_count($task_count, true);
 127          $this->iohandler->set_progress('UPDATE_UPDATING_FILES', 0);
 128  
 129          $this->file_updater = $this->get_file_updater();
 130  
 131          // File updater fallback logic
 132          try
 133          {
 134              // Update files
 135              foreach ($file_update_info as $type => $file_update_vector)
 136              {
 137                  if (!$type_progress_found)
 138                  {
 139                      if ($type === $update_type_progress || empty($update_elem_progress))
 140                      {
 141                          $type_progress_found = true;
 142                      }
 143                      else
 144                      {
 145                          continue;
 146                      }
 147                  }
 148  
 149                  foreach ($file_update_vector as $path)
 150                  {
 151                      if (!$elem_progress_found)
 152                      {
 153                          if ($path === $update_elem_progress || empty($update_elem_progress))
 154                          {
 155                              $elem_progress_found = true;
 156                          }
 157                          else
 158                          {
 159                              continue;
 160                          }
 161                      }
 162  
 163                      switch ($type)
 164                      {
 165                          case 'delete':
 166                              $this->file_updater->delete_file($path);
 167                          break;
 168                          case 'new':
 169                              $this->file_updater->create_new_file($path, $new_path . $path);
 170                          break;
 171                          case 'update_without_diff':
 172                              $this->file_updater->update_file($path, $new_path . $path);
 173                          break;
 174                          case 'update_with_diff':
 175                              $cache_diff_filename = '_file_' . md5($path);
 176                              if ($this->cache->_exists($cache_diff_filename))
 177                              {
 178                              $this->file_updater->update_file(
 179                                  $path,
 180                                      base64_decode($this->cache->get($cache_diff_filename)),
 181                                  true
 182                              );
 183                              }
 184                          break;
 185                      }
 186  
 187                      // Save progress
 188                      $this->installer_config->set('file_updater_type_progress', $type);
 189                      $this->installer_config->set('file_updater_elem_progress', $path);
 190                      $progress_count++;
 191                      $this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count);
 192  
 193                      if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
 194                      {
 195                          // Request refresh
 196                          throw new resource_limit_reached_exception();
 197                      }
 198                  }
 199              }
 200  
 201              $this->iohandler->finish_progress('UPDATE_UPDATING_FILES');
 202          }
 203          catch (runtime_exception $e)
 204          {
 205              if ($e instanceof resource_limit_reached_exception)
 206              {
 207                  throw new resource_limit_reached_exception();
 208              }
 209  
 210              $current_method = $this->installer_config->get('file_update_method', '');
 211  
 212              // File updater failed, try to fallback to download file update mode
 213              if ($current_method !== 'compression')
 214              {
 215                  $this->iohandler->add_warning_message(array(
 216                      'UPDATE_FILE_UPDATER_HAS_FAILED',
 217                      $current_method,
 218                      'compression'
 219                  ));
 220                  $this->installer_config->set('file_update_method', 'compression');
 221  
 222                  // We only want a simple refresh here
 223                  throw new resource_limit_reached_exception();
 224              }
 225              else
 226              {
 227                  // Nowhere to fallback to :(
 228                  // Due to the way the installer handles fatal errors, we need to throw a low level exception
 229                  throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED');
 230              }
 231          }
 232  
 233          $file_updater_method = $this->installer_config->get('file_update_method', '');
 234          if ($file_updater_method === 'compression' || $file_updater_method === 'ftp')
 235          {
 236              $this->file_updater->close();
 237          }
 238      }
 239  
 240      /**
 241       * Get file updater
 242       *
 243       * @param null|string    $file_updater_method    Name of the file updater to use
 244       *
 245       * @return file_updater_interface    File updater
 246       */
 247  	protected function get_file_updater($file_updater_method = null)
 248      {
 249          $file_updater_method = ($file_updater_method === null) ? $this->installer_config->get('file_update_method', '') : $file_updater_method;
 250  
 251          if ($file_updater_method === 'compression')
 252          {
 253              $compression_method = $this->installer_config->get('file_update_compression', '');
 254  
 255              /** @var \phpbb\install\helper\file_updater\compression_file_updater $file_updater */
 256              $file_updater = $this->factory->get('compression');
 257              $archive_path = $file_updater->init($compression_method);
 258              $this->installer_config->set('update_file_archive', $archive_path);
 259          }
 260          else if ($file_updater_method === 'ftp')
 261          {
 262              /** @var \phpbb\install\helper\file_updater\ftp_file_updater $file_updater */
 263              $file_updater = $this->factory->get('ftp');
 264              $file_updater->init(
 265                  $this->installer_config->get('ftp_method', ''),
 266                  $this->installer_config->get('ftp_host', ''),
 267                  $this->installer_config->get('ftp_user', ''),
 268                  $this->installer_config->get('ftp_pass', ''),
 269                  $this->installer_config->get('ftp_path', ''),
 270                  $this->installer_config->get('ftp_port', 0),
 271                  $this->installer_config->get('ftp_timeout', 10)
 272              );
 273          }
 274          else
 275          {
 276              /** @var file_updater_interface $file_updater */
 277              $file_updater = $this->factory->get('direct_file');
 278          }
 279  
 280          return $file_updater;
 281      }
 282  
 283      /**
 284       * {@inheritdoc}
 285       */
 286  	static public function get_step_count()
 287      {
 288          return 0;
 289      }
 290  
 291      /**
 292       * {@inheritdoc}
 293       */
 294  	public function get_task_lang_name()
 295      {
 296          return '';
 297      }
 298  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1