Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions core/Command/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ protected function configure() {
$this
->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,
Expand All @@ -99,28 +93,12 @@ protected function configure() {
*/
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
Expand All @@ -135,8 +113,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->logger
);

$updater->setSimulateStepEnabled($simulateStepEnabled);
$updater->setUpdateStepEnabled($updateStepEnabled);
$updater->setSkip3rdPartyAppsDisable($skip3rdPartyAppsDisable);
$dispatcher = \OC::$server->getEventDispatcher();
$progress = new ProgressBar($output);
Expand Down Expand Up @@ -228,12 +204,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$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);
});
Expand Down
11 changes: 0 additions & 11 deletions lib/private/DB/MDB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public function updateDbFromStructure($file, $generateSql = false) {
}
}

/**
* 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
Expand Down
123 changes: 37 additions & 86 deletions lib/private/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
use OC\IntegrityCheck\Checker;
use OC_App;
use OCP\IConfig;
use OC\Setup;
use OCP\ILogger;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
Expand All @@ -59,12 +59,6 @@ class Updater extends BasicEmitter {
/** @var Checker */
private $checker;

/** @var bool */
private $simulateStepEnabled;

/** @var bool */
private $updateStepEnabled;

/** @var bool */
private $skip3rdPartyAppsDisable;

Expand All @@ -87,29 +81,6 @@ public function __construct(IConfig $config,
$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;
}

/**
Expand All @@ -131,9 +102,9 @@ public function setSkip3rdPartyAppsDisable($flag) {
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);

Expand Down Expand Up @@ -254,68 +225,48 @@ private function doUpgrade($currentVersion, $installedVersion) {
$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() {
Expand Down Expand Up @@ -424,7 +375,7 @@ protected function doAppUpgrade() {
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
Expand Down Expand Up @@ -461,7 +412,7 @@ private function checkAppsRequirements() {
*/
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;
}
Expand Down
17 changes: 0 additions & 17 deletions lib/private/legacy/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,6 @@ public static function updateDbFromStructure($file) {
return $result;
}

/**
* 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
Expand Down
28 changes: 7 additions & 21 deletions tests/lib/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
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();

Expand Down Expand Up @@ -169,20 +169,6 @@ public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersion,
$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'));
Expand Down