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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
check.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\console\command\update;
015
016 use phpbb\config\config;
017 use phpbb\exception\exception_interface;
018 use phpbb\language\language;
019 use phpbb\user;
020 use Symfony\Component\Console\Input\InputInterface;
021 use Symfony\Component\Console\Input\InputArgument;
022 use Symfony\Component\Console\Input\InputOption;
023 use Symfony\Component\Console\Output\OutputInterface;
024 use Symfony\Component\Console\Style\SymfonyStyle;
025 use Symfony\Component\DependencyInjection\ContainerInterface;
026
027 class check extends \phpbb\console\command\command
028 {
029 /** @var \phpbb\config\config */
030 protected $config;
031
032 /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */
033 protected $phpbb_container;
034 /**
035 * @var language
036 */
037 private $language;
038
039 /**
040 * Construct method
041 */
042 public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language)
043 {
044 $this->config = $config;
045 $this->phpbb_container = $phpbb_container;
046 $this->language = $language;
047
048 $this->language->add_lang(array('acp/common', 'acp/extensions'));
049
050 parent::__construct($user);
051 }
052
053 /**
054 * Configures the service.
055 *
056 * Sets the name and description of the command.
057 *
058 * @return null
059 */
060 protected function configure()
061 {
062 $this
063 ->setName('update:check')
064 ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK'))
065 ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1'))
066 ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY'))
067 ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE'))
068 ;
069 }
070
071 /**
072 * Executes the command.
073 *
074 * Checks if an update is available.
075 * If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed.
076 * If their is none, nothing is printed unless verbose mode is set.
077 *
078 * @param InputInterface $input Input stream, used to get the options.
079 * @param OutputInterface $output Output stream, used to print messages.
080 * @return int 0 if the board is up to date, 1 if it is not and 2 if an error occured.
081 * @throws \RuntimeException
082 */
083 protected function execute(InputInterface $input, OutputInterface $output)
084 {
085 $io = new SymfonyStyle($input, $output);
086
087 $recheck = true;
088 if ($input->getOption('cache'))
089 {
090 $recheck = false;
091 }
092
093 $stability = null;
094 if ($input->getOption('stability'))
095 {
096 $stability = $input->getOption('stability');
097 if (!($stability == 'stable') && !($stability == 'unstable'))
098 {
099 $io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability));
100 return 3;
101 }
102 }
103
104 $ext_name = $input->getArgument('ext-name');
105 if ($ext_name != null)
106 {
107 if ($ext_name == 'all')
108 {
109 return $this->check_all_ext($io, $stability, $recheck);
110 }
111 else
112 {
113 return $this->check_ext($input, $io, $stability, $recheck, $ext_name);
114 }
115 }
116 else
117 {
118 return $this->check_core($input, $io, $stability, $recheck);
119 }
120 }
121
122 /**
123 * Check if a given extension is up to date
124 *
125 * @param InputInterface $input Input stream, used to get the options.
126 * @param SymfonyStyle $io IO handler, for formatted and unified IO
127 * @param string $stability Force a given stability
128 * @param bool $recheck Disallow the use of the cache
129 * @param string $ext_name The extension name
130 * @return int
131 */
132 protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name)
133 {
134 try
135 {
136 $ext_manager = $this->phpbb_container->get('ext.manager');
137 $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null);
138 $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
139
140 $metadata = $md_manager->get_metadata('all');
141 if ($input->getOption('verbose'))
142 {
143 $io->title($md_manager->get_metadata('display-name'));
144
145 $io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']);
146 }
147
148 if (!empty($updates_available))
149 {
150 if ($input->getOption('verbose'))
151 {
152 $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name']));
153
154 $this->display_versions($io, $updates_available);
155 }
156
157 return 1;
158 }
159 else
160 {
161 if ($input->getOption('verbose'))
162 {
163 $io->success($this->language->lang('UPDATE_NOT_NEEDED'));
164 }
165
166 return 0;
167 }
168 }
169 catch (\RuntimeException $e)
170 {
171 $io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name));
172
173 return 1;
174 }
175 }
176
177 /**
178 * Check if the core is up to date
179 *
180 * @param InputInterface $input Input stream, used to get the options.
181 * @param SymfonyStyle $io IO handler, for formatted and unified IO
182 * @param string $stability Force a given stability
183 * @param bool $recheck Disallow the use of the cache
184 * @return int
185 */
186 protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck)
187 {
188 $version_helper = $this->phpbb_container->get('version_helper');
189 $version_helper->force_stability($stability);
190
191 $updates_available = $version_helper->get_suggested_updates($recheck);
192
193 if ($input->getOption('verbose'))
194 {
195 $io->title('phpBB core');
196
197 $io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']);
198 }
199
200 if (!empty($updates_available))
201 {
202 $io->caution($this->language->lang('UPDATE_NEEDED'));
203
204 if ($input->getOption('verbose'))
205 {
206 $this->display_versions($io, $updates_available);
207 }
208
209 return 1;
210 }
211 else
212 {
213 if ($input->getOption('verbose'))
214 {
215 $io->success($this->language->lang('UPDATE_NOT_NEEDED'));
216 }
217
218 return 0;
219 }
220 }
221
222 /**
223 * Check if all the available extensions are up to date
224 *
225 * @param SymfonyStyle $io IO handler, for formatted and unified IO
226 * @param bool $recheck Disallow the use of the cache
227 * @return int
228 */
229 protected function check_all_ext(SymfonyStyle $io, $stability, $recheck)
230 {
231 /** @var \phpbb\extension\manager $ext_manager */
232 $ext_manager = $this->phpbb_container->get('ext.manager');
233
234 $rows = [];
235
236 foreach ($ext_manager->all_available() as $ext_name => $ext_path)
237 {
238 $row = [];
239 $row[] = sprintf("<info>%s</info>", $ext_name);
240 $md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
241 try
242 {
243 $metadata = $md_manager->get_metadata('all');
244 if (isset($metadata['extra']['version-check']))
245 {
246 try {
247 $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
248 if (!empty($updates_available))
249 {
250 $versions = array_map(function($entry)
251 {
252 return $entry['current'];
253 }, $updates_available);
254
255 $row[] = sprintf("<comment>%s</comment>", $metadata['version']);
256 $row[] = implode(', ', $versions);
257 }
258 else
259 {
260 $row[] = sprintf("<info>%s</info>", $metadata['version']);
261 $row[] = '';
262 }
263 } catch (\RuntimeException $e) {
264 $row[] = $metadata['version'];
265 $row[] = '';
266 }
267 }
268 else
269 {
270 $row[] = $metadata['version'];
271 $row[] = '';
272 }
273 }
274 catch (exception_interface $e)
275 {
276 $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
277 $row[] = '<error>' . $exception_message . '</error>';
278 }
279 catch (\RuntimeException $e)
280 {
281 $row[] = '<error>' . $e->getMessage() . '</error>';
282 }
283
284 $rows[] = $row;
285 }
286
287 $io->table([
288 $this->language->lang('EXTENSION_NAME'),
289 $this->language->lang('CURRENT_VERSION'),
290 $this->language->lang('LATEST_VERSION'),
291 ], $rows);
292
293 return 0;
294 }
295
296 /**
297 * Display the details of the available updates
298 *
299 * @param SymfonyStyle $io IO handler, for formatted and unified IO
300 * @param array $updates_available The list of the available updates
301 */
302 protected function display_versions(SymfonyStyle $io, $updates_available)
303 {
304 $io->section($this->language->lang('UPDATES_AVAILABLE'));
305
306 $rows = [];
307 foreach ($updates_available as $version_data)
308 {
309 $row = ['', '', ''];
310 $row[0] = $version_data['current'];
311
312 if (isset($version_data['announcement']))
313 {
314 $row[1] = $version_data['announcement'];
315 }
316
317 if (isset($version_data['download']))
318 {
319 $row[2] = $version_data['download'];
320 }
321
322 $rows[] = $row;
323 }
324
325 $io->table([
326 $this->language->lang('VERSION'),
327 $this->language->lang('ANNOUNCEMENT_TOPIC'),
328 $this->language->lang('DOWNLOAD_LATEST'),
329 ], $rows);
330 }
331 }
332