[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\console\command\update; 15 16 use phpbb\config\config; 17 use phpbb\exception\exception_interface; 18 use phpbb\language\language; 19 use phpbb\user; 20 use Symfony\Component\Console\Input\InputInterface; 21 use Symfony\Component\Console\Input\InputArgument; 22 use Symfony\Component\Console\Input\InputOption; 23 use Symfony\Component\Console\Output\OutputInterface; 24 use Symfony\Component\Console\Style\SymfonyStyle; 25 use Symfony\Component\DependencyInjection\ContainerInterface; 26 27 class check extends \phpbb\console\command\command 28 { 29 /** @var config */ 30 protected $config; 31 32 /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ 33 protected $phpbb_container; 34 35 /** 36 * @var language 37 */ 38 private $language; 39 40 /** 41 * Construct method 42 */ 43 public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language) 44 { 45 $this->config = $config; 46 $this->phpbb_container = $phpbb_container; 47 $this->language = $language; 48 49 $this->language->add_lang(array('acp/common', 'acp/extensions')); 50 51 parent::__construct($user); 52 } 53 54 /** 55 * Configures the service. 56 * 57 * Sets the name and description of the command. 58 * 59 * @return null 60 */ 61 protected function configure() 62 { 63 $this 64 ->setName('update:check') 65 ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK')) 66 ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) 67 ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) 68 ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) 69 ; 70 } 71 72 /** 73 * Executes the command. 74 * 75 * Checks if an update is available. 76 * If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed. 77 * If their is none, nothing is printed unless verbose mode is set. 78 * 79 * @param InputInterface $input Input stream, used to get the options. 80 * @param OutputInterface $output Output stream, used to print messages. 81 * @return int 0 if the board is up to date, 1 if it is not and 2 if an error occurred. 82 * @throws \RuntimeException 83 */ 84 protected function execute(InputInterface $input, OutputInterface $output) 85 { 86 $io = new SymfonyStyle($input, $output); 87 88 $recheck = true; 89 if ($input->getOption('cache')) 90 { 91 $recheck = false; 92 } 93 94 $stability = null; 95 if ($input->getOption('stability')) 96 { 97 $stability = $input->getOption('stability'); 98 if (!($stability == 'stable') && !($stability == 'unstable')) 99 { 100 $io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); 101 return 3; 102 } 103 } 104 105 $ext_name = $input->getArgument('ext-name'); 106 if ($ext_name != null) 107 { 108 if ($ext_name == 'all') 109 { 110 return $this->check_all_ext($io, $stability, $recheck); 111 } 112 else 113 { 114 return $this->check_ext($input, $io, $stability, $recheck, $ext_name); 115 } 116 } 117 else 118 { 119 return $this->check_core($input, $io, $stability, $recheck); 120 } 121 } 122 123 /** 124 * Check if a given extension is up to date 125 * 126 * @param InputInterface $input Input stream, used to get the options. 127 * @param SymfonyStyle $io IO handler, for formatted and unified IO 128 * @param string $stability Force a given stability 129 * @param bool $recheck Disallow the use of the cache 130 * @param string $ext_name The extension name 131 * @return int 132 */ 133 protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name) 134 { 135 try 136 { 137 $ext_manager = $this->phpbb_container->get('ext.manager'); 138 $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); 139 $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); 140 141 $metadata = $md_manager->get_metadata('all'); 142 if ($input->getOption('verbose')) 143 { 144 $io->title($md_manager->get_metadata('display-name')); 145 146 $io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); 147 } 148 149 if (!empty($updates_available)) 150 { 151 if ($input->getOption('verbose')) 152 { 153 $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name'])); 154 155 $this->display_versions($io, $updates_available); 156 } 157 158 return 1; 159 } 160 else 161 { 162 if ($input->getOption('verbose')) 163 { 164 $io->success($this->language->lang('UPDATE_NOT_NEEDED')); 165 } 166 167 return 0; 168 } 169 } 170 catch (\RuntimeException $e) 171 { 172 $io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name)); 173 174 return 1; 175 } 176 } 177 178 /** 179 * Check if the core is up to date 180 * 181 * @param InputInterface $input Input stream, used to get the options. 182 * @param SymfonyStyle $io IO handler, for formatted and unified IO 183 * @param string $stability Force a given stability 184 * @param bool $recheck Disallow the use of the cache 185 * @return int 186 */ 187 protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck) 188 { 189 $version_helper = $this->phpbb_container->get('version_helper'); 190 $version_helper->force_stability($stability); 191 192 $updates_available = $version_helper->get_suggested_updates($recheck); 193 194 if ($input->getOption('verbose')) 195 { 196 $io->title('phpBB core'); 197 198 $io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); 199 } 200 201 if (!empty($updates_available)) 202 { 203 $io->caution($this->language->lang('UPDATE_NEEDED')); 204 205 if ($input->getOption('verbose')) 206 { 207 $this->display_versions($io, $updates_available); 208 } 209 210 return 1; 211 } 212 else 213 { 214 if ($input->getOption('verbose')) 215 { 216 $io->success($this->language->lang('UPDATE_NOT_NEEDED')); 217 } 218 219 return 0; 220 } 221 } 222 223 /** 224 * Check if all the available extensions are up to date 225 * 226 * @param SymfonyStyle $io IO handler, for formatted and unified IO 227 * @param string $stability Stability specifier string 228 * @param bool $recheck Disallow the use of the cache 229 * @return int 230 */ 231 protected function check_all_ext(SymfonyStyle $io, $stability, $recheck) 232 { 233 /** @var \phpbb\extension\manager $ext_manager */ 234 $ext_manager = $this->phpbb_container->get('ext.manager'); 235 236 $rows = []; 237 238 foreach ($ext_manager->all_available() as $ext_name => $ext_path) 239 { 240 $row = []; 241 $row[] = sprintf("<info>%s</info>", $ext_name); 242 $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); 243 try 244 { 245 $metadata = $md_manager->get_metadata('all'); 246 if (isset($metadata['extra']['version-check'])) 247 { 248 try { 249 $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); 250 if (!empty($updates_available)) 251 { 252 $versions = array_map(function($entry) 253 { 254 return $entry['current']; 255 }, $updates_available); 256 257 $row[] = sprintf("<comment>%s</comment>", $metadata['version']); 258 $row[] = implode(', ', $versions); 259 } 260 else 261 { 262 $row[] = sprintf("<info>%s</info>", $metadata['version']); 263 $row[] = ''; 264 } 265 } catch (\RuntimeException $e) { 266 $row[] = $metadata['version']; 267 $row[] = ''; 268 } 269 } 270 else 271 { 272 $row[] = $metadata['version']; 273 $row[] = ''; 274 } 275 } 276 catch (exception_interface $e) 277 { 278 $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); 279 $row[] = '<error>' . $exception_message . '</error>'; 280 } 281 catch (\RuntimeException $e) 282 { 283 $row[] = '<error>' . $e->getMessage() . '</error>'; 284 } 285 286 $rows[] = $row; 287 } 288 289 $io->table([ 290 $this->language->lang('EXTENSION_NAME'), 291 $this->language->lang('CURRENT_VERSION'), 292 $this->language->lang('LATEST_VERSION'), 293 ], $rows); 294 295 return 0; 296 } 297 298 /** 299 * Display the details of the available updates 300 * 301 * @param SymfonyStyle $io IO handler, for formatted and unified IO 302 * @param array $updates_available The list of the available updates 303 */ 304 protected function display_versions(SymfonyStyle $io, $updates_available) 305 { 306 $io->section($this->language->lang('UPDATES_AVAILABLE')); 307 308 $rows = []; 309 foreach ($updates_available as $version_data) 310 { 311 $row = ['', '', '']; 312 $row[0] = $version_data['current']; 313 314 if (isset($version_data['announcement'])) 315 { 316 $row[1] = $version_data['announcement']; 317 } 318 319 if (isset($version_data['download'])) 320 { 321 $row[2] = $version_data['download']; 322 } 323 324 $rows[] = $row; 325 } 326 327 $io->table([ 328 $this->language->lang('VERSION'), 329 $this->language->lang('ANNOUNCEMENT_TOPIC'), 330 $this->language->lang('DOWNLOAD_LATEST'), 331 ], $rows); 332 } 333 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |