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

file_check.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.50 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\filesystem\filesystem;
017  use phpbb\install\exception\resource_limit_reached_exception;
018  use phpbb\install\helper\config;
019  use phpbb\install\helper\iohandler\iohandler_interface;
020  use phpbb\install\helper\update_helper;
021  use phpbb\install\task_base;
022   
023  /**
024   * Updater task performing file checking
025   */
026  class file_check extends task_base
027  {
028      /**
029       * @var filesystem
030       */
031      protected $filesystem;
032   
033      /**
034       * @var config
035       */
036      protected $installer_config;
037   
038      /**
039       * @var iohandler_interface
040       */
041      protected $iohandler;
042   
043      /**
044       * @var update_helper
045       */
046      protected $update_helper;
047   
048      /**
049       * @var string
050       */
051      protected $phpbb_root_path;
052   
053      /**
054       * Construct
055       *
056       * @param filesystem            $filesystem
057       * @param config                $config
058       * @param iohandler_interface    $iohandler
059       * @param update_helper            $update_helper
060       * @param string                $phpbb_root_path
061       */
062      public function __construct(filesystem $filesystem, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path)
063      {
064          $this->filesystem        = $filesystem;
065          $this->installer_config    = $config;
066          $this->iohandler        = $iohandler;
067          $this->update_helper    = $update_helper;
068          $this->phpbb_root_path    = $phpbb_root_path;
069   
070          parent::__construct(false);
071      }
072   
073      /**
074       * {@inheritdoc}
075       */
076      public function check_requirements()
077      {
078          return $this->installer_config->get('do_update_files', false);
079      }
080   
081      /**
082       * {@inheritdoc}
083       */
084      public function run()
085      {
086          if (!$this->installer_config->has_restart_point('check_update_files'))
087          {
088              $this->installer_config->create_progress_restart_point('check_update_files');
089          }
090   
091          $old_path = $this->update_helper->get_path_to_old_update_files();
092          $new_path = $this->update_helper->get_path_to_new_update_files();
093   
094          $update_info = $this->installer_config->get('update_info', array());
095          $file_update_info = $this->installer_config->get('update_files', array());
096   
097          if (empty($update_info))
098          {
099              $root_path = $this->phpbb_root_path;
100   
101              $update_info = $this->installer_config->get('update_info_unprocessed', array());
102   
103              $file_update_info = array();
104              $file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
105   
106              // Filter out files that are already deleted
107              $file_update_info['delete'] = array_filter(
108                  $update_info['deleted'],
109                  function ($filename) use ($root_path)
110                  {
111                      return file_exists($root_path . $filename);
112                  }
113              );
114          }
115   
116          $progress_count = $this->installer_config->get('file_check_progress_count', 0);
117          $task_count = count($update_info['files']);
118          $this->iohandler->set_task_count($task_count);
119          $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
120   
121          // Create list of default extensions that should have been added prior
122          // to this update
123          $default_update_extensions = [];
124          foreach (\phpbb\install\module\update_database\task\update_extensions::$default_extensions_update as $version => $extensions)
125          {
126              if ($this->update_helper->phpbb_version_compare($update_info['version']['from'], $version, '>='))
127              {
128                  $default_update_extensions = array_merge($default_update_extensions, $extensions);
129              }
130          }
131   
132          foreach ($update_info['files'] as $key => $filename)
133          {
134              $old_file = $old_path . $filename;
135              $new_file = $new_path . $filename;
136              $file = $this->phpbb_root_path . $filename;
137   
138              if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0)
139              {
140                  // Save progress
141                  $this->installer_config->set('update_info', $update_info);
142                  $this->installer_config->set('file_check_progress_count', $progress_count);
143                  $this->installer_config->set('update_files', $file_update_info);
144   
145                  // Request refresh
146                  throw new resource_limit_reached_exception();
147              }
148   
149              $progress_count++;
150              $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
151   
152              // Do not copy default extension again if the previous version was
153              // packaged with it but it does not exist (e.g. deleted by admin)
154              if (strpos($file, $this->phpbb_root_path . 'ext/') !== false)
155              {
156                  $skip_file = false;
157                  foreach ($default_update_extensions as $ext_name)
158                  {
159                      if (strpos($file, $this->phpbb_root_path . 'ext/' . $ext_name) !== false &&
160                          !$this->filesystem->exists($this->phpbb_root_path . 'ext/' . $ext_name . '/composer.json'))
161                      {
162                          $skip_file = true;
163                          break;
164                      }
165                  }
166   
167                  if ($skip_file)
168                  {
169                      continue;
170                  }
171              }
172   
173              if (!$this->filesystem->exists($file))
174              {
175                  $file_update_info['new'][] = $filename;
176              }
177              else
178              {
179                  $file_checksum = md5_file($file);
180   
181                  if ($file_checksum === md5_file($new_file))
182                  {
183                      // File already up to date
184                      continue;
185                  }
186                  else if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file))
187                  {
188                      // No need to diff the file
189                      $file_update_info['update_without_diff'][] = $filename;
190                  }
191                  else
192                  {
193                      $file_update_info['update_with_diff'][] = $filename;
194                  }
195              }
196   
197              unset($update_info['files'][$key]);
198          }
199   
200          $this->installer_config->set('update_files', $file_update_info);
201          $this->installer_config->set('update_info', array());
202      }
203   
204      /**
205       * {@inheritdoc}
206       */
207      static public function get_step_count()
208      {
209          return 0;
210      }
211   
212      /**
213       * {@inheritdoc}
214       */
215      public function get_task_lang_name()
216      {
217          return '';
218      }
219  }
220