Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

update_files.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 7.35 KiB


 001  <?php
 002  /**
 003   *
 004   * This file is part of the phpBB Forum Software package.
 005   *
 006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007   * @license GNU General Public License, version 2 (GPL-2.0)
 008   *
 009   * For full copyright and license information, please see
 010   * the docs/CREDITS.txt file.
 011   *
 012   */
 013   
 014  namespace phpbb\install\module\update_filesystem\task;
 015   
 016  use phpbb\exception\runtime_exception;
 017  use phpbb\install\exception\resource_limit_reached_exception;
 018  use phpbb\install\helper\config;
 019  use phpbb\install\helper\container_factory;
 020  use phpbb\install\helper\file_updater\factory;
 021  use phpbb\install\helper\file_updater\file_updater_interface;
 022  use phpbb\install\helper\iohandler\iohandler_interface;
 023  use phpbb\install\helper\update_helper;
 024  use phpbb\install\task_base;
 025   
 026  /**
 027   * File updater task
 028   */
 029  class update_files extends task_base
 030  {
 031      /**
 032       * @var \phpbb\cache\driver\driver_interface
 033       */
 034      protected $cache;
 035   
 036      /**
 037       * @var config
 038       */
 039      protected $installer_config;
 040   
 041      /**
 042       * @var iohandler_interface
 043       */
 044      protected $iohandler;
 045   
 046      /**
 047       * @var factory
 048       */
 049      protected $factory;
 050   
 051      /**
 052       * @var file_updater_interface
 053       */
 054      protected $file_updater;
 055   
 056      /**
 057       * @var update_helper
 058       */
 059      protected $update_helper;
 060   
 061      /**
 062       * @var string
 063       */
 064      protected $phpbb_root_path;
 065   
 066      /**
 067       * Constructor
 068       *
 069       * @param container_factory        $container
 070       * @param config                $config
 071       * @param iohandler_interface    $iohandler
 072       * @param factory                $file_updater_factory
 073       * @param update_helper            $update_helper
 074       * @param string                $phpbb_root_path
 075       */
 076      public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, factory $file_updater_factory, update_helper $update_helper, $phpbb_root_path)
 077      {
 078          $this->factory            = $file_updater_factory;
 079          $this->installer_config    = $config;
 080          $this->iohandler        = $iohandler;
 081          $this->update_helper    = $update_helper;
 082          $this->phpbb_root_path    = $phpbb_root_path;
 083   
 084          $this->cache            = $container->get('cache.driver');
 085          $this->file_updater        = null;
 086   
 087          parent::__construct(false);
 088      }
 089   
 090      /**
 091       * {@inheritdoc}
 092       */
 093      public function check_requirements()
 094      {
 095          return $this->installer_config->get('do_update_files', false);
 096      }
 097   
 098      /**
 099       * {@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                              $this->file_updater->update_file(
 176                                  $path,
 177                                  base64_decode($this->cache->get('_file_' . md5($path))),
 178                                  true
 179                              );
 180                          break;
 181                      }
 182   
 183                      // Save progress
 184                      $this->installer_config->set('file_updater_type_progress', $type);
 185                      $this->installer_config->set('file_updater_elem_progress', $path);
 186                      $progress_count++;
 187                      $this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count);
 188   
 189                      if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
 190                      {
 191                          // Request refresh
 192                          throw new resource_limit_reached_exception();
 193                      }
 194                  }
 195              }
 196   
 197              $this->iohandler->finish_progress('UPDATE_UPDATING_FILES');
 198          }
 199          catch (runtime_exception $e)
 200          {
 201              if ($e instanceof resource_limit_reached_exception)
 202              {
 203                  throw new resource_limit_reached_exception();
 204              }
 205   
 206              $current_method = $this->installer_config->get('file_update_method', '');
 207   
 208              // File updater failed, try to fallback to download file update mode
 209              if ($current_method !== 'compression')
 210              {
 211                  $this->iohandler->add_warning_message(array(
 212                      'UPDATE_FILE_UPDATER_HAS_FAILED',
 213                      $current_method,
 214                      'compression'
 215                  ));
 216                  $this->installer_config->set('file_update_method', 'compression');
 217   
 218                  // We only want a simple refresh here
 219                  throw new resource_limit_reached_exception();
 220              }
 221              else
 222              {
 223                  // Nowhere to fallback to :(
 224                  // Due to the way the installer handles fatal errors, we need to throw a low level exception
 225                  throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED');
 226              }
 227          }
 228   
 229          $file_updater_method = $this->installer_config->get('file_update_method', '');
 230          if ($file_updater_method === 'compression' || $file_updater_method === 'ftp')
 231          {
 232              $this->file_updater->close();
 233          }
 234      }
 235   
 236      /**
 237       * Get file updater
 238       *
 239       * @param null|string    $file_updater_method    Name of the file updater to use
 240       *
 241       * @return file_updater_interface    File updater
 242       */
 243      protected function get_file_updater($file_updater_method = null)
 244      {
 245          $file_updater_method = ($file_updater_method === null) ? $this->installer_config->get('file_update_method', '') : $file_updater_method;
 246   
 247          if ($file_updater_method === 'compression')
 248          {
 249              $compression_method = $this->installer_config->get('file_update_compression', '');
 250   
 251              /** @var \phpbb\install\helper\file_updater\compression_file_updater $file_updater */
 252              $file_updater = $this->factory->get('compression');
 253              $archive_path = $file_updater->init($compression_method);
 254              $this->installer_config->set('update_file_archive', $archive_path);
 255          }
 256          else if ($file_updater_method === 'ftp')
 257          {
 258              /** @var \phpbb\install\helper\file_updater\ftp_file_updater $file_updater */
 259              $file_updater = $this->factory->get('ftp');
 260              $file_updater->init(
 261                  $this->installer_config->get('ftp_method', ''),
 262                  $this->installer_config->get('ftp_host', ''),
 263                  $this->installer_config->get('ftp_user', ''),
 264                  $this->installer_config->get('ftp_pass', ''),
 265                  $this->installer_config->get('ftp_path', ''),
 266                  $this->installer_config->get('ftp_port', 0),
 267                  $this->installer_config->get('ftp_timeout', 10)
 268              );
 269          }
 270          else
 271          {
 272              /** @var file_updater_interface $file_updater */
 273              $file_updater = $this->factory->get('direct_file');
 274          }
 275   
 276          return $file_updater;
 277      }
 278   
 279      /**
 280       * {@inheritdoc}
 281       */
 282      static public function get_step_count()
 283      {
 284          return 0;
 285      }
 286   
 287      /**
 288       * {@inheritdoc}
 289       */
 290      public function get_task_lang_name()
 291      {
 292          return '';
 293      }
 294  }
 295