Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
update_files.php
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 $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 }
299