@@ -46,238 +46,238 @@ |
||
| 46 | 46 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 47 | 47 | |
| 48 | 48 | class Upgrade extends Command { |
| 49 | - public const ERROR_SUCCESS = 0; |
|
| 50 | - public const ERROR_NOT_INSTALLED = 1; |
|
| 51 | - public const ERROR_MAINTENANCE_MODE = 2; |
|
| 52 | - public const ERROR_UP_TO_DATE = 0; |
|
| 53 | - public const ERROR_INVALID_ARGUMENTS = 4; |
|
| 54 | - public const ERROR_FAILURE = 5; |
|
| 49 | + public const ERROR_SUCCESS = 0; |
|
| 50 | + public const ERROR_NOT_INSTALLED = 1; |
|
| 51 | + public const ERROR_MAINTENANCE_MODE = 2; |
|
| 52 | + public const ERROR_UP_TO_DATE = 0; |
|
| 53 | + public const ERROR_INVALID_ARGUMENTS = 4; |
|
| 54 | + public const ERROR_FAILURE = 5; |
|
| 55 | 55 | |
| 56 | - /** @var IConfig */ |
|
| 57 | - private $config; |
|
| 56 | + /** @var IConfig */ |
|
| 57 | + private $config; |
|
| 58 | 58 | |
| 59 | - /** @var ILogger */ |
|
| 60 | - private $logger; |
|
| 59 | + /** @var ILogger */ |
|
| 60 | + private $logger; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param ILogger $logger |
|
| 65 | - * @param Installer $installer |
|
| 66 | - */ |
|
| 67 | - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
| 68 | - parent::__construct(); |
|
| 69 | - $this->config = $config; |
|
| 70 | - $this->logger = $logger; |
|
| 71 | - $this->installer = $installer; |
|
| 72 | - } |
|
| 62 | + /** |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param ILogger $logger |
|
| 65 | + * @param Installer $installer |
|
| 66 | + */ |
|
| 67 | + public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
| 68 | + parent::__construct(); |
|
| 69 | + $this->config = $config; |
|
| 70 | + $this->logger = $logger; |
|
| 71 | + $this->installer = $installer; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - protected function configure() { |
|
| 75 | - $this |
|
| 76 | - ->setName('upgrade') |
|
| 77 | - ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
| 78 | - } |
|
| 74 | + protected function configure() { |
|
| 75 | + $this |
|
| 76 | + ->setName('upgrade') |
|
| 77 | + ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Execute the upgrade command |
|
| 82 | - * |
|
| 83 | - * @param InputInterface $input input interface |
|
| 84 | - * @param OutputInterface $output output interface |
|
| 85 | - */ |
|
| 86 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 87 | - if (Util::needUpgrade()) { |
|
| 88 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 89 | - // Prepend each line with a little timestamp |
|
| 90 | - $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
| 91 | - $output->setFormatter($timestampFormatter); |
|
| 92 | - } |
|
| 80 | + /** |
|
| 81 | + * Execute the upgrade command |
|
| 82 | + * |
|
| 83 | + * @param InputInterface $input input interface |
|
| 84 | + * @param OutputInterface $output output interface |
|
| 85 | + */ |
|
| 86 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 87 | + if (Util::needUpgrade()) { |
|
| 88 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 89 | + // Prepend each line with a little timestamp |
|
| 90 | + $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
| 91 | + $output->setFormatter($timestampFormatter); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $self = $this; |
|
| 95 | - $updater = new Updater( |
|
| 96 | - $this->config, |
|
| 97 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 98 | - $this->logger, |
|
| 99 | - $this->installer |
|
| 100 | - ); |
|
| 94 | + $self = $this; |
|
| 95 | + $updater = new Updater( |
|
| 96 | + $this->config, |
|
| 97 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 98 | + $this->logger, |
|
| 99 | + $this->installer |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 103 | - $progress = new ProgressBar($output); |
|
| 104 | - $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
| 105 | - $listener = function ($event) use ($progress, $output) { |
|
| 106 | - if ($event instanceof GenericEvent) { |
|
| 107 | - $message = $event->getSubject(); |
|
| 108 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 109 | - $output->writeln(' Checking table ' . $message); |
|
| 110 | - } else { |
|
| 111 | - if (strlen($message) > 60) { |
|
| 112 | - $message = substr($message, 0, 57) . '...'; |
|
| 113 | - } |
|
| 114 | - $progress->setMessage($message); |
|
| 115 | - if ($event[0] === 1) { |
|
| 116 | - $output->writeln(''); |
|
| 117 | - $progress->start($event[1]); |
|
| 118 | - } |
|
| 119 | - $progress->setProgress($event[0]); |
|
| 120 | - if ($event[0] === $event[1]) { |
|
| 121 | - $progress->setMessage('Done'); |
|
| 122 | - $progress->finish(); |
|
| 123 | - $output->writeln(''); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - }; |
|
| 128 | - $repairListener = function ($event) use ($progress, $output) { |
|
| 129 | - if (!$event instanceof GenericEvent) { |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - switch ($event->getSubject()) { |
|
| 133 | - case '\OC\Repair::startProgress': |
|
| 134 | - $progress->setMessage('Starting ...'); |
|
| 135 | - $output->writeln($event->getArgument(1)); |
|
| 136 | - $output->writeln(''); |
|
| 137 | - $progress->start($event->getArgument(0)); |
|
| 138 | - break; |
|
| 139 | - case '\OC\Repair::advance': |
|
| 140 | - $desc = $event->getArgument(1); |
|
| 141 | - if (!empty($desc)) { |
|
| 142 | - $progress->setMessage($desc); |
|
| 143 | - } |
|
| 144 | - $progress->advance($event->getArgument(0)); |
|
| 102 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 103 | + $progress = new ProgressBar($output); |
|
| 104 | + $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
| 105 | + $listener = function ($event) use ($progress, $output) { |
|
| 106 | + if ($event instanceof GenericEvent) { |
|
| 107 | + $message = $event->getSubject(); |
|
| 108 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 109 | + $output->writeln(' Checking table ' . $message); |
|
| 110 | + } else { |
|
| 111 | + if (strlen($message) > 60) { |
|
| 112 | + $message = substr($message, 0, 57) . '...'; |
|
| 113 | + } |
|
| 114 | + $progress->setMessage($message); |
|
| 115 | + if ($event[0] === 1) { |
|
| 116 | + $output->writeln(''); |
|
| 117 | + $progress->start($event[1]); |
|
| 118 | + } |
|
| 119 | + $progress->setProgress($event[0]); |
|
| 120 | + if ($event[0] === $event[1]) { |
|
| 121 | + $progress->setMessage('Done'); |
|
| 122 | + $progress->finish(); |
|
| 123 | + $output->writeln(''); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + }; |
|
| 128 | + $repairListener = function ($event) use ($progress, $output) { |
|
| 129 | + if (!$event instanceof GenericEvent) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + switch ($event->getSubject()) { |
|
| 133 | + case '\OC\Repair::startProgress': |
|
| 134 | + $progress->setMessage('Starting ...'); |
|
| 135 | + $output->writeln($event->getArgument(1)); |
|
| 136 | + $output->writeln(''); |
|
| 137 | + $progress->start($event->getArgument(0)); |
|
| 138 | + break; |
|
| 139 | + case '\OC\Repair::advance': |
|
| 140 | + $desc = $event->getArgument(1); |
|
| 141 | + if (!empty($desc)) { |
|
| 142 | + $progress->setMessage($desc); |
|
| 143 | + } |
|
| 144 | + $progress->advance($event->getArgument(0)); |
|
| 145 | 145 | |
| 146 | - break; |
|
| 147 | - case '\OC\Repair::finishProgress': |
|
| 148 | - $progress->setMessage('Done'); |
|
| 149 | - $progress->finish(); |
|
| 150 | - $output->writeln(''); |
|
| 151 | - break; |
|
| 152 | - case '\OC\Repair::step': |
|
| 153 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 154 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
| 155 | - } |
|
| 156 | - break; |
|
| 157 | - case '\OC\Repair::info': |
|
| 158 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 159 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
| 160 | - } |
|
| 161 | - break; |
|
| 162 | - case '\OC\Repair::warning': |
|
| 163 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
| 164 | - break; |
|
| 165 | - case '\OC\Repair::error': |
|
| 166 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
| 167 | - break; |
|
| 168 | - } |
|
| 169 | - }; |
|
| 146 | + break; |
|
| 147 | + case '\OC\Repair::finishProgress': |
|
| 148 | + $progress->setMessage('Done'); |
|
| 149 | + $progress->finish(); |
|
| 150 | + $output->writeln(''); |
|
| 151 | + break; |
|
| 152 | + case '\OC\Repair::step': |
|
| 153 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 154 | + $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
| 155 | + } |
|
| 156 | + break; |
|
| 157 | + case '\OC\Repair::info': |
|
| 158 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 159 | + $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
| 160 | + } |
|
| 161 | + break; |
|
| 162 | + case '\OC\Repair::warning': |
|
| 163 | + $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
| 164 | + break; |
|
| 165 | + case '\OC\Repair::error': |
|
| 166 | + $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
| 167 | + break; |
|
| 168 | + } |
|
| 169 | + }; |
|
| 170 | 170 | |
| 171 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
| 172 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
| 173 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 174 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 175 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 176 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 177 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 178 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 179 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 171 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
| 172 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
| 173 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 174 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 175 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 176 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 177 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 178 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 179 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 180 | 180 | |
| 181 | 181 | |
| 182 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
| 183 | - $output->writeln('<info>Turned on maintenance mode</info>'); |
|
| 184 | - }); |
|
| 185 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
| 186 | - $output->writeln('<info>Turned off maintenance mode</info>'); |
|
| 187 | - }); |
|
| 188 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
| 189 | - $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
| 190 | - }); |
|
| 191 | - $updater->listen('\OC\Updater', 'updateEnd', |
|
| 192 | - function ($success) use ($output, $self) { |
|
| 193 | - if ($success) { |
|
| 194 | - $message = "<info>Update successful</info>"; |
|
| 195 | - } else { |
|
| 196 | - $message = "<error>Update failed</error>"; |
|
| 197 | - } |
|
| 198 | - $output->writeln($message); |
|
| 199 | - }); |
|
| 200 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
| 201 | - $output->writeln('<info>Updating database schema</info>'); |
|
| 202 | - }); |
|
| 203 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
| 204 | - $output->writeln('<info>Updated database</info>'); |
|
| 205 | - }); |
|
| 206 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
| 207 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
| 208 | - }); |
|
| 209 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
| 210 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
| 211 | - }); |
|
| 212 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
| 213 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
| 214 | - }); |
|
| 215 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
| 216 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
| 217 | - }); |
|
| 218 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
| 219 | - $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
| 220 | - }); |
|
| 221 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
| 222 | - $output->writeln("<info>Updating <$app> ...</info>"); |
|
| 223 | - }); |
|
| 224 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
| 225 | - $output->writeln("<info>Updated <$app> to $version</info>"); |
|
| 226 | - }); |
|
| 227 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
| 228 | - $output->writeln("<error>$message</error>"); |
|
| 229 | - }); |
|
| 230 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 231 | - $output->writeln("<info>Setting log level to debug</info>"); |
|
| 232 | - }); |
|
| 233 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 234 | - $output->writeln("<info>Resetting log level</info>"); |
|
| 235 | - }); |
|
| 236 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
| 237 | - $output->writeln("<info>Starting code integrity check...</info>"); |
|
| 238 | - }); |
|
| 239 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
| 240 | - $output->writeln("<info>Finished code integrity check</info>"); |
|
| 241 | - }); |
|
| 182 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
| 183 | + $output->writeln('<info>Turned on maintenance mode</info>'); |
|
| 184 | + }); |
|
| 185 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
| 186 | + $output->writeln('<info>Turned off maintenance mode</info>'); |
|
| 187 | + }); |
|
| 188 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
| 189 | + $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
| 190 | + }); |
|
| 191 | + $updater->listen('\OC\Updater', 'updateEnd', |
|
| 192 | + function ($success) use ($output, $self) { |
|
| 193 | + if ($success) { |
|
| 194 | + $message = "<info>Update successful</info>"; |
|
| 195 | + } else { |
|
| 196 | + $message = "<error>Update failed</error>"; |
|
| 197 | + } |
|
| 198 | + $output->writeln($message); |
|
| 199 | + }); |
|
| 200 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
| 201 | + $output->writeln('<info>Updating database schema</info>'); |
|
| 202 | + }); |
|
| 203 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
| 204 | + $output->writeln('<info>Updated database</info>'); |
|
| 205 | + }); |
|
| 206 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
| 207 | + $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
| 208 | + }); |
|
| 209 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
| 210 | + $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
| 211 | + }); |
|
| 212 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
| 213 | + $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
| 214 | + }); |
|
| 215 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
| 216 | + $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
| 217 | + }); |
|
| 218 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
| 219 | + $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
| 220 | + }); |
|
| 221 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
| 222 | + $output->writeln("<info>Updating <$app> ...</info>"); |
|
| 223 | + }); |
|
| 224 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
| 225 | + $output->writeln("<info>Updated <$app> to $version</info>"); |
|
| 226 | + }); |
|
| 227 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
| 228 | + $output->writeln("<error>$message</error>"); |
|
| 229 | + }); |
|
| 230 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 231 | + $output->writeln("<info>Setting log level to debug</info>"); |
|
| 232 | + }); |
|
| 233 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 234 | + $output->writeln("<info>Resetting log level</info>"); |
|
| 235 | + }); |
|
| 236 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
| 237 | + $output->writeln("<info>Starting code integrity check...</info>"); |
|
| 238 | + }); |
|
| 239 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
| 240 | + $output->writeln("<info>Finished code integrity check</info>"); |
|
| 241 | + }); |
|
| 242 | 242 | |
| 243 | - $success = $updater->upgrade(); |
|
| 243 | + $success = $updater->upgrade(); |
|
| 244 | 244 | |
| 245 | - $this->postUpgradeCheck($input, $output); |
|
| 245 | + $this->postUpgradeCheck($input, $output); |
|
| 246 | 246 | |
| 247 | - if (!$success) { |
|
| 248 | - return self::ERROR_FAILURE; |
|
| 249 | - } |
|
| 247 | + if (!$success) { |
|
| 248 | + return self::ERROR_FAILURE; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return self::ERROR_SUCCESS; |
|
| 252 | - } elseif ($this->config->getSystemValueBool('maintenance')) { |
|
| 253 | - //Possible scenario: Nextcloud core is updated but an app failed |
|
| 254 | - $output->writeln('<comment>Nextcloud is in maintenance mode</comment>'); |
|
| 255 | - $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
| 256 | - . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
| 257 | - . 'upgrade procedure, remove the "maintenance mode" from ' |
|
| 258 | - . 'config.php and call this script again.</comment>' |
|
| 259 | - , true); |
|
| 260 | - return self::ERROR_MAINTENANCE_MODE; |
|
| 261 | - } else { |
|
| 262 | - $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
| 263 | - return self::ERROR_UP_TO_DATE; |
|
| 264 | - } |
|
| 265 | - } |
|
| 251 | + return self::ERROR_SUCCESS; |
|
| 252 | + } elseif ($this->config->getSystemValueBool('maintenance')) { |
|
| 253 | + //Possible scenario: Nextcloud core is updated but an app failed |
|
| 254 | + $output->writeln('<comment>Nextcloud is in maintenance mode</comment>'); |
|
| 255 | + $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
| 256 | + . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
| 257 | + . 'upgrade procedure, remove the "maintenance mode" from ' |
|
| 258 | + . 'config.php and call this script again.</comment>' |
|
| 259 | + , true); |
|
| 260 | + return self::ERROR_MAINTENANCE_MODE; |
|
| 261 | + } else { |
|
| 262 | + $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
| 263 | + return self::ERROR_UP_TO_DATE; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Perform a post upgrade check (specific to the command line tool) |
|
| 269 | - * |
|
| 270 | - * @param InputInterface $input input interface |
|
| 271 | - * @param OutputInterface $output output interface |
|
| 272 | - */ |
|
| 273 | - protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
| 274 | - $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
|
| 275 | - if (empty($trustedDomains)) { |
|
| 276 | - $output->write( |
|
| 277 | - '<warning>The setting "trusted_domains" could not be ' . |
|
| 278 | - 'set automatically by the upgrade script, ' . |
|
| 279 | - 'please set it manually</warning>' |
|
| 280 | - ); |
|
| 281 | - } |
|
| 282 | - } |
|
| 267 | + /** |
|
| 268 | + * Perform a post upgrade check (specific to the command line tool) |
|
| 269 | + * |
|
| 270 | + * @param InputInterface $input input interface |
|
| 271 | + * @param OutputInterface $output output interface |
|
| 272 | + */ |
|
| 273 | + protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
| 274 | + $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
|
| 275 | + if (empty($trustedDomains)) { |
|
| 276 | + $output->write( |
|
| 277 | + '<warning>The setting "trusted_domains" could not be ' . |
|
| 278 | + 'set automatically by the upgrade script, ' . |
|
| 279 | + 'please set it manually</warning>' |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 103 | 103 | $progress = new ProgressBar($output); |
| 104 | 104 | $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
| 105 | - $listener = function ($event) use ($progress, $output) { |
|
| 105 | + $listener = function($event) use ($progress, $output) { |
|
| 106 | 106 | if ($event instanceof GenericEvent) { |
| 107 | 107 | $message = $event->getSubject(); |
| 108 | 108 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
| 109 | - $output->writeln(' Checking table ' . $message); |
|
| 109 | + $output->writeln(' Checking table '.$message); |
|
| 110 | 110 | } else { |
| 111 | 111 | if (strlen($message) > 60) { |
| 112 | - $message = substr($message, 0, 57) . '...'; |
|
| 112 | + $message = substr($message, 0, 57).'...'; |
|
| 113 | 113 | } |
| 114 | 114 | $progress->setMessage($message); |
| 115 | 115 | if ($event[0] === 1) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | }; |
| 128 | - $repairListener = function ($event) use ($progress, $output) { |
|
| 128 | + $repairListener = function($event) use ($progress, $output) { |
|
| 129 | 129 | if (!$event instanceof GenericEvent) { |
| 130 | 130 | return; |
| 131 | 131 | } |
@@ -151,19 +151,19 @@ discard block |
||
| 151 | 151 | break; |
| 152 | 152 | case '\OC\Repair::step': |
| 153 | 153 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
| 154 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
| 154 | + $output->writeln('<info>Repair step: '.$event->getArgument(0).'</info>'); |
|
| 155 | 155 | } |
| 156 | 156 | break; |
| 157 | 157 | case '\OC\Repair::info': |
| 158 | 158 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
| 159 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
| 159 | + $output->writeln('<info>Repair info: '.$event->getArgument(0).'</info>'); |
|
| 160 | 160 | } |
| 161 | 161 | break; |
| 162 | 162 | case '\OC\Repair::warning': |
| 163 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
| 163 | + $output->writeln('<error>Repair warning: '.$event->getArgument(0).'</error>'); |
|
| 164 | 164 | break; |
| 165 | 165 | case '\OC\Repair::error': |
| 166 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
| 166 | + $output->writeln('<error>Repair error: '.$event->getArgument(0).'</error>'); |
|
| 167 | 167 | break; |
| 168 | 168 | } |
| 169 | 169 | }; |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
| 180 | 180 | |
| 181 | 181 | |
| 182 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
| 182 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($output) { |
|
| 183 | 183 | $output->writeln('<info>Turned on maintenance mode</info>'); |
| 184 | 184 | }); |
| 185 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
| 185 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($output) { |
|
| 186 | 186 | $output->writeln('<info>Turned off maintenance mode</info>'); |
| 187 | 187 | }); |
| 188 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
| 188 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use ($output) { |
|
| 189 | 189 | $output->writeln('<info>Maintenance mode is kept active</info>'); |
| 190 | 190 | }); |
| 191 | 191 | $updater->listen('\OC\Updater', 'updateEnd', |
| 192 | - function ($success) use ($output, $self) { |
|
| 192 | + function($success) use ($output, $self) { |
|
| 193 | 193 | if ($success) { |
| 194 | 194 | $message = "<info>Update successful</info>"; |
| 195 | 195 | } else { |
@@ -197,46 +197,46 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | $output->writeln($message); |
| 199 | 199 | }); |
| 200 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
| 200 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($output) { |
|
| 201 | 201 | $output->writeln('<info>Updating database schema</info>'); |
| 202 | 202 | }); |
| 203 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
| 203 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use ($output) { |
|
| 204 | 204 | $output->writeln('<info>Updated database</info>'); |
| 205 | 205 | }); |
| 206 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
| 207 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
| 206 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use ($output) { |
|
| 207 | + $output->writeln('<comment>Disabled incompatible app: '.$app.'</comment>'); |
|
| 208 | 208 | }); |
| 209 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
| 210 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
| 209 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($output) { |
|
| 210 | + $output->writeln('<info>Checking for update of app '.$app.' in appstore</info>'); |
|
| 211 | 211 | }); |
| 212 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
| 213 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
| 212 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($output) { |
|
| 213 | + $output->writeln('<info>Update app '.$app.' from appstore</info>'); |
|
| 214 | 214 | }); |
| 215 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
| 216 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
| 215 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($output) { |
|
| 216 | + $output->writeln('<info>Checked for update of app "'.$app.'" in appstore </info>'); |
|
| 217 | 217 | }); |
| 218 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
| 218 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($output) { |
|
| 219 | 219 | $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
| 220 | 220 | }); |
| 221 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
| 221 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function($app, $version) use ($output) { |
|
| 222 | 222 | $output->writeln("<info>Updating <$app> ...</info>"); |
| 223 | 223 | }); |
| 224 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
| 224 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($output) { |
|
| 225 | 225 | $output->writeln("<info>Updated <$app> to $version</info>"); |
| 226 | 226 | }); |
| 227 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
| 227 | + $updater->listen('\OC\Updater', 'failure', function($message) use ($output, $self) { |
|
| 228 | 228 | $output->writeln("<error>$message</error>"); |
| 229 | 229 | }); |
| 230 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 230 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use ($output) { |
|
| 231 | 231 | $output->writeln("<info>Setting log level to debug</info>"); |
| 232 | 232 | }); |
| 233 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
| 233 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($output) { |
|
| 234 | 234 | $output->writeln("<info>Resetting log level</info>"); |
| 235 | 235 | }); |
| 236 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
| 236 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($output) { |
|
| 237 | 237 | $output->writeln("<info>Starting code integrity check...</info>"); |
| 238 | 238 | }); |
| 239 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
| 239 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($output) { |
|
| 240 | 240 | $output->writeln("<info>Finished code integrity check</info>"); |
| 241 | 241 | }); |
| 242 | 242 | |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
| 275 | 275 | if (empty($trustedDomains)) { |
| 276 | 276 | $output->write( |
| 277 | - '<warning>The setting "trusted_domains" could not be ' . |
|
| 278 | - 'set automatically by the upgrade script, ' . |
|
| 277 | + '<warning>The setting "trusted_domains" could not be '. |
|
| 278 | + 'set automatically by the upgrade script, '. |
|
| 279 | 279 | 'please set it manually</warning>' |
| 280 | 280 | ); |
| 281 | 281 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 37 | 37 | |
| 38 | 38 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
| 39 | - @set_time_limit(0); |
|
| 39 | + @set_time_limit(0); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | require_once '../../lib/base.php'; |
@@ -50,176 +50,176 @@ discard block |
||
| 50 | 50 | $eventSource->send('success', $l->t('Preparing update')); |
| 51 | 51 | |
| 52 | 52 | class FeedBackHandler { |
| 53 | - /** @var integer */ |
|
| 54 | - private $progressStateMax = 100; |
|
| 55 | - /** @var integer */ |
|
| 56 | - private $progressStateStep = 0; |
|
| 57 | - /** @var string */ |
|
| 58 | - private $currentStep; |
|
| 59 | - /** @var \OCP\IEventSource */ |
|
| 60 | - private $eventSource; |
|
| 61 | - /** @var \OCP\IL10N */ |
|
| 62 | - private $l10n; |
|
| 63 | - |
|
| 64 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
| 65 | - $this->eventSource = $eventSource; |
|
| 66 | - $this->l10n = $l10n; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function handleRepairFeedback($event) { |
|
| 70 | - if (!$event instanceof GenericEvent) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - switch ($event->getSubject()) { |
|
| 75 | - case '\OC\Repair::startProgress': |
|
| 76 | - $this->progressStateMax = $event->getArgument(0); |
|
| 77 | - $this->progressStateStep = 0; |
|
| 78 | - $this->currentStep = $event->getArgument(1); |
|
| 79 | - break; |
|
| 80 | - case '\OC\Repair::advance': |
|
| 81 | - $this->progressStateStep += $event->getArgument(0); |
|
| 82 | - $desc = $event->getArgument(1); |
|
| 83 | - if (empty($desc)) { |
|
| 84 | - $desc = $this->currentStep; |
|
| 85 | - } |
|
| 86 | - $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
| 87 | - break; |
|
| 88 | - case '\OC\Repair::finishProgress': |
|
| 89 | - $this->progressStateMax = $this->progressStateStep; |
|
| 90 | - $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
| 91 | - break; |
|
| 92 | - case '\OC\Repair::step': |
|
| 93 | - $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
| 94 | - break; |
|
| 95 | - case '\OC\Repair::info': |
|
| 96 | - $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
| 97 | - break; |
|
| 98 | - case '\OC\Repair::warning': |
|
| 99 | - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
| 100 | - break; |
|
| 101 | - case '\OC\Repair::error': |
|
| 102 | - $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
| 103 | - break; |
|
| 104 | - } |
|
| 105 | - } |
|
| 53 | + /** @var integer */ |
|
| 54 | + private $progressStateMax = 100; |
|
| 55 | + /** @var integer */ |
|
| 56 | + private $progressStateStep = 0; |
|
| 57 | + /** @var string */ |
|
| 58 | + private $currentStep; |
|
| 59 | + /** @var \OCP\IEventSource */ |
|
| 60 | + private $eventSource; |
|
| 61 | + /** @var \OCP\IL10N */ |
|
| 62 | + private $l10n; |
|
| 63 | + |
|
| 64 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
| 65 | + $this->eventSource = $eventSource; |
|
| 66 | + $this->l10n = $l10n; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function handleRepairFeedback($event) { |
|
| 70 | + if (!$event instanceof GenericEvent) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + switch ($event->getSubject()) { |
|
| 75 | + case '\OC\Repair::startProgress': |
|
| 76 | + $this->progressStateMax = $event->getArgument(0); |
|
| 77 | + $this->progressStateStep = 0; |
|
| 78 | + $this->currentStep = $event->getArgument(1); |
|
| 79 | + break; |
|
| 80 | + case '\OC\Repair::advance': |
|
| 81 | + $this->progressStateStep += $event->getArgument(0); |
|
| 82 | + $desc = $event->getArgument(1); |
|
| 83 | + if (empty($desc)) { |
|
| 84 | + $desc = $this->currentStep; |
|
| 85 | + } |
|
| 86 | + $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
| 87 | + break; |
|
| 88 | + case '\OC\Repair::finishProgress': |
|
| 89 | + $this->progressStateMax = $this->progressStateStep; |
|
| 90 | + $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
| 91 | + break; |
|
| 92 | + case '\OC\Repair::step': |
|
| 93 | + $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
| 94 | + break; |
|
| 95 | + case '\OC\Repair::info': |
|
| 96 | + $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
| 97 | + break; |
|
| 98 | + case '\OC\Repair::warning': |
|
| 99 | + $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
| 100 | + break; |
|
| 101 | + case '\OC\Repair::error': |
|
| 102 | + $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
| 103 | + break; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (\OCP\Util::needUpgrade()) { |
| 109 | - $config = \OC::$server->getSystemConfig(); |
|
| 110 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
| 111 | - $eventSource->send('failure', $l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
| 112 | - $eventSource->close(); |
|
| 113 | - exit(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // if a user is currently logged in, their session must be ignored to |
|
| 117 | - // avoid side effects |
|
| 118 | - \OC_User::setIncognitoMode(true); |
|
| 119 | - |
|
| 120 | - $logger = \OC::$server->getLogger(); |
|
| 121 | - $config = \OC::$server->getConfig(); |
|
| 122 | - $updater = new \OC\Updater( |
|
| 123 | - $config, |
|
| 124 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 125 | - $logger, |
|
| 126 | - \OC::$server->query(\OC\Installer::class) |
|
| 127 | - ); |
|
| 128 | - $incompatibleApps = []; |
|
| 129 | - |
|
| 130 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
| 132 | - if ($event instanceof GenericEvent) { |
|
| 133 | - $eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 134 | - } |
|
| 135 | - }); |
|
| 136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
| 137 | - if ($event instanceof GenericEvent) { |
|
| 138 | - $eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 139 | - } |
|
| 140 | - }); |
|
| 141 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
| 142 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 143 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
| 144 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 145 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
| 146 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
| 147 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
| 148 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
| 149 | - |
|
| 150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
| 151 | - $eventSource->send('success', $l->t('Turned on maintenance mode')); |
|
| 152 | - }); |
|
| 153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
| 154 | - $eventSource->send('success', $l->t('Turned off maintenance mode')); |
|
| 155 | - }); |
|
| 156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
| 157 | - $eventSource->send('success', $l->t('Maintenance mode is kept active')); |
|
| 158 | - }); |
|
| 159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
| 160 | - $eventSource->send('success', $l->t('Updating database schema')); |
|
| 161 | - }); |
|
| 162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
| 163 | - $eventSource->send('success', $l->t('Updated database')); |
|
| 164 | - }); |
|
| 165 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
| 166 | - $eventSource->send('success', $l->t('Checking for update of app "%s" in appstore', [$app])); |
|
| 167 | - }); |
|
| 168 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 169 | - $eventSource->send('success', $l->t('Update app "%s" from appstore', [$app])); |
|
| 170 | - }); |
|
| 171 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 172 | - $eventSource->send('success', $l->t('Checked for update of app "%s" in appstore', [$app])); |
|
| 173 | - }); |
|
| 174 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
| 175 | - $eventSource->send('success', $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
| 176 | - }); |
|
| 177 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
| 178 | - $eventSource->send('success', $l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
| 179 | - }); |
|
| 180 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
| 181 | - $incompatibleApps[] = $app; |
|
| 182 | - }); |
|
| 183 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
| 184 | - $eventSource->send('failure', $message); |
|
| 185 | - $eventSource->close(); |
|
| 186 | - $config->setSystemValue('maintenance', false); |
|
| 187 | - }); |
|
| 188 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 189 | - $eventSource->send('success', $l->t('Set log level to debug')); |
|
| 190 | - }); |
|
| 191 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 192 | - $eventSource->send('success', $l->t('Reset log level')); |
|
| 193 | - }); |
|
| 194 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 195 | - $eventSource->send('success', $l->t('Starting code integrity check')); |
|
| 196 | - }); |
|
| 197 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 198 | - $eventSource->send('success', $l->t('Finished code integrity check')); |
|
| 199 | - }); |
|
| 200 | - |
|
| 201 | - try { |
|
| 202 | - $updater->upgrade(); |
|
| 203 | - } catch (\Exception $e) { |
|
| 204 | - \OC::$server->getLogger()->logException($e, [ |
|
| 205 | - 'level' => ILogger::ERROR, |
|
| 206 | - 'app' => 'update', |
|
| 207 | - ]); |
|
| 208 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
| 209 | - $eventSource->close(); |
|
| 210 | - exit(); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $disabledApps = []; |
|
| 214 | - foreach ($incompatibleApps as $app) { |
|
| 215 | - $disabledApps[$app] = $l->t('%s (incompatible)', [$app]); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if (!empty($disabledApps)) { |
|
| 219 | - $eventSource->send('notice', $l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
| 220 | - } |
|
| 109 | + $config = \OC::$server->getSystemConfig(); |
|
| 110 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
| 111 | + $eventSource->send('failure', $l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
| 112 | + $eventSource->close(); |
|
| 113 | + exit(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // if a user is currently logged in, their session must be ignored to |
|
| 117 | + // avoid side effects |
|
| 118 | + \OC_User::setIncognitoMode(true); |
|
| 119 | + |
|
| 120 | + $logger = \OC::$server->getLogger(); |
|
| 121 | + $config = \OC::$server->getConfig(); |
|
| 122 | + $updater = new \OC\Updater( |
|
| 123 | + $config, |
|
| 124 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 125 | + $logger, |
|
| 126 | + \OC::$server->query(\OC\Installer::class) |
|
| 127 | + ); |
|
| 128 | + $incompatibleApps = []; |
|
| 129 | + |
|
| 130 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
| 132 | + if ($event instanceof GenericEvent) { |
|
| 133 | + $eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 134 | + } |
|
| 135 | + }); |
|
| 136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
| 137 | + if ($event instanceof GenericEvent) { |
|
| 138 | + $eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 139 | + } |
|
| 140 | + }); |
|
| 141 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
| 142 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 143 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
| 144 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 145 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
| 146 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
| 147 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
| 148 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
| 149 | + |
|
| 150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
| 151 | + $eventSource->send('success', $l->t('Turned on maintenance mode')); |
|
| 152 | + }); |
|
| 153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
| 154 | + $eventSource->send('success', $l->t('Turned off maintenance mode')); |
|
| 155 | + }); |
|
| 156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
| 157 | + $eventSource->send('success', $l->t('Maintenance mode is kept active')); |
|
| 158 | + }); |
|
| 159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
| 160 | + $eventSource->send('success', $l->t('Updating database schema')); |
|
| 161 | + }); |
|
| 162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
| 163 | + $eventSource->send('success', $l->t('Updated database')); |
|
| 164 | + }); |
|
| 165 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
| 166 | + $eventSource->send('success', $l->t('Checking for update of app "%s" in appstore', [$app])); |
|
| 167 | + }); |
|
| 168 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 169 | + $eventSource->send('success', $l->t('Update app "%s" from appstore', [$app])); |
|
| 170 | + }); |
|
| 171 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 172 | + $eventSource->send('success', $l->t('Checked for update of app "%s" in appstore', [$app])); |
|
| 173 | + }); |
|
| 174 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
| 175 | + $eventSource->send('success', $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
| 176 | + }); |
|
| 177 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
| 178 | + $eventSource->send('success', $l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
| 179 | + }); |
|
| 180 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
| 181 | + $incompatibleApps[] = $app; |
|
| 182 | + }); |
|
| 183 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
| 184 | + $eventSource->send('failure', $message); |
|
| 185 | + $eventSource->close(); |
|
| 186 | + $config->setSystemValue('maintenance', false); |
|
| 187 | + }); |
|
| 188 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 189 | + $eventSource->send('success', $l->t('Set log level to debug')); |
|
| 190 | + }); |
|
| 191 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 192 | + $eventSource->send('success', $l->t('Reset log level')); |
|
| 193 | + }); |
|
| 194 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 195 | + $eventSource->send('success', $l->t('Starting code integrity check')); |
|
| 196 | + }); |
|
| 197 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 198 | + $eventSource->send('success', $l->t('Finished code integrity check')); |
|
| 199 | + }); |
|
| 200 | + |
|
| 201 | + try { |
|
| 202 | + $updater->upgrade(); |
|
| 203 | + } catch (\Exception $e) { |
|
| 204 | + \OC::$server->getLogger()->logException($e, [ |
|
| 205 | + 'level' => ILogger::ERROR, |
|
| 206 | + 'app' => 'update', |
|
| 207 | + ]); |
|
| 208 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
| 209 | + $eventSource->close(); |
|
| 210 | + exit(); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $disabledApps = []; |
|
| 214 | + foreach ($incompatibleApps as $app) { |
|
| 215 | + $disabledApps[$app] = $l->t('%s (incompatible)', [$app]); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if (!empty($disabledApps)) { |
|
| 219 | + $eventSource->send('notice', $l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
| 220 | + } |
|
| 221 | 221 | } else { |
| 222 | - $eventSource->send('notice', $l->t('Already up to date')); |
|
| 222 | + $eventSource->send('notice', $l->t('Already up to date')); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $eventSource->send('done', ''); |
@@ -90,16 +90,16 @@ discard block |
||
| 90 | 90 | $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
| 91 | 91 | break; |
| 92 | 92 | case '\OC\Repair::step': |
| 93 | - $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
| 93 | + $this->eventSource->send('success', $this->l10n->t('Repair step:').' '.$event->getArgument(0)); |
|
| 94 | 94 | break; |
| 95 | 95 | case '\OC\Repair::info': |
| 96 | - $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
| 96 | + $this->eventSource->send('success', $this->l10n->t('Repair info:').' '.$event->getArgument(0)); |
|
| 97 | 97 | break; |
| 98 | 98 | case '\OC\Repair::warning': |
| 99 | - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
| 99 | + $this->eventSource->send('notice', $this->l10n->t('Repair warning:').' '.$event->getArgument(0)); |
|
| 100 | 100 | break; |
| 101 | 101 | case '\OC\Repair::error': |
| 102 | - $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
| 102 | + $this->eventSource->send('notice', $this->l10n->t('Repair error:').' '.$event->getArgument(0)); |
|
| 103 | 103 | break; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | $incompatibleApps = []; |
| 129 | 129 | |
| 130 | 130 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
| 131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
| 132 | 132 | if ($event instanceof GenericEvent) { |
| 133 | 133 | $eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
| 134 | 134 | } |
| 135 | 135 | }); |
| 136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
| 136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
| 137 | 137 | if ($event instanceof GenericEvent) { |
| 138 | 138 | $eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
| 139 | 139 | } |
@@ -147,54 +147,54 @@ discard block |
||
| 147 | 147 | $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
| 148 | 148 | $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
| 149 | 149 | |
| 150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
| 150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($eventSource, $l) { |
|
| 151 | 151 | $eventSource->send('success', $l->t('Turned on maintenance mode')); |
| 152 | 152 | }); |
| 153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
| 153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($eventSource, $l) { |
|
| 154 | 154 | $eventSource->send('success', $l->t('Turned off maintenance mode')); |
| 155 | 155 | }); |
| 156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
| 156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use ($eventSource, $l) { |
|
| 157 | 157 | $eventSource->send('success', $l->t('Maintenance mode is kept active')); |
| 158 | 158 | }); |
| 159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
| 159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($eventSource, $l) { |
|
| 160 | 160 | $eventSource->send('success', $l->t('Updating database schema')); |
| 161 | 161 | }); |
| 162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
| 162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use ($eventSource, $l) { |
|
| 163 | 163 | $eventSource->send('success', $l->t('Updated database')); |
| 164 | 164 | }); |
| 165 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
| 165 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($eventSource, $l) { |
|
| 166 | 166 | $eventSource->send('success', $l->t('Checking for update of app "%s" in appstore', [$app])); |
| 167 | 167 | }); |
| 168 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 168 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($eventSource, $l) { |
|
| 169 | 169 | $eventSource->send('success', $l->t('Update app "%s" from appstore', [$app])); |
| 170 | 170 | }); |
| 171 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 171 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($eventSource, $l) { |
|
| 172 | 172 | $eventSource->send('success', $l->t('Checked for update of app "%s" in appstore', [$app])); |
| 173 | 173 | }); |
| 174 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
| 174 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($eventSource, $l) { |
|
| 175 | 175 | $eventSource->send('success', $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
| 176 | 176 | }); |
| 177 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
| 177 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($eventSource, $l) { |
|
| 178 | 178 | $eventSource->send('success', $l->t('Updated "%1$s" to %2$s', [$app, $version])); |
| 179 | 179 | }); |
| 180 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
| 180 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use (&$incompatibleApps) { |
|
| 181 | 181 | $incompatibleApps[] = $app; |
| 182 | 182 | }); |
| 183 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
| 183 | + $updater->listen('\OC\Updater', 'failure', function($message) use ($eventSource, $config) { |
|
| 184 | 184 | $eventSource->send('failure', $message); |
| 185 | 185 | $eventSource->close(); |
| 186 | 186 | $config->setSystemValue('maintenance', false); |
| 187 | 187 | }); |
| 188 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 188 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 189 | 189 | $eventSource->send('success', $l->t('Set log level to debug')); |
| 190 | 190 | }); |
| 191 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 191 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
| 192 | 192 | $eventSource->send('success', $l->t('Reset log level')); |
| 193 | 193 | }); |
| 194 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 194 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
| 195 | 195 | $eventSource->send('success', $l->t('Starting code integrity check')); |
| 196 | 196 | }); |
| 197 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
| 197 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
| 198 | 198 | $eventSource->send('success', $l->t('Finished code integrity check')); |
| 199 | 199 | }); |
| 200 | 200 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | 'level' => ILogger::ERROR, |
| 206 | 206 | 'app' => 'update', |
| 207 | 207 | ]); |
| 208 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
| 208 | + $eventSource->send('failure', get_class($e).': '.$e->getMessage()); |
|
| 209 | 209 | $eventSource->close(); |
| 210 | 210 | exit(); |
| 211 | 211 | } |
@@ -59,520 +59,520 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class Updater extends BasicEmitter { |
| 61 | 61 | |
| 62 | - /** @var ILogger $log */ |
|
| 63 | - private $log; |
|
| 64 | - |
|
| 65 | - /** @var IConfig */ |
|
| 66 | - private $config; |
|
| 67 | - |
|
| 68 | - /** @var Checker */ |
|
| 69 | - private $checker; |
|
| 70 | - |
|
| 71 | - /** @var Installer */ |
|
| 72 | - private $installer; |
|
| 73 | - |
|
| 74 | - private $logLevelNames = [ |
|
| 75 | - 0 => 'Debug', |
|
| 76 | - 1 => 'Info', |
|
| 77 | - 2 => 'Warning', |
|
| 78 | - 3 => 'Error', |
|
| 79 | - 4 => 'Fatal', |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param IConfig $config |
|
| 84 | - * @param Checker $checker |
|
| 85 | - * @param ILogger $log |
|
| 86 | - * @param Installer $installer |
|
| 87 | - */ |
|
| 88 | - public function __construct(IConfig $config, |
|
| 89 | - Checker $checker, |
|
| 90 | - ILogger $log = null, |
|
| 91 | - Installer $installer) { |
|
| 92 | - $this->log = $log; |
|
| 93 | - $this->config = $config; |
|
| 94 | - $this->checker = $checker; |
|
| 95 | - $this->installer = $installer; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 100 | - * except the main .htaccess file |
|
| 101 | - * |
|
| 102 | - * @return bool true if the operation succeeded, false otherwise |
|
| 103 | - */ |
|
| 104 | - public function upgrade() { |
|
| 105 | - $this->emitRepairEvents(); |
|
| 106 | - $this->logAllEvents(); |
|
| 107 | - |
|
| 108 | - $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
| 109 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 110 | - $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
| 111 | - |
|
| 112 | - $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
| 113 | - |
|
| 114 | - if (!$wasMaintenanceModeEnabled) { |
|
| 115 | - $this->config->setSystemValue('maintenance', true); |
|
| 116 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Clear CAN_INSTALL file if not on git |
|
| 120 | - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 121 | - if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 122 | - $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 127 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 128 | - |
|
| 129 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 130 | - |
|
| 131 | - $success = true; |
|
| 132 | - try { |
|
| 133 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
| 134 | - } catch (HintException $exception) { |
|
| 135 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 136 | - $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 137 | - $success = false; |
|
| 138 | - } catch (\Exception $exception) { |
|
| 139 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 140 | - $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 141 | - $success = false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $this->emit('\OC\Updater', 'updateEnd', [$success]); |
|
| 145 | - |
|
| 146 | - if (!$wasMaintenanceModeEnabled && $success) { |
|
| 147 | - $this->config->setSystemValue('maintenance', false); |
|
| 148 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 149 | - } else { |
|
| 150 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 154 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
| 155 | - $this->config->setSystemValue('installed', true); |
|
| 156 | - |
|
| 157 | - return $success; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Return version from which this version is allowed to upgrade from |
|
| 162 | - * |
|
| 163 | - * @return array allowed previous versions per vendor |
|
| 164 | - */ |
|
| 165 | - private function getAllowedPreviousVersions() { |
|
| 166 | - // this should really be a JSON file |
|
| 167 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 168 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 169 | - return $OC_VersionCanBeUpgradedFrom; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Return vendor from which this version was published |
|
| 174 | - * |
|
| 175 | - * @return string Get the vendor |
|
| 176 | - */ |
|
| 177 | - private function getVendor() { |
|
| 178 | - // this should really be a JSON file |
|
| 179 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 180 | - /** @var string $vendor */ |
|
| 181 | - return (string) $vendor; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Whether an upgrade to a specified version is possible |
|
| 186 | - * @param string $oldVersion |
|
| 187 | - * @param string $newVersion |
|
| 188 | - * @param array $allowedPreviousVersions |
|
| 189 | - * @return bool |
|
| 190 | - */ |
|
| 191 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 192 | - $version = explode('.', $oldVersion); |
|
| 193 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 194 | - |
|
| 195 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 196 | - |
|
| 197 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 198 | - if ($currentVendor === '' && ( |
|
| 199 | - isset($allowedPreviousVersions['owncloud'][$oldVersion]) || |
|
| 200 | - isset($allowedPreviousVersions['owncloud'][$majorMinor]) |
|
| 201 | - )) { |
|
| 202 | - $currentVendor = 'owncloud'; |
|
| 203 | - $this->config->setAppValue('core', 'vendor', $currentVendor); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($currentVendor === 'nextcloud') { |
|
| 207 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 208 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 209 | - $this->config->getSystemValue('debug', false)); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Check if the instance can be migrated |
|
| 213 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 214 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 219 | - * except the main .htaccess file |
|
| 220 | - * |
|
| 221 | - * @param string $currentVersion current version to upgrade to |
|
| 222 | - * @param string $installedVersion previous version from which to upgrade from |
|
| 223 | - * |
|
| 224 | - * @throws \Exception |
|
| 225 | - */ |
|
| 226 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
| 227 | - // Stop update if the update is over several major versions |
|
| 228 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 229 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 230 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Update .htaccess files |
|
| 234 | - try { |
|
| 235 | - Setup::updateHtaccess(); |
|
| 236 | - Setup::protectDataDirectory(); |
|
| 237 | - } catch (\Exception $e) { |
|
| 238 | - throw new \Exception($e->getMessage()); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // create empty file in data dir, so we can later find |
|
| 242 | - // out that this is indeed an ownCloud data directory |
|
| 243 | - // (in case it didn't exist before) |
|
| 244 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 245 | - |
|
| 246 | - // pre-upgrade repairs |
|
| 247 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 248 | - $repair->run(); |
|
| 249 | - |
|
| 250 | - $this->doCoreUpgrade(); |
|
| 251 | - |
|
| 252 | - try { |
|
| 253 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 254 | - Setup::installBackgroundJobs(); |
|
| 255 | - } catch (\Exception $e) { |
|
| 256 | - throw new \Exception($e->getMessage()); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // update all shipped apps |
|
| 260 | - $this->checkAppsRequirements(); |
|
| 261 | - $this->doAppUpgrade(); |
|
| 262 | - |
|
| 263 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 264 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 265 | - |
|
| 266 | - // upgrade appstore apps |
|
| 267 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 268 | - $autoDisabledApps = \OC::$server->getAppManager()->getAutoDisabledApps(); |
|
| 269 | - $this->upgradeAppStoreApps($autoDisabledApps, true); |
|
| 270 | - |
|
| 271 | - // install new shipped apps on upgrade |
|
| 272 | - $errors = Installer::installShippedApps(true); |
|
| 273 | - foreach ($errors as $appId => $exception) { |
|
| 274 | - /** @var \Exception $exception */ |
|
| 275 | - $this->log->logException($exception, ['app' => $appId]); |
|
| 276 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // post-upgrade repairs |
|
| 280 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 281 | - $repair->run(); |
|
| 282 | - |
|
| 283 | - //Invalidate update feed |
|
| 284 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 285 | - |
|
| 286 | - // Check for code integrity if not disabled |
|
| 287 | - if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 288 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 289 | - $this->checker->runInstanceVerification(); |
|
| 290 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // only set the final version if everything went well |
|
| 294 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 295 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - protected function doCoreUpgrade() { |
|
| 299 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 300 | - |
|
| 301 | - // execute core migrations |
|
| 302 | - $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 303 | - $ms->migrate(); |
|
| 304 | - |
|
| 305 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 310 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 311 | - * |
|
| 312 | - * @throws NeedsUpdateException |
|
| 313 | - */ |
|
| 314 | - protected function doAppUpgrade() { |
|
| 315 | - $apps = \OC_App::getEnabledApps(); |
|
| 316 | - $priorityTypes = ['authentication', 'filesystem', 'logging']; |
|
| 317 | - $pseudoOtherType = 'other'; |
|
| 318 | - $stacks = [$pseudoOtherType => []]; |
|
| 319 | - |
|
| 320 | - foreach ($apps as $appId) { |
|
| 321 | - $priorityType = false; |
|
| 322 | - foreach ($priorityTypes as $type) { |
|
| 323 | - if (!isset($stacks[$type])) { |
|
| 324 | - $stacks[$type] = []; |
|
| 325 | - } |
|
| 326 | - if (\OC_App::isType($appId, [$type])) { |
|
| 327 | - $stacks[$type][] = $appId; |
|
| 328 | - $priorityType = true; |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - if (!$priorityType) { |
|
| 333 | - $stacks[$pseudoOtherType][] = $appId; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - foreach (array_merge($priorityTypes, [$pseudoOtherType]) as $type) { |
|
| 337 | - $stack = $stacks[$type]; |
|
| 338 | - foreach ($stack as $appId) { |
|
| 339 | - if (\OC_App::shouldUpgrade($appId)) { |
|
| 340 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 341 | - \OC_App::updateApp($appId); |
|
| 342 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 343 | - } |
|
| 344 | - if ($type !== $pseudoOtherType) { |
|
| 345 | - // load authentication, filesystem and logging apps after |
|
| 346 | - // upgrading them. Other apps my need to rely on modifying |
|
| 347 | - // user and/or filesystem aspects. |
|
| 348 | - \OC_App::loadApp($appId); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * check if the current enabled apps are compatible with the current |
|
| 356 | - * ownCloud version. disable them if not. |
|
| 357 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 358 | - * party apps installed. |
|
| 359 | - * |
|
| 360 | - * @return array |
|
| 361 | - * @throws \Exception |
|
| 362 | - */ |
|
| 363 | - private function checkAppsRequirements() { |
|
| 364 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 365 | - $apps = OC_App::getEnabledApps(); |
|
| 366 | - $version = implode('.', Util::getVersion()); |
|
| 367 | - $disabledApps = []; |
|
| 368 | - $appManager = \OC::$server->getAppManager(); |
|
| 369 | - foreach ($apps as $app) { |
|
| 370 | - // check if the app is compatible with this version of Nextcloud |
|
| 371 | - $info = OC_App::getAppInfo($app); |
|
| 372 | - if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
| 373 | - if ($appManager->isShipped($app)) { |
|
| 374 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 375 | - } |
|
| 376 | - \OC::$server->getAppManager()->disableApp($app, true); |
|
| 377 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
|
| 378 | - } |
|
| 379 | - // no need to disable any app in case this is a non-core upgrade |
|
| 380 | - if (!$isCoreUpgrade) { |
|
| 381 | - continue; |
|
| 382 | - } |
|
| 383 | - // shipped apps will remain enabled |
|
| 384 | - if ($appManager->isShipped($app)) { |
|
| 385 | - continue; |
|
| 386 | - } |
|
| 387 | - // authentication and session apps will remain enabled as well |
|
| 388 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 389 | - continue; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - return $disabledApps; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @return bool |
|
| 397 | - */ |
|
| 398 | - private function isCodeUpgrade() { |
|
| 399 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 400 | - $currentVersion = implode('.', Util::getVersion()); |
|
| 401 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 402 | - return true; |
|
| 403 | - } |
|
| 404 | - return false; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @param array $disabledApps |
|
| 409 | - * @param bool $reenable |
|
| 410 | - * @throws \Exception |
|
| 411 | - */ |
|
| 412 | - private function upgradeAppStoreApps(array $disabledApps, $reenable = false) { |
|
| 413 | - foreach ($disabledApps as $app) { |
|
| 414 | - try { |
|
| 415 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 416 | - if ($this->installer->isUpdateAvailable($app)) { |
|
| 417 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 418 | - $this->installer->updateAppstoreApp($app); |
|
| 419 | - } |
|
| 420 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 421 | - |
|
| 422 | - if ($reenable) { |
|
| 423 | - $ocApp = new \OC_App(); |
|
| 424 | - $ocApp->enable($app); |
|
| 425 | - } |
|
| 426 | - } catch (\Exception $ex) { |
|
| 427 | - $this->log->logException($ex, ['app' => 'core']); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Forward messages emitted by the repair routine |
|
| 434 | - */ |
|
| 435 | - private function emitRepairEvents() { |
|
| 436 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 437 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 438 | - if ($event instanceof GenericEvent) { |
|
| 439 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 440 | - } |
|
| 441 | - }); |
|
| 442 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 443 | - if ($event instanceof GenericEvent) { |
|
| 444 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 445 | - } |
|
| 446 | - }); |
|
| 447 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 448 | - if ($event instanceof GenericEvent) { |
|
| 449 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 450 | - } |
|
| 451 | - }); |
|
| 452 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 453 | - if ($event instanceof GenericEvent) { |
|
| 454 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 455 | - } |
|
| 456 | - }); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - private function logAllEvents() { |
|
| 460 | - $log = $this->log; |
|
| 461 | - |
|
| 462 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 463 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 464 | - if (!$event instanceof GenericEvent) { |
|
| 465 | - return; |
|
| 466 | - } |
|
| 467 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 468 | - }); |
|
| 469 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 470 | - if (!$event instanceof GenericEvent) { |
|
| 471 | - return; |
|
| 472 | - } |
|
| 473 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 474 | - }); |
|
| 475 | - |
|
| 476 | - $repairListener = function ($event) use ($log) { |
|
| 477 | - if (!$event instanceof GenericEvent) { |
|
| 478 | - return; |
|
| 479 | - } |
|
| 480 | - switch ($event->getSubject()) { |
|
| 481 | - case '\OC\Repair::startProgress': |
|
| 482 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 483 | - break; |
|
| 484 | - case '\OC\Repair::advance': |
|
| 485 | - $desc = $event->getArgument(1); |
|
| 486 | - if (empty($desc)) { |
|
| 487 | - $desc = ''; |
|
| 488 | - } |
|
| 489 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 490 | - |
|
| 491 | - break; |
|
| 492 | - case '\OC\Repair::finishProgress': |
|
| 493 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 494 | - break; |
|
| 495 | - case '\OC\Repair::step': |
|
| 496 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 497 | - break; |
|
| 498 | - case '\OC\Repair::info': |
|
| 499 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 500 | - break; |
|
| 501 | - case '\OC\Repair::warning': |
|
| 502 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 503 | - break; |
|
| 504 | - case '\OC\Repair::error': |
|
| 505 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 506 | - break; |
|
| 507 | - } |
|
| 508 | - }; |
|
| 509 | - |
|
| 510 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 511 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 512 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 513 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 514 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 515 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 516 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 520 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 521 | - }); |
|
| 522 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 523 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 524 | - }); |
|
| 525 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 526 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 527 | - }); |
|
| 528 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 529 | - if ($success) { |
|
| 530 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 531 | - } else { |
|
| 532 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 533 | - } |
|
| 534 | - }); |
|
| 535 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 536 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 537 | - }); |
|
| 538 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 539 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 540 | - }); |
|
| 541 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 542 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 543 | - }); |
|
| 544 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 545 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 546 | - }); |
|
| 547 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 548 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 549 | - }); |
|
| 550 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 551 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 552 | - }); |
|
| 553 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 554 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 555 | - }); |
|
| 556 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 557 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 558 | - }); |
|
| 559 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 560 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 561 | - }); |
|
| 562 | - $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 563 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 564 | - }); |
|
| 565 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 566 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 567 | - }); |
|
| 568 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 569 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 570 | - }); |
|
| 571 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 572 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 573 | - }); |
|
| 574 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 575 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 576 | - }); |
|
| 577 | - } |
|
| 62 | + /** @var ILogger $log */ |
|
| 63 | + private $log; |
|
| 64 | + |
|
| 65 | + /** @var IConfig */ |
|
| 66 | + private $config; |
|
| 67 | + |
|
| 68 | + /** @var Checker */ |
|
| 69 | + private $checker; |
|
| 70 | + |
|
| 71 | + /** @var Installer */ |
|
| 72 | + private $installer; |
|
| 73 | + |
|
| 74 | + private $logLevelNames = [ |
|
| 75 | + 0 => 'Debug', |
|
| 76 | + 1 => 'Info', |
|
| 77 | + 2 => 'Warning', |
|
| 78 | + 3 => 'Error', |
|
| 79 | + 4 => 'Fatal', |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param IConfig $config |
|
| 84 | + * @param Checker $checker |
|
| 85 | + * @param ILogger $log |
|
| 86 | + * @param Installer $installer |
|
| 87 | + */ |
|
| 88 | + public function __construct(IConfig $config, |
|
| 89 | + Checker $checker, |
|
| 90 | + ILogger $log = null, |
|
| 91 | + Installer $installer) { |
|
| 92 | + $this->log = $log; |
|
| 93 | + $this->config = $config; |
|
| 94 | + $this->checker = $checker; |
|
| 95 | + $this->installer = $installer; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 100 | + * except the main .htaccess file |
|
| 101 | + * |
|
| 102 | + * @return bool true if the operation succeeded, false otherwise |
|
| 103 | + */ |
|
| 104 | + public function upgrade() { |
|
| 105 | + $this->emitRepairEvents(); |
|
| 106 | + $this->logAllEvents(); |
|
| 107 | + |
|
| 108 | + $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
| 109 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 110 | + $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
| 111 | + |
|
| 112 | + $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
| 113 | + |
|
| 114 | + if (!$wasMaintenanceModeEnabled) { |
|
| 115 | + $this->config->setSystemValue('maintenance', true); |
|
| 116 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Clear CAN_INSTALL file if not on git |
|
| 120 | + if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 121 | + if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 122 | + $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 127 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 128 | + |
|
| 129 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 130 | + |
|
| 131 | + $success = true; |
|
| 132 | + try { |
|
| 133 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
| 134 | + } catch (HintException $exception) { |
|
| 135 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 136 | + $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 137 | + $success = false; |
|
| 138 | + } catch (\Exception $exception) { |
|
| 139 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 140 | + $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 141 | + $success = false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $this->emit('\OC\Updater', 'updateEnd', [$success]); |
|
| 145 | + |
|
| 146 | + if (!$wasMaintenanceModeEnabled && $success) { |
|
| 147 | + $this->config->setSystemValue('maintenance', false); |
|
| 148 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 149 | + } else { |
|
| 150 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 154 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
| 155 | + $this->config->setSystemValue('installed', true); |
|
| 156 | + |
|
| 157 | + return $success; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Return version from which this version is allowed to upgrade from |
|
| 162 | + * |
|
| 163 | + * @return array allowed previous versions per vendor |
|
| 164 | + */ |
|
| 165 | + private function getAllowedPreviousVersions() { |
|
| 166 | + // this should really be a JSON file |
|
| 167 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 168 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 169 | + return $OC_VersionCanBeUpgradedFrom; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Return vendor from which this version was published |
|
| 174 | + * |
|
| 175 | + * @return string Get the vendor |
|
| 176 | + */ |
|
| 177 | + private function getVendor() { |
|
| 178 | + // this should really be a JSON file |
|
| 179 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 180 | + /** @var string $vendor */ |
|
| 181 | + return (string) $vendor; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Whether an upgrade to a specified version is possible |
|
| 186 | + * @param string $oldVersion |
|
| 187 | + * @param string $newVersion |
|
| 188 | + * @param array $allowedPreviousVersions |
|
| 189 | + * @return bool |
|
| 190 | + */ |
|
| 191 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 192 | + $version = explode('.', $oldVersion); |
|
| 193 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
| 194 | + |
|
| 195 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 196 | + |
|
| 197 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 198 | + if ($currentVendor === '' && ( |
|
| 199 | + isset($allowedPreviousVersions['owncloud'][$oldVersion]) || |
|
| 200 | + isset($allowedPreviousVersions['owncloud'][$majorMinor]) |
|
| 201 | + )) { |
|
| 202 | + $currentVendor = 'owncloud'; |
|
| 203 | + $this->config->setAppValue('core', 'vendor', $currentVendor); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($currentVendor === 'nextcloud') { |
|
| 207 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 208 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 209 | + $this->config->getSystemValue('debug', false)); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Check if the instance can be migrated |
|
| 213 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 214 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 219 | + * except the main .htaccess file |
|
| 220 | + * |
|
| 221 | + * @param string $currentVersion current version to upgrade to |
|
| 222 | + * @param string $installedVersion previous version from which to upgrade from |
|
| 223 | + * |
|
| 224 | + * @throws \Exception |
|
| 225 | + */ |
|
| 226 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
| 227 | + // Stop update if the update is over several major versions |
|
| 228 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 229 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 230 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Update .htaccess files |
|
| 234 | + try { |
|
| 235 | + Setup::updateHtaccess(); |
|
| 236 | + Setup::protectDataDirectory(); |
|
| 237 | + } catch (\Exception $e) { |
|
| 238 | + throw new \Exception($e->getMessage()); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // create empty file in data dir, so we can later find |
|
| 242 | + // out that this is indeed an ownCloud data directory |
|
| 243 | + // (in case it didn't exist before) |
|
| 244 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 245 | + |
|
| 246 | + // pre-upgrade repairs |
|
| 247 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 248 | + $repair->run(); |
|
| 249 | + |
|
| 250 | + $this->doCoreUpgrade(); |
|
| 251 | + |
|
| 252 | + try { |
|
| 253 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 254 | + Setup::installBackgroundJobs(); |
|
| 255 | + } catch (\Exception $e) { |
|
| 256 | + throw new \Exception($e->getMessage()); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // update all shipped apps |
|
| 260 | + $this->checkAppsRequirements(); |
|
| 261 | + $this->doAppUpgrade(); |
|
| 262 | + |
|
| 263 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 264 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 265 | + |
|
| 266 | + // upgrade appstore apps |
|
| 267 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 268 | + $autoDisabledApps = \OC::$server->getAppManager()->getAutoDisabledApps(); |
|
| 269 | + $this->upgradeAppStoreApps($autoDisabledApps, true); |
|
| 270 | + |
|
| 271 | + // install new shipped apps on upgrade |
|
| 272 | + $errors = Installer::installShippedApps(true); |
|
| 273 | + foreach ($errors as $appId => $exception) { |
|
| 274 | + /** @var \Exception $exception */ |
|
| 275 | + $this->log->logException($exception, ['app' => $appId]); |
|
| 276 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // post-upgrade repairs |
|
| 280 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 281 | + $repair->run(); |
|
| 282 | + |
|
| 283 | + //Invalidate update feed |
|
| 284 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 285 | + |
|
| 286 | + // Check for code integrity if not disabled |
|
| 287 | + if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 288 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 289 | + $this->checker->runInstanceVerification(); |
|
| 290 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // only set the final version if everything went well |
|
| 294 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 295 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + protected function doCoreUpgrade() { |
|
| 299 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 300 | + |
|
| 301 | + // execute core migrations |
|
| 302 | + $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 303 | + $ms->migrate(); |
|
| 304 | + |
|
| 305 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 310 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 311 | + * |
|
| 312 | + * @throws NeedsUpdateException |
|
| 313 | + */ |
|
| 314 | + protected function doAppUpgrade() { |
|
| 315 | + $apps = \OC_App::getEnabledApps(); |
|
| 316 | + $priorityTypes = ['authentication', 'filesystem', 'logging']; |
|
| 317 | + $pseudoOtherType = 'other'; |
|
| 318 | + $stacks = [$pseudoOtherType => []]; |
|
| 319 | + |
|
| 320 | + foreach ($apps as $appId) { |
|
| 321 | + $priorityType = false; |
|
| 322 | + foreach ($priorityTypes as $type) { |
|
| 323 | + if (!isset($stacks[$type])) { |
|
| 324 | + $stacks[$type] = []; |
|
| 325 | + } |
|
| 326 | + if (\OC_App::isType($appId, [$type])) { |
|
| 327 | + $stacks[$type][] = $appId; |
|
| 328 | + $priorityType = true; |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + if (!$priorityType) { |
|
| 333 | + $stacks[$pseudoOtherType][] = $appId; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + foreach (array_merge($priorityTypes, [$pseudoOtherType]) as $type) { |
|
| 337 | + $stack = $stacks[$type]; |
|
| 338 | + foreach ($stack as $appId) { |
|
| 339 | + if (\OC_App::shouldUpgrade($appId)) { |
|
| 340 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 341 | + \OC_App::updateApp($appId); |
|
| 342 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 343 | + } |
|
| 344 | + if ($type !== $pseudoOtherType) { |
|
| 345 | + // load authentication, filesystem and logging apps after |
|
| 346 | + // upgrading them. Other apps my need to rely on modifying |
|
| 347 | + // user and/or filesystem aspects. |
|
| 348 | + \OC_App::loadApp($appId); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * check if the current enabled apps are compatible with the current |
|
| 356 | + * ownCloud version. disable them if not. |
|
| 357 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 358 | + * party apps installed. |
|
| 359 | + * |
|
| 360 | + * @return array |
|
| 361 | + * @throws \Exception |
|
| 362 | + */ |
|
| 363 | + private function checkAppsRequirements() { |
|
| 364 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 365 | + $apps = OC_App::getEnabledApps(); |
|
| 366 | + $version = implode('.', Util::getVersion()); |
|
| 367 | + $disabledApps = []; |
|
| 368 | + $appManager = \OC::$server->getAppManager(); |
|
| 369 | + foreach ($apps as $app) { |
|
| 370 | + // check if the app is compatible with this version of Nextcloud |
|
| 371 | + $info = OC_App::getAppInfo($app); |
|
| 372 | + if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
| 373 | + if ($appManager->isShipped($app)) { |
|
| 374 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 375 | + } |
|
| 376 | + \OC::$server->getAppManager()->disableApp($app, true); |
|
| 377 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
|
| 378 | + } |
|
| 379 | + // no need to disable any app in case this is a non-core upgrade |
|
| 380 | + if (!$isCoreUpgrade) { |
|
| 381 | + continue; |
|
| 382 | + } |
|
| 383 | + // shipped apps will remain enabled |
|
| 384 | + if ($appManager->isShipped($app)) { |
|
| 385 | + continue; |
|
| 386 | + } |
|
| 387 | + // authentication and session apps will remain enabled as well |
|
| 388 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 389 | + continue; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + return $disabledApps; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @return bool |
|
| 397 | + */ |
|
| 398 | + private function isCodeUpgrade() { |
|
| 399 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 400 | + $currentVersion = implode('.', Util::getVersion()); |
|
| 401 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 402 | + return true; |
|
| 403 | + } |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @param array $disabledApps |
|
| 409 | + * @param bool $reenable |
|
| 410 | + * @throws \Exception |
|
| 411 | + */ |
|
| 412 | + private function upgradeAppStoreApps(array $disabledApps, $reenable = false) { |
|
| 413 | + foreach ($disabledApps as $app) { |
|
| 414 | + try { |
|
| 415 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 416 | + if ($this->installer->isUpdateAvailable($app)) { |
|
| 417 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 418 | + $this->installer->updateAppstoreApp($app); |
|
| 419 | + } |
|
| 420 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 421 | + |
|
| 422 | + if ($reenable) { |
|
| 423 | + $ocApp = new \OC_App(); |
|
| 424 | + $ocApp->enable($app); |
|
| 425 | + } |
|
| 426 | + } catch (\Exception $ex) { |
|
| 427 | + $this->log->logException($ex, ['app' => 'core']); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Forward messages emitted by the repair routine |
|
| 434 | + */ |
|
| 435 | + private function emitRepairEvents() { |
|
| 436 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 437 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 438 | + if ($event instanceof GenericEvent) { |
|
| 439 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 440 | + } |
|
| 441 | + }); |
|
| 442 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 443 | + if ($event instanceof GenericEvent) { |
|
| 444 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 445 | + } |
|
| 446 | + }); |
|
| 447 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 448 | + if ($event instanceof GenericEvent) { |
|
| 449 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 450 | + } |
|
| 451 | + }); |
|
| 452 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 453 | + if ($event instanceof GenericEvent) { |
|
| 454 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 455 | + } |
|
| 456 | + }); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + private function logAllEvents() { |
|
| 460 | + $log = $this->log; |
|
| 461 | + |
|
| 462 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 463 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 464 | + if (!$event instanceof GenericEvent) { |
|
| 465 | + return; |
|
| 466 | + } |
|
| 467 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 468 | + }); |
|
| 469 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 470 | + if (!$event instanceof GenericEvent) { |
|
| 471 | + return; |
|
| 472 | + } |
|
| 473 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 474 | + }); |
|
| 475 | + |
|
| 476 | + $repairListener = function ($event) use ($log) { |
|
| 477 | + if (!$event instanceof GenericEvent) { |
|
| 478 | + return; |
|
| 479 | + } |
|
| 480 | + switch ($event->getSubject()) { |
|
| 481 | + case '\OC\Repair::startProgress': |
|
| 482 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 483 | + break; |
|
| 484 | + case '\OC\Repair::advance': |
|
| 485 | + $desc = $event->getArgument(1); |
|
| 486 | + if (empty($desc)) { |
|
| 487 | + $desc = ''; |
|
| 488 | + } |
|
| 489 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 490 | + |
|
| 491 | + break; |
|
| 492 | + case '\OC\Repair::finishProgress': |
|
| 493 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 494 | + break; |
|
| 495 | + case '\OC\Repair::step': |
|
| 496 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 497 | + break; |
|
| 498 | + case '\OC\Repair::info': |
|
| 499 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 500 | + break; |
|
| 501 | + case '\OC\Repair::warning': |
|
| 502 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 503 | + break; |
|
| 504 | + case '\OC\Repair::error': |
|
| 505 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 506 | + break; |
|
| 507 | + } |
|
| 508 | + }; |
|
| 509 | + |
|
| 510 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 511 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 512 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 513 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 514 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 515 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 516 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 520 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 521 | + }); |
|
| 522 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 523 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 524 | + }); |
|
| 525 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 526 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 527 | + }); |
|
| 528 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 529 | + if ($success) { |
|
| 530 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 531 | + } else { |
|
| 532 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 533 | + } |
|
| 534 | + }); |
|
| 535 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 536 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 537 | + }); |
|
| 538 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 539 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 540 | + }); |
|
| 541 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 542 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 543 | + }); |
|
| 544 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 545 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 546 | + }); |
|
| 547 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 548 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 549 | + }); |
|
| 550 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 551 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 552 | + }); |
|
| 553 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 554 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 555 | + }); |
|
| 556 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 557 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 558 | + }); |
|
| 559 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 560 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 561 | + }); |
|
| 562 | + $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 563 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 564 | + }); |
|
| 565 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 566 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 567 | + }); |
|
| 568 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 569 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 570 | + }); |
|
| 571 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 572 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 573 | + }); |
|
| 574 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 575 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 576 | + }); |
|
| 577 | + } |
|
| 578 | 578 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $this->logAllEvents(); |
| 107 | 107 | |
| 108 | 108 | $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
| 109 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 109 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 110 | 110 | $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
| 111 | 111 | |
| 112 | 112 | $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | // Clear CAN_INSTALL file if not on git |
| 120 | 120 | if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
| 121 | - if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 121 | + if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 122 | 122 | $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -126,18 +126,18 @@ discard block |
||
| 126 | 126 | $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
| 127 | 127 | $currentVersion = implode('.', \OCP\Util::getVersion()); |
| 128 | 128 | |
| 129 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 129 | + $this->log->debug('starting upgrade from '.$installedVersion.' to '.$currentVersion, ['app' => 'core']); |
|
| 130 | 130 | |
| 131 | 131 | $success = true; |
| 132 | 132 | try { |
| 133 | 133 | $this->doUpgrade($currentVersion, $installedVersion); |
| 134 | 134 | } catch (HintException $exception) { |
| 135 | 135 | $this->log->logException($exception, ['app' => 'core']); |
| 136 | - $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 136 | + $this->emit('\OC\Updater', 'failure', [$exception->getMessage().': '.$exception->getHint()]); |
|
| 137 | 137 | $success = false; |
| 138 | 138 | } catch (\Exception $exception) { |
| 139 | 139 | $this->log->logException($exception, ['app' => 'core']); |
| 140 | - $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 140 | + $this->emit('\OC\Updater', 'failure', [get_class($exception).': '.$exception->getMessage()]); |
|
| 141 | 141 | $success = false; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $this->emit('\OC\Updater', 'maintenanceActive'); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 153 | + $this->emit('\OC\Updater', 'resetLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 154 | 154 | $this->config->setSystemValue('loglevel', $logLevel); |
| 155 | 155 | $this->config->setSystemValue('installed', true); |
| 156 | 156 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | private function getAllowedPreviousVersions() { |
| 166 | 166 | // this should really be a JSON file |
| 167 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 167 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 168 | 168 | /** @var array $OC_VersionCanBeUpgradedFrom */ |
| 169 | 169 | return $OC_VersionCanBeUpgradedFrom; |
| 170 | 170 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | private function getVendor() { |
| 178 | 178 | // this should really be a JSON file |
| 179 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 179 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 180 | 180 | /** @var string $vendor */ |
| 181 | 181 | return (string) $vendor; |
| 182 | 182 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
| 192 | 192 | $version = explode('.', $oldVersion); |
| 193 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 193 | + $majorMinor = $version[0].'.'.$version[1]; |
|
| 194 | 194 | |
| 195 | 195 | $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
| 196 | 196 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | // create empty file in data dir, so we can later find |
| 242 | 242 | // out that this is indeed an ownCloud data directory |
| 243 | 243 | // (in case it didn't exist before) |
| 244 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 244 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); |
|
| 245 | 245 | |
| 246 | 246 | // pre-upgrade repairs |
| 247 | 247 | $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | foreach ($errors as $appId => $exception) { |
| 274 | 274 | /** @var \Exception $exception */ |
| 275 | 275 | $this->log->logException($exception, ['app' => $appId]); |
| 276 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 276 | + $this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | // post-upgrade repairs |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $info = OC_App::getAppInfo($app); |
| 372 | 372 | if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
| 373 | 373 | if ($appManager->isShipped($app)) { |
| 374 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 374 | + throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update'); |
|
| 375 | 375 | } |
| 376 | 376 | \OC::$server->getAppManager()->disableApp($app, true); |
| 377 | 377 | $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
@@ -434,22 +434,22 @@ discard block |
||
| 434 | 434 | */ |
| 435 | 435 | private function emitRepairEvents() { |
| 436 | 436 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 437 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 437 | + $dispatcher->addListener('\OC\Repair::warning', function($event) { |
|
| 438 | 438 | if ($event instanceof GenericEvent) { |
| 439 | 439 | $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
| 440 | 440 | } |
| 441 | 441 | }); |
| 442 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 442 | + $dispatcher->addListener('\OC\Repair::error', function($event) { |
|
| 443 | 443 | if ($event instanceof GenericEvent) { |
| 444 | 444 | $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
| 445 | 445 | } |
| 446 | 446 | }); |
| 447 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 447 | + $dispatcher->addListener('\OC\Repair::info', function($event) { |
|
| 448 | 448 | if ($event instanceof GenericEvent) { |
| 449 | 449 | $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
| 450 | 450 | } |
| 451 | 451 | }); |
| 452 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 452 | + $dispatcher->addListener('\OC\Repair::step', function($event) { |
|
| 453 | 453 | if ($event instanceof GenericEvent) { |
| 454 | 454 | $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
| 455 | 455 | } |
@@ -460,49 +460,49 @@ discard block |
||
| 460 | 460 | $log = $this->log; |
| 461 | 461 | |
| 462 | 462 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 463 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 463 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 464 | 464 | if (!$event instanceof GenericEvent) { |
| 465 | 465 | return; |
| 466 | 466 | } |
| 467 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 467 | + $log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 468 | 468 | }); |
| 469 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 469 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 470 | 470 | if (!$event instanceof GenericEvent) { |
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 473 | + $log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 474 | 474 | }); |
| 475 | 475 | |
| 476 | - $repairListener = function ($event) use ($log) { |
|
| 476 | + $repairListener = function($event) use ($log) { |
|
| 477 | 477 | if (!$event instanceof GenericEvent) { |
| 478 | 478 | return; |
| 479 | 479 | } |
| 480 | 480 | switch ($event->getSubject()) { |
| 481 | 481 | case '\OC\Repair::startProgress': |
| 482 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 482 | + $log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 483 | 483 | break; |
| 484 | 484 | case '\OC\Repair::advance': |
| 485 | 485 | $desc = $event->getArgument(1); |
| 486 | 486 | if (empty($desc)) { |
| 487 | 487 | $desc = ''; |
| 488 | 488 | } |
| 489 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 489 | + $log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 490 | 490 | |
| 491 | 491 | break; |
| 492 | 492 | case '\OC\Repair::finishProgress': |
| 493 | 493 | $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
| 494 | 494 | break; |
| 495 | 495 | case '\OC\Repair::step': |
| 496 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 496 | + $log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 497 | 497 | break; |
| 498 | 498 | case '\OC\Repair::info': |
| 499 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 499 | + $log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 500 | 500 | break; |
| 501 | 501 | case '\OC\Repair::warning': |
| 502 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 502 | + $log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 503 | 503 | break; |
| 504 | 504 | case '\OC\Repair::error': |
| 505 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 505 | + $log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 506 | 506 | break; |
| 507 | 507 | } |
| 508 | 508 | }; |
@@ -516,62 +516,62 @@ discard block |
||
| 516 | 516 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
| 517 | 517 | |
| 518 | 518 | |
| 519 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 519 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function() use ($log) { |
|
| 520 | 520 | $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
| 521 | 521 | }); |
| 522 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 522 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function() use ($log) { |
|
| 523 | 523 | $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
| 524 | 524 | }); |
| 525 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 525 | + $this->listen('\OC\Updater', 'maintenanceActive', function() use ($log) { |
|
| 526 | 526 | $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
| 527 | 527 | }); |
| 528 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 528 | + $this->listen('\OC\Updater', 'updateEnd', function($success) use ($log) { |
|
| 529 | 529 | if ($success) { |
| 530 | 530 | $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
| 531 | 531 | } else { |
| 532 | 532 | $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
| 533 | 533 | } |
| 534 | 534 | }); |
| 535 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 535 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($log) { |
|
| 536 | 536 | $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
| 537 | 537 | }); |
| 538 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 538 | + $this->listen('\OC\Updater', 'dbUpgrade', function() use ($log) { |
|
| 539 | 539 | $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
| 540 | 540 | }); |
| 541 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 542 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 541 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use ($log) { |
|
| 542 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']); |
|
| 543 | 543 | }); |
| 544 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 545 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 544 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($log) { |
|
| 545 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 546 | 546 | }); |
| 547 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 548 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 547 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($log) { |
|
| 548 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']); |
|
| 549 | 549 | }); |
| 550 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 551 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 550 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($log) { |
|
| 551 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 552 | 552 | }); |
| 553 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 554 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 553 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) { |
|
| 554 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <'.$app.'> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 555 | 555 | }); |
| 556 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 557 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 556 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) { |
|
| 557 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']); |
|
| 558 | 558 | }); |
| 559 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 560 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 559 | + $this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) { |
|
| 560 | + $log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']); |
|
| 561 | 561 | }); |
| 562 | - $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 563 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 562 | + $this->listen('\OC\Updater', 'failure', function($message) use ($log) { |
|
| 563 | + $log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']); |
|
| 564 | 564 | }); |
| 565 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 565 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function() use ($log) { |
|
| 566 | 566 | $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
| 567 | 567 | }); |
| 568 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 569 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 568 | + $this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($log) { |
|
| 569 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']); |
|
| 570 | 570 | }); |
| 571 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 571 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($log) { |
|
| 572 | 572 | $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
| 573 | 573 | }); |
| 574 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 574 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($log) { |
|
| 575 | 575 | $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
| 576 | 576 | }); |
| 577 | 577 | } |