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 |
check_filesystem.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\requirements\task;
015
016 /**
017 * Checks filesystem requirements
018 */
019 class check_filesystem extends \phpbb\install\task_base
020 {
021 /**
022 * @var \phpbb\filesystem\filesystem_interface
023 */
024 protected $filesystem;
025
026 /**
027 * @var array
028 */
029 protected $files_to_check;
030
031 /**
032 * @var bool
033 */
034 protected $tests_passed;
035
036 /**
037 * @var string
038 */
039 protected $phpbb_root_path;
040
041 /**
042 * @var \phpbb\install\helper\iohandler\iohandler_interface
043 */
044 protected $response;
045
046 /**
047 * Constructor
048 *
049 * @param \phpbb\filesystem\filesystem_interface $filesystem filesystem handler
050 * @param \phpbb\install\helper\iohandler\iohandler_interface $response response helper
051 * @param string $phpbb_root_path relative path to phpBB's root
052 * @param string $php_ext extension of php files
053 * @param bool $check_config_php Whether or not to check if config.php is writable
054 */
055 public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, \phpbb\install\helper\iohandler\iohandler_interface $response, $phpbb_root_path, $php_ext, $check_config_php = true)
056 {
057 parent::__construct(true);
058
059 $this->filesystem = $filesystem;
060 $this->response = $response;
061 $this->phpbb_root_path = $phpbb_root_path;
062
063 $this->tests_passed = false;
064
065 // Files/Directories to check
066 // All file/directory names must be relative to phpBB's root path
067 $this->files_to_check = array(
068 array(
069 'path' => 'cache/',
070 'failable' => false,
071 'is_file' => false,
072 ),
073 array(
074 'path' => 'store/',
075 'failable' => false,
076 'is_file' => false,
077 ),
078 array(
079 'path' => 'files/',
080 'failable' => false,
081 'is_file' => false,
082 ),
083 array(
084 'path' => 'images/avatars/upload/',
085 'failable' => true,
086 'is_file' => false,
087 ),
088 );
089
090 if ($check_config_php)
091 {
092 $this->files_to_check[] = array(
093 'path' => "config.$php_ext",
094 'failable' => false,
095 'is_file' => true,
096 );
097 }
098 }
099
100 /**
101 * {@inheritdoc}
102 */
103 public function run()
104 {
105 $this->tests_passed = true;
106
107 // Check files/directories to be writable
108 foreach ($this->files_to_check as $file)
109 {
110 if ($file['is_file'])
111 {
112 $this->check_file($file['path'], $file['failable']);
113 }
114 else
115 {
116 $this->check_dir($file['path'], $file['failable']);
117 }
118 }
119
120 return $this->tests_passed;
121 }
122
123 /**
124 * Sets $this->tests_passed
125 *
126 * @param bool $is_passed
127 */
128 protected function set_test_passed($is_passed)
129 {
130 // If one test failed, tests_passed should be false
131 $this->tests_passed = (!$this->tests_passed) ? false : $is_passed;
132 }
133
134 /**
135 * Check if a file is readable and writable
136 *
137 * @param string $file Filename
138 * @param bool $failable Whether failing test should interrupt installation process
139 */
140 protected function check_file($file, $failable = false)
141 {
142 $path = $this->phpbb_root_path . $file;
143 $exists = $writable = true;
144
145 // Try to create file if it does not exists
146 if (!file_exists($path))
147 {
148 $fp = @fopen($path, 'w');
149 @fclose($fp);
150 try
151 {
152 $this->filesystem->phpbb_chmod($path,
153 \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE
154 );
155 $exists = true;
156 }
157 catch (\phpbb\filesystem\exception\filesystem_exception $e)
158 {
159 // Do nothing
160 }
161 }
162
163 if (file_exists($path))
164 {
165 if (!$this->filesystem->is_writable($path))
166 {
167 $writable = false;
168 }
169 }
170 else
171 {
172 $exists = $writable = false;
173 }
174
175 $this->set_test_passed(($exists && $writable) || $failable);
176
177 if (!($exists && $writable))
178 {
179 $title = ($exists) ? 'FILE_NOT_WRITABLE' : 'FILE_NOT_EXISTS';
180 $lang_suffix = '_EXPLAIN';
181 $lang_suffix .= ($failable) ? '_OPTIONAL' : '';
182 $description = array($title . $lang_suffix, $file);
183
184 if ($failable)
185 {
186 $this->response->add_warning_message($title, $description);
187 }
188 else
189 {
190 $this->response->add_error_message($title, $description);
191 }
192 }
193 }
194
195 /**
196 * Check if a directory is readable and writable
197 *
198 * @param string $dir Filename
199 * @param bool $failable Whether failing test should abort the installation process
200 */
201 protected function check_dir($dir, $failable = false)
202 {
203 $path = $this->phpbb_root_path . $dir;
204 $exists = $writable = false;
205
206 // Try to create the directory if it does not exist
207 if (!file_exists($path))
208 {
209 try
210 {
211 $this->filesystem->mkdir($path, 0777);
212 $this->filesystem->phpbb_chmod($path,
213 \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE
214 );
215 $exists = true;
216 }
217 catch (\phpbb\filesystem\exception\filesystem_exception $e)
218 {
219 // Do nothing
220 $this->response->add_warning_message($e->getMessage(), $e->get_filename());
221 }
222 }
223
224 // Now really check
225 if (file_exists($path) && is_dir($path))
226 {
227 try
228 {
229 $exists = true;
230 $this->filesystem->phpbb_chmod($path,
231 \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE
232 );
233 }
234 catch (\phpbb\filesystem\exception\filesystem_exception $e)
235 {
236 $this->response->add_warning_message($e->getMessage(), $e->get_filename());
237 // Do nothing
238 }
239 }
240
241 if ($this->filesystem->is_writable($path))
242 {
243 $writable = true;
244 }
245
246 $this->set_test_passed(($exists && $writable) || $failable);
247
248 if (!($exists && $writable))
249 {
250 $title = ($exists) ? 'DIRECTORY_NOT_WRITABLE' : 'DIRECTORY_NOT_EXISTS';
251 $lang_suffix = '_EXPLAIN';
252 $lang_suffix .= ($failable) ? '_OPTIONAL' : '';
253 $description = array($title . $lang_suffix, $dir);
254
255 if ($failable)
256 {
257 $this->response->add_warning_message($title, $description);
258 }
259 else
260 {
261 $this->response->add_error_message($title, $description);
262 }
263 }
264 }
265
266 /**
267 * {@inheritdoc}
268 */
269 static public function get_step_count()
270 {
271 return 0;
272 }
273
274 /**
275 * {@inheritdoc}
276 */
277 public function get_task_lang_name()
278 {
279 return '';
280 }
281 }
282