Added CLI arguments for upgrade simulation steps

Added "dry run" argument to only run the update simulation.
Added argument to disable migration (useful for bigger setups where
table duplication would take too much space)
This commit is contained in:
Vincent Petry 2014-06-05 16:19:24 +02:00
parent ff651a3e0d
commit 5e27ac3e0d
2 changed files with 93 additions and 20 deletions

View File

@ -12,6 +12,7 @@ use OC\Updater;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class Upgrade extends Command { class Upgrade extends Command {
@ -19,12 +20,24 @@ class Upgrade extends Command {
const ERROR_NOT_INSTALLED = 1; const ERROR_NOT_INSTALLED = 1;
const ERROR_MAINTENANCE_MODE = 2; const ERROR_MAINTENANCE_MODE = 2;
const ERROR_UP_TO_DATE = 3; const ERROR_UP_TO_DATE = 3;
const ERROR_INVALID_ARGUMENTS = 4;
protected function configure() { protected function configure() {
$this $this
->setName('upgrade') ->setName('upgrade')
->setDescription('run upgrade routines') ->setDescription('run upgrade routines')
; ->addOption(
'--skip-migration-test',
null,
InputOption::VALUE_NONE,
'skips the database schema migration simulation and update directly'
)
->addOption(
'--dry-run',
null,
InputOption::VALUE_NONE,
'only runs the database schema migration simulation, do not actually update'
);
} }
/** /**
@ -43,15 +56,41 @@ class Upgrade extends Command {
return self::ERROR_NOT_INSTALLED; return self::ERROR_NOT_INSTALLED;
} }
$simulateStepEnabled = true;
$updateStepEnabled = true;
if ($input->getOption('skip-migration-test')) {
$simulateStepEnabled = false;
}
if ($input->getOption('dry-run')) {
$updateStepEnabled = false;
}
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(\OC::checkUpgrade(false)) {
$updater = new Updater(); $updater = new Updater();
$updater->setSimulateStepEnabled($simulateStepEnabled);
$updater->setUpdateStepEnabled($updateStepEnabled);
$updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) { $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
$output->writeln('<info>Turned on maintenance mode</info>'); $output->writeln('<info>Turned on maintenance mode</info>');
}); });
$updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) { $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output, $updateStepEnabled) {
$output->writeln('<info>Turned off maintenance mode</info>'); $output->writeln('<info>Turned off maintenance mode</info>');
if (!$updateStepEnabled) {
$output->writeln('<info>Update simulation successful</info>');
}
else {
$output->writeln('<info>Update successful</info>'); $output->writeln('<info>Update successful</info>');
}
}); });
$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
$output->writeln('<info>Updated database</info>'); $output->writeln('<info>Updated database</info>');

View File

@ -25,11 +25,38 @@ class Updater extends BasicEmitter {
*/ */
private $log; private $log;
private $simulateStepEnabled;
private $updateStepEnabled;
/** /**
* @param \OC\Log $log * @param \OC\Log $log
*/ */
public function __construct($log = null) { public function __construct($log = null) {
$this->log = $log; $this->log = $log;
$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;
} }
/** /**
@ -92,6 +119,8 @@ class Updater extends BasicEmitter {
/** /**
* runs the update actions in maintenance mode, does not upgrade the source files * runs the update actions in maintenance mode, does not upgrade the source files
* except the main .htaccess file * except the main .htaccess file
*
* @return bool true if the operation succeeded, false otherwise
*/ */
public function upgrade() { public function upgrade() {
\OC_DB::enableCaching(false); \OC_DB::enableCaching(false);
@ -128,6 +157,7 @@ class Updater extends BasicEmitter {
$canUpgrade = false; $canUpgrade = false;
// simulate DB upgrade // simulate DB upgrade
if ($this->simulateStepEnabled) {
try { try {
// simulate core DB upgrade // simulate core DB upgrade
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); \OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
@ -150,6 +180,10 @@ class Updater extends BasicEmitter {
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->emit('\OC\Updater', 'failure', array($exception->getMessage())); $this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
} }
}
else {
$canUpgrade = true;
}
// upgrade from OC6 to OC7 // upgrade from OC6 to OC7
// TODO removed it again for OC8 // TODO removed it again for OC8
@ -158,7 +192,7 @@ class Updater extends BasicEmitter {
\OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes');
} }
if ($canUpgrade) { if ($this->updateStepEnabled && $canUpgrade) {
// proceed with real upgrade // proceed with real upgrade
try { try {
// do the real upgrade // do the real upgrade