| Conditions | 8 |
| Paths | 11 |
| Total Lines | 87 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 117 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 118 | { |
||
| 119 | if (version_compare($this->currentInstalledVersion, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<')) { |
||
| 120 | $output->writeln($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => $this->currentInstalledVersion, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION])); |
||
| 121 | |||
| 122 | return false; |
||
| 123 | } |
||
| 124 | |||
| 125 | $io = new SymfonyStyle($input, $output); |
||
| 126 | $io->title($this->translator->__('Zikula Upgrader Script')); |
||
| 127 | $io->section($this->translator->__f('*** UPGRADING TO ZIKULA CORE %version% ***', ['%version%' => ZikulaKernel::VERSION])); |
||
| 128 | $io->text($this->translator->__f('Upgrading Zikula in %env% environment.', ['%env%' => $this->kernel->getEnvironment()])); |
||
| 129 | |||
| 130 | $warnings = $this->controllerHelper->initPhp(); |
||
| 131 | if (!empty($warnings)) { |
||
| 132 | $this->printWarnings($output, $warnings); |
||
| 133 | |||
| 134 | return false; |
||
| 135 | } |
||
| 136 | $checks = $this->controllerHelper->requirementsMet(); |
||
| 137 | if (true !== $checks) { |
||
|
|
|||
| 138 | $this->printRequirementsWarnings($output, $checks); |
||
| 139 | |||
| 140 | return false; |
||
| 141 | } |
||
| 142 | |||
| 143 | $count = $this->migrationHelper->countUnMigratedUsers(); |
||
| 144 | if ($count > 0) { |
||
| 145 | $io->text($this->translator->__('Beginning user migration...')); |
||
| 146 | $userMigrationMaxuid = (int)$this->migrationHelper->getMaxUnMigratedUid(); |
||
| 147 | $progressBar = new ProgressBar($output, (int)ceil($count / MigrationHelper::BATCH_LIMIT)); |
||
| 148 | $progressBar->start(); |
||
| 149 | $lastUid = 0; |
||
| 150 | do { |
||
| 151 | $result = $this->migrationHelper->migrateUsers($lastUid); |
||
| 152 | $lastUid = $result['lastUid']; |
||
| 153 | $progressBar->advance(); |
||
| 154 | } while ($lastUid < $userMigrationMaxuid); |
||
| 155 | $progressBar->finish(); |
||
| 156 | $io->success($this->translator->__('User migration complete!')); |
||
| 157 | } else { |
||
| 158 | $io->text($this->translator->__('There was no need to migrate any users.')); |
||
| 159 | } |
||
| 160 | |||
| 161 | // avoid warning in PHP 7.2 based on ini_set() usage which is caused by any access to the |
||
| 162 | // session before regeneration happens (e.g. by an event listener executed before a login) |
||
| 163 | // see issue #3898 for the details |
||
| 164 | $reportingLevel = error_reporting(); |
||
| 165 | error_reporting($reportingLevel & ~E_WARNING); |
||
| 166 | |||
| 167 | // get the settings from user input |
||
| 168 | $settings = $this->getHelper('form')->interactUsingForm(LocaleType::class, $input, $output, [ |
||
| 169 | 'choices' => $this->localeApi->getSupportedLocaleNames() |
||
| 170 | ]); |
||
| 171 | |||
| 172 | $data = $this->getHelper('form')->interactUsingForm(LoginType::class, $input, $output); |
||
| 173 | foreach ($data as $k => $v) { |
||
| 174 | $data[$k] = base64_encode($v); // encode so values are 'safe' for json |
||
| 175 | } |
||
| 176 | $settings = array_merge($settings, $data); |
||
| 177 | |||
| 178 | $data = $this->getHelper('form')->interactUsingForm(RequestContextType::class, $input, $output); |
||
| 179 | foreach ($data as $k => $v) { |
||
| 180 | $newKey = str_replace(':', '.', $k); |
||
| 181 | $data[$newKey] = $v; |
||
| 182 | unset($data[$k]); |
||
| 183 | } |
||
| 184 | $settings = array_merge($settings, $data); |
||
| 185 | |||
| 186 | $this->printSettings($settings, $io); |
||
| 187 | $io->newLine(); |
||
| 188 | |||
| 189 | // write the parameters to custom_parameters.yml |
||
| 190 | $yamlManager = new YamlDumper($this->kernel->getProjectDir() . '/app/config', 'custom_parameters.yml'); |
||
| 191 | $params = array_merge($yamlManager->getParameters(), $settings); |
||
| 192 | unset($params['upgrading']); |
||
| 193 | $yamlManager->setParameters($params); |
||
| 194 | |||
| 195 | // upgrade! |
||
| 196 | $ajaxStage = new AjaxUpgraderStage($this->translator, $this->currentInstalledVersion); |
||
| 197 | $this->stageHelper->handleAjaxStage($ajaxStage, $io); |
||
| 198 | |||
| 199 | error_reporting($reportingLevel); |
||
| 200 | |||
| 201 | $io->success($this->translator->__('UPGRADE COMPLETE!')); |
||
| 202 | |||
| 203 | return true; |
||
| 204 | } |
||
| 206 |