protected function execute(InputInterface $input, OutputInterface $output) { $includeExpensive = $input->getOption('include-expensive'); if ($includeExpensive) { foreach ($this->repair->getExpensiveRepairSteps() as $step) { $this->repair->addStep($step); } } $maintenanceMode = $this->config->getSystemValue('maintenance', false); $this->config->setSystemValue('maintenance', true); $this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'info', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'warning', function ($description) use($output) { $output->writeln(' - WARNING: ' . $description); }); $this->repair->listen('\\OC\\Repair', 'error', function ($description) use($output) { $output->writeln(' - ERROR: ' . $description); }); $this->repair->run(); $this->config->setSystemValue('maintenance', $maintenanceMode); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->run(); }
public function testRunRepairStepsContinueAfterWarning() { $this->repair->addStep(new TestRepairStep(true)); $this->repair->addStep(new TestRepairStep(false)); $this->repair->run(); $this->assertEquals(array('step: Test Name', 'warning: Simulated warning', 'step: Test Name', 'info: Simulated info'), $this->outputArray); }
protected function execute(InputInterface $input, OutputInterface $output) { $maintenanceMode = $this->config->getSystemValue('maintenance', false); $this->config->setSystemValue('maintenance', true); $this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'info', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'error', function ($description) use($output) { $output->writeln(' - ERROR: ' . $description); }); $this->repair->run(); $this->config->setSystemValue('maintenance', $maintenanceMode); }
protected function execute(InputInterface $input, OutputInterface $output) { // TODO: inject DB connection/factory when possible $connection = \OC_DB::getConnection(); $connection->disableQueryStatementCaching(); $maintenanceMode = $this->config->getValue('maintenance', false); $this->config->setValue('maintenance', true); $this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'info', function ($description) use($output) { $output->writeln(' - ' . $description); }); $this->repair->listen('\\OC\\Repair', 'error', function ($description) use($output) { $output->writeln(' - ERROR: ' . $description); }); $this->repair->run(); $this->config->setValue('maintenance', $maintenanceMode); }
protected function execute(InputInterface $input, OutputInterface $output) { $includeExpensive = $input->getOption('include-expensive'); if ($includeExpensive) { foreach ($this->repair->getExpensiveRepairSteps() as $step) { $this->repair->addStep($step); } } $apps = \OC::$server->getAppManager()->getInstalledApps(); foreach ($apps as $app) { if (!\OC_App::isEnabled($app)) { continue; } $info = \OC_App::getAppInfo($app); if (!is_array($info)) { continue; } $steps = $info['repair-steps']['post-migration']; foreach ($steps as $step) { try { $this->repair->addStep($step); } catch (Exception $ex) { $output->writeln("<error>Failed to load repair step for {$app}: {$ex->getMessage()}</error>"); } } } $maintenanceMode = $this->config->getSystemValue('maintenance', false); $this->config->setSystemValue('maintenance', true); $this->progress = new ProgressBar($output); $this->output = $output; $this->dispatcher->addListener('\\OC\\Repair::startProgress', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::advance', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::finishProgress', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::step', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::info', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::warning', [$this, 'handleRepairFeedBack']); $this->dispatcher->addListener('\\OC\\Repair::error', [$this, 'handleRepairFeedBack']); $this->repair->run(); $this->config->setSystemValue('maintenance', $maintenanceMode); }
/** * runs the update actions in maintenance mode, does not upgrade the source files * except the main .htaccess file * * @param string $currentVersion current version to upgrade to * @param string $installedVersion previous version from which to upgrade from * * @throws \Exception */ private function doUpgrade($currentVersion, $installedVersion) { // Stop update if the update is over several major versions $allowedPreviousVersion = $this->getAllowedPreviousVersion(); if (!self::isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersion)) { throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); } // Update .htaccess files try { Setup::updateHtaccess(); Setup::protectDataDirectory(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory // (in case it didn't exist before) file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); // pre-upgrade repairs $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); $repair->run(); // simulate DB upgrade if ($this->simulateStepEnabled) { $this->checkCoreUpgrade(); // simulate apps DB upgrade $this->checkAppUpgrade($currentVersion); } if ($this->updateStepEnabled) { $this->doCoreUpgrade(); // update all shipped apps $disabledApps = $this->checkAppsRequirements(); $this->doAppUpgrade(); // upgrade appstore apps $this->upgradeAppStoreApps($disabledApps); // install new shipped apps on upgrade OC_App::loadApps('authentication'); $errors = Installer::installShippedApps(true); foreach ($errors as $appId => $exception) { /** @var \Exception $exception */ $this->log->logException($exception, ['app' => $appId]); $this->emit('\\OC\\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); } // post-upgrade repairs $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); $repair->run(); //Invalidate update feed $this->config->setAppValue('core', 'lastupdatedat', 0); // Check for code integrity if not disabled if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { $this->emit('\\OC\\Updater', 'startCheckCodeIntegrity'); $this->checker->runInstanceVerification(); $this->emit('\\OC\\Updater', 'finishedCheckCodeIntegrity'); } // only set the final version if everything went well $this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion())); } }
/** * @param string $appId * @param string[] $steps * @throws \OC\NeedsUpdateException */ public static function executeRepairSteps($appId, array $steps) { if (empty($steps)) { return; } // load the app self::loadApp($appId, false); $dispatcher = OC::$server->getEventDispatcher(); // load the steps $r = new Repair([], $dispatcher); foreach ($steps as $step) { try { $r->addStep($step); } catch (Exception $ex) { $r->emit('\\OC\\Repair', 'error', [$ex->getMessage()]); \OC::$server->getLogger()->logException($ex); } } // run the steps $r->run(); }
/** * @param array $argument * @throws \Exception * @throws \OC\NeedsUpdateException */ protected function run($argument) { if (!isset($argument['app']) || !isset($argument['step'])) { // remove the job - we can never execute it $this->jobList->remove($this, $this->argument); return; } $app = $argument['app']; try { $this->loadApp($app); } catch (NeedsUpdateException $ex) { // as long as the app is not yet done with it's offline migration // we better not start with the live migration return; } $step = $argument['step']; $repair = new Repair([], $this->dispatcher); try { $repair->addStep($step); } catch (\Exception $ex) { $this->logger->logException($ex, ['app' => 'migration']); // remove the job - we can never execute it $this->jobList->remove($this, $this->argument); return; } // execute the repair step $repair->run(); // remove the job once executed successfully $this->jobList->remove($this, $this->argument); }
/** * runs the update actions in maintenance mode, does not upgrade the source files */ public function upgrade() { \OC_DB::enableCaching(false); \OC_Config::setValue('maintenance', true); $installedVersion = \OC_Config::getValue('version', '0.0.0'); $currentVersion = implode('.', \OC_Util::getVersion()); if ($this->log) { $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); } $this->emit('\\OC\\Updater', 'maintenanceStart'); // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory // (in case it didn't exist before) file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); /* * START CONFIG CHANGES FOR OLDER VERSIONS */ if (!\OC::$CLI && version_compare($installedVersion, '6.00.4', '<')) { // Add the trusted_domains config if it is not existant // This is added to prevent host header poisoning \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost()))); } /* * STOP CONFIG CHANGES FOR OLDER VERSIONS */ try { \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); $this->emit('\\OC\\Updater', 'dbUpgrade'); // do a file cache upgrade for users with files // this can take loooooooooooooooooooooooong $this->upgradeFileCache(); } catch (\Exception $exception) { $this->emit('\\OC\\Updater', 'failure', array($exception->getMessage())); } \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); \OC_App::checkAppsRequirements(); // load all apps to also upgrade enabled apps \OC_App::loadApps(); $repair = new Repair(); $repair->run(); //Invalidate update feed \OC_Appconfig::setValue('core', 'lastupdatedat', 0); \OC_Config::setValue('maintenance', false); $this->emit('\\OC\\Updater', 'maintenanceEnd'); }
/** * runs the update actions in maintenance mode, does not upgrade the source files * except the main .htaccess file * * @param string $currentVersion current version to upgrade to * @param string $installedVersion previous version from which to upgrade from * * @throws \Exception * @return bool true if the operation succeeded, false otherwise */ private function doUpgrade($currentVersion, $installedVersion) { // Stop update if the update is over several major versions if (!self::isUpgradePossible($installedVersion, $currentVersion)) { throw new \Exception('Updates between multiple major versions are unsupported.'); } // Update htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { try { \OC_Setup::updateHtaccess(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory // (in case it didn't exist before) file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); // pre-upgrade repairs $repair = new Repair(Repair::getBeforeUpgradeRepairSteps()); $repair->run(); // simulate DB upgrade if ($this->simulateStepEnabled) { $this->checkCoreUpgrade(); // simulate apps DB upgrade $this->checkAppUpgrade($currentVersion); } if ($this->updateStepEnabled) { $this->doCoreUpgrade(); $this->checkAppsRequirements(); $this->doAppUpgrade(); // post-upgrade repairs $repair = new Repair(Repair::getRepairSteps()); $repair->run(); //Invalidate update feed $this->config->setAppValue('core', 'lastupdatedat', 0); // only set the final version if everything went well $this->config->setSystemValue('version', implode('.', \OC_Util::getVersion())); } }
/** * runs the update actions in maintenance mode, does not upgrade the source files */ public function upgrade() { \OC_DB::enableCaching(false); \OC_Config::setValue('maintenance', true); $installedVersion = \OC_Config::getValue('version', '0.0.0'); $currentVersion = implode('.', \OC_Util::getVersion()); if ($this->log) { $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); } $this->emit('\\OC\\Updater', 'maintenanceStart'); try { \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); $this->emit('\\OC\\Updater', 'dbUpgrade'); // do a file cache upgrade for users with files // this can take loooooooooooooooooooooooong $this->upgradeFileCache(); } catch (\Exception $exception) { $this->emit('\\OC\\Updater', 'failure', array($exception->getMessage())); } \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); \OC_App::checkAppsRequirements(); // load all apps to also upgrade enabled apps \OC_App::loadApps(); $repair = new Repair(); $repair->run(); \OC_Config::setValue('maintenance', false); $this->emit('\\OC\\Updater', 'maintenanceEnd'); }