[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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\reparser; 15 16 use phpbb\exception\runtime_exception; 17 use Symfony\Component\Console\Input\InputInterface; 18 use Symfony\Component\Console\Input\InputArgument; 19 use Symfony\Component\Console\Input\InputOption; 20 use Symfony\Component\Console\Output\OutputInterface; 21 use Symfony\Component\Console\Style\SymfonyStyle; 22 23 class reparse extends \phpbb\console\command\command 24 { 25 /** 26 * @var InputInterface 27 */ 28 protected $input; 29 30 /** 31 * @var SymfonyStyle 32 */ 33 protected $io; 34 35 /** 36 * @var OutputInterface 37 */ 38 protected $output; 39 40 /** 41 * @var \phpbb\lock\db 42 */ 43 protected $reparse_lock; 44 45 /** 46 * @var \phpbb\textreparser\manager 47 */ 48 protected $reparser_manager; 49 50 /** 51 * @var \phpbb\di\service_collection 52 */ 53 protected $reparsers; 54 55 /** 56 * @var array The reparser's last $current ID as values 57 */ 58 protected $resume_data; 59 60 /** 61 * Constructor 62 * 63 * @param \phpbb\user $user 64 * @param \phpbb\lock\db $reparse_lock 65 * @param \phpbb\textreparser\manager $reparser_manager 66 * @param \phpbb\di\service_collection $reparsers 67 */ 68 public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) 69 { 70 require_once __DIR__ . '/../../../../includes/functions_content.php'; 71 72 $this->reparse_lock = $reparse_lock; 73 $this->reparser_manager = $reparser_manager; 74 $this->reparsers = $reparsers; 75 parent::__construct($user); 76 } 77 78 /** 79 * Sets the command name and description 80 * 81 * @return null 82 */ 83 protected function configure() 84 { 85 $this 86 ->setName('reparser:reparse') 87 ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) 88 ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) 89 ->addOption( 90 'dry-run', 91 null, 92 InputOption::VALUE_NONE, 93 $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN') 94 ) 95 ->addOption( 96 'resume', 97 null, 98 InputOption::VALUE_NONE, 99 $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME') 100 ) 101 ->addOption( 102 'range-min', 103 null, 104 InputOption::VALUE_REQUIRED, 105 $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'), 106 1 107 ) 108 ->addOption( 109 'range-max', 110 null, 111 InputOption::VALUE_REQUIRED, 112 $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX') 113 ) 114 ->addOption( 115 'range-size', 116 null, 117 InputOption::VALUE_REQUIRED, 118 $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'), 119 100 120 ); 121 ; 122 } 123 124 /** 125 * Executes the command reparser:reparse 126 * 127 * @param InputInterface $input 128 * @param OutputInterface $output 129 * @return integer 130 */ 131 protected function execute(InputInterface $input, OutputInterface $output) 132 { 133 $this->input = $input; 134 $this->output = $output; 135 $this->io = new SymfonyStyle($input, $output); 136 137 if (!$this->reparse_lock->acquire()) 138 { 139 throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); 140 } 141 142 $name = $input->getArgument('reparser-name'); 143 if ($name) 144 { 145 $name = $this->reparser_manager->find_reparser($name); 146 $this->reparse($name); 147 } 148 else 149 { 150 foreach ($this->reparsers as $name => $service) 151 { 152 $this->reparse($name); 153 } 154 } 155 156 $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); 157 158 $this->reparse_lock->release(); 159 160 return 0; 161 } 162 163 /** 164 * Get an option value, adjusted for given reparser 165 * 166 * Will use the last saved value if --resume is set and the option was not specified 167 * on the command line 168 * 169 * @param string $option_name Option name 170 * @return integer 171 */ 172 protected function get_option($option_name) 173 { 174 // Return the option from the resume_data if applicable 175 if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) 176 { 177 return $this->resume_data[$option_name]; 178 } 179 180 return $this->input->getOption($option_name); 181 } 182 183 /** 184 * Reparse all text handled by given reparser within given range 185 * 186 * @param string $name Reparser service name 187 */ 188 protected function reparse($name) 189 { 190 $reparser = $this->reparsers[$name]; 191 $this->resume_data = $this->reparser_manager->get_resume_data($name); 192 if ($this->input->getOption('dry-run')) 193 { 194 $reparser->disable_save(); 195 } 196 else 197 { 198 $reparser->enable_save(); 199 } 200 201 // Start at range-max if specified or at the highest ID otherwise 202 $max = $this->get_option('range-max'); 203 $min = $this->get_option('range-min'); 204 $size = $this->get_option('range-size'); 205 206 // range-max has no default value, it must be computed for each reparser 207 if ($max === null) 208 { 209 $max = $reparser->get_max_id(); 210 } 211 212 if ($max < $min) 213 { 214 return; 215 } 216 217 $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max)); 218 219 $progress = $this->create_progress_bar($max, $this->io, $this->output, true); 220 $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name())); 221 $progress->start(); 222 223 // Start from $max and decrement $current by $size until we reach $min 224 $current = $max; 225 while ($current >= $min) 226 { 227 $start = max($min, $current + 1 - $size); 228 $end = max($min, $current); 229 230 $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end)); 231 $reparser->reparse_range($start, $end); 232 233 $current = $start - 1; 234 $progress->setProgress($max + 1 - $start); 235 236 $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run')); 237 } 238 $progress->finish(); 239 240 $this->io->newLine(2); 241 } 242 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |