diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-09-28 16:29:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-28 16:29:09 +0200 |
commit | 19f94ac5f9d08b958602ab07848a5c22d183b027 (patch) | |
tree | 7004a4a9da3b88d66f94b5252af58316c61b91d0 | |
parent | 32640c9a5b1a2b6f09511b42b71a8320d28279ce (diff) | |
parent | 3b7f548b0f17e757810de97b2d098835fccd791b (diff) | |
download | nextcloud-server-19f94ac5f9d08b958602ab07848a5c22d183b027.tar.gz nextcloud-server-19f94ac5f9d08b958602ab07848a5c22d183b027.zip |
Merge pull request #1549 from nextcloud/kill-update-simulation
Kill update simulation
-rw-r--r-- | core/Command/Upgrade.php | 31 | ||||
-rw-r--r-- | lib/private/DB/MDB2SchemaManager.php | 11 | ||||
-rw-r--r-- | lib/private/Updater.php | 123 | ||||
-rw-r--r-- | lib/private/legacy/db.php | 17 | ||||
-rw-r--r-- | tests/lib/UpdaterTest.php | 28 |
5 files changed, 47 insertions, 163 deletions
diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 69354272de8..d9f26d5ac8d 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -72,12 +72,6 @@ class Upgrade extends Command { ->setName('upgrade') ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.') ->addOption( - '--skip-migration-test', - null, - InputOption::VALUE_NONE, - 'skips the database schema migration simulation and update directly' - ) - ->addOption( '--dry-run', null, InputOption::VALUE_NONE, @@ -99,28 +93,12 @@ class Upgrade extends Command { */ protected function execute(InputInterface $input, OutputInterface $output) { - $simulateStepEnabled = true; - $updateStepEnabled = true; $skip3rdPartyAppsDisable = false; - if ($input->getOption('skip-migration-test')) { - $simulateStepEnabled = false; - } - if ($input->getOption('dry-run')) { - $updateStepEnabled = false; - } if ($input->getOption('no-app-disable')) { $skip3rdPartyAppsDisable = true; } - if (!$simulateStepEnabled && !$updateStepEnabled) { - $output->writeln( - '<error>Only one of "--skip-migration-test" or "--dry-run" ' . - 'can be specified at a time.</error>' - ); - return self::ERROR_INVALID_ARGUMENTS; - } - if(\OC::checkUpgrade(false)) { if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { // Prepend each line with a little timestamp @@ -135,8 +113,6 @@ class Upgrade extends Command { $this->logger ); - $updater->setSimulateStepEnabled($simulateStepEnabled); - $updater->setUpdateStepEnabled($updateStepEnabled); $updater->setSkip3rdPartyAppsDisable($skip3rdPartyAppsDisable); $dispatcher = \OC::$server->getEventDispatcher(); $progress = new ProgressBar($output); @@ -228,12 +204,11 @@ class Upgrade extends Command { $output->writeln('<info>Maintenance mode is kept active</info>'); }); $updater->listen('\OC\Updater', 'updateEnd', - function ($success) use($output, $updateStepEnabled, $self) { - $mode = $updateStepEnabled ? 'Update' : 'Update simulation'; + function ($success) use($output, $self) { if ($success) { - $message = "<info>$mode successful</info>"; + $message = "<info>Update successful</info>"; } else { - $message = "<error>$mode failed</error>"; + $message = "<error>Update failed</error>"; } $output->writeln($message); }); diff --git a/lib/private/DB/MDB2SchemaManager.php b/lib/private/DB/MDB2SchemaManager.php index 494c8fd53f1..f209991eb84 100644 --- a/lib/private/DB/MDB2SchemaManager.php +++ b/lib/private/DB/MDB2SchemaManager.php @@ -122,17 +122,6 @@ class MDB2SchemaManager { } /** - * update the database scheme - * @param string $file file to read structure from - * @return boolean - */ - public function simulateUpdateDbFromStructure($file) { - $toSchema = $this->readSchemaFromFile($file); - $this->getMigrator()->checkMigrate($toSchema); - return true; - } - - /** * @param \Doctrine\DBAL\Schema\Schema $schema * @return string */ diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 609e965bfad..646fc031a83 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -35,8 +35,8 @@ use OC\Hooks\BasicEmitter; use OC\IntegrityCheck\Checker; use OC_App; use OCP\IConfig; -use OC\Setup; use OCP\ILogger; +use OCP\Util; use Symfony\Component\EventDispatcher\GenericEvent; /** @@ -60,12 +60,6 @@ class Updater extends BasicEmitter { private $checker; /** @var bool */ - private $simulateStepEnabled; - - /** @var bool */ - private $updateStepEnabled; - - /** @var bool */ private $skip3rdPartyAppsDisable; private $logLevelNames = [ @@ -87,29 +81,6 @@ class Updater extends BasicEmitter { $this->log = $log; $this->config = $config; $this->checker = $checker; - $this->simulateStepEnabled = true; - $this->updateStepEnabled = true; - } - - /** - * Sets whether the database migration simulation must - * be enabled. - * This can be set to false to skip this test. - * - * @param bool $flag true to enable simulation, false otherwise - */ - public function setSimulateStepEnabled($flag) { - $this->simulateStepEnabled = $flag; - } - - /** - * Sets whether the update must be performed. - * This can be set to false to skip the actual update. - * - * @param bool $flag true to enable update, false otherwise - */ - public function setUpdateStepEnabled($flag) { - $this->updateStepEnabled = $flag; } /** @@ -131,9 +102,9 @@ class Updater extends BasicEmitter { public function upgrade() { $this->emitRepairEvents(); - $logLevel = $this->config->getSystemValue('loglevel', \OCP\Util::WARN); + $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); - $this->config->setSystemValue('loglevel', \OCP\Util::DEBUG); + $this->config->setSystemValue('loglevel', Util::DEBUG); $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); @@ -254,68 +225,48 @@ class Updater extends BasicEmitter { $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); + $this->doCoreUpgrade(); + try { + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 + Setup::installBackgroundJobs(); + } catch (\Exception $e) { + throw new \Exception($e->getMessage()); } - if ($this->updateStepEnabled) { - $this->doCoreUpgrade(); - - try { - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 - Setup::installBackgroundJobs(); - } catch (\Exception $e) { - throw new \Exception($e->getMessage()); - } - - // update all shipped apps - $disabledApps = $this->checkAppsRequirements(); - $this->doAppUpgrade(); + // 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()]); - } + // upgrade appstore apps + $this->upgradeAppStoreApps($disabledApps); - // post-upgrade repairs - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); - $repair->run(); + // 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()]); + } - //Invalidate update feed - $this->config->setAppValue('core', 'lastupdatedat', 0); + // post-upgrade repairs + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); + $repair->run(); - // 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'); - } + //Invalidate update feed + $this->config->setAppValue('core', 'lastupdatedat', 0); - // only set the final version if everything went well - $this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion())); - $this->config->setAppValue('core', 'vendor', $this->getVendor()); + // 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'); } - } - protected function checkCoreUpgrade() { - $this->emit('\OC\Updater', 'dbSimulateUpgradeBefore'); - - // simulate core DB upgrade - \OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); - - $this->emit('\OC\Updater', 'dbSimulateUpgrade'); + // only set the final version if everything went well + $this->config->setSystemValue('version', implode('.', Util::getVersion())); + $this->config->setAppValue('core', 'vendor', $this->getVendor()); } protected function doCoreUpgrade() { @@ -424,7 +375,7 @@ class Updater extends BasicEmitter { private function checkAppsRequirements() { $isCoreUpgrade = $this->isCodeUpgrade(); $apps = OC_App::getEnabledApps(); - $version = \OCP\Util::getVersion(); + $version = Util::getVersion(); $disabledApps = []; foreach ($apps as $app) { // check if the app is compatible with this version of ownCloud @@ -461,7 +412,7 @@ class Updater extends BasicEmitter { */ private function isCodeUpgrade() { $installedVersion = $this->config->getSystemValue('version', '0.0.0'); - $currentVersion = implode('.', \OCP\Util::getVersion()); + $currentVersion = implode('.', Util::getVersion()); if (version_compare($currentVersion, $installedVersion, '>')) { return true; } diff --git a/lib/private/legacy/db.php b/lib/private/legacy/db.php index 2d48e830ec2..415701d4024 100644 --- a/lib/private/legacy/db.php +++ b/lib/private/legacy/db.php @@ -192,23 +192,6 @@ class OC_DB { } /** - * simulate the database schema update - * @param string $file file to read structure from - * @throws Exception - * @return string|boolean - */ - public static function simulateUpdateDbFromStructure($file) { - $schemaManager = self::getMDB2SchemaManager(); - try { - $result = $schemaManager->simulateUpdateDbFromStructure($file); - } catch (Exception $e) { - \OCP\Util::writeLog('core', 'Simulated database structure update failed ('.$e.')', \OCP\Util::FATAL); - throw $e; - } - return $result; - } - - /** * remove all tables defined in a database structure xml file * @param string $file the xml file describing the tables */ diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index 0c67a3f7433..80c7c28cd68 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -27,25 +27,25 @@ use OCP\IConfig; use OCP\ILogger; use OC\IntegrityCheck\Checker; -class UpdaterTest extends \Test\TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ +class UpdaterTest extends TestCase { + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var ILogger */ + /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */ private $logger; /** @var Updater */ private $updater; - /** @var Checker */ + /** @var Checker | \PHPUnit_Framework_MockObject_MockObject */ private $checker; public function setUp() { parent::setUp(); - $this->config = $this->getMockBuilder('\\OCP\\IConfig') + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->logger = $this->getMockBuilder('\\OCP\\ILogger') + $this->logger = $this->getMockBuilder(ILogger::class) ->disableOriginalConstructor() ->getMock(); - $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') + $this->checker = $this->getMockBuilder(Checker::class) ->disableOriginalConstructor() ->getMock(); @@ -169,20 +169,6 @@ class UpdaterTest extends \Test\TestCase { $this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion)); } - public function testSetSimulateStepEnabled() { - $this->updater->setSimulateStepEnabled(true); - $this->assertSame(true, $this->invokePrivate($this->updater, 'simulateStepEnabled')); - $this->updater->setSimulateStepEnabled(false); - $this->assertSame(false, $this->invokePrivate($this->updater, 'simulateStepEnabled')); - } - - public function testSetUpdateStepEnabled() { - $this->updater->setUpdateStepEnabled(true); - $this->assertSame(true, $this->invokePrivate($this->updater, 'updateStepEnabled')); - $this->updater->setUpdateStepEnabled(false); - $this->assertSame(false, $this->invokePrivate($this->updater, 'updateStepEnabled')); - } - public function testSetSkip3rdPartyAppsDisable() { $this->updater->setSkip3rdPartyAppsDisable(true); $this->assertSame(true, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable')); |