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:
parent
ff651a3e0d
commit
5e27ac3e0d
|
@ -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>');
|
||||||
$output->writeln('<info>Update successful</info>');
|
if (!$updateStepEnabled) {
|
||||||
|
$output->writeln('<info>Update simulation successful</info>');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$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>');
|
||||||
|
|
|
@ -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,27 +157,32 @@ class Updater extends BasicEmitter {
|
||||||
$canUpgrade = false;
|
$canUpgrade = false;
|
||||||
|
|
||||||
// simulate DB upgrade
|
// simulate DB upgrade
|
||||||
try {
|
if ($this->simulateStepEnabled) {
|
||||||
// simulate core DB upgrade
|
try {
|
||||||
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
// simulate core DB upgrade
|
||||||
|
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||||
|
|
||||||
// simulate apps DB upgrade
|
// simulate apps DB upgrade
|
||||||
$version = \OC_Util::getVersion();
|
$version = \OC_Util::getVersion();
|
||||||
$apps = \OC_App::getEnabledApps();
|
$apps = \OC_App::getEnabledApps();
|
||||||
foreach ($apps as $appId) {
|
foreach ($apps as $appId) {
|
||||||
$info = \OC_App::getAppInfo($appId);
|
$info = \OC_App::getAppInfo($appId);
|
||||||
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
||||||
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
||||||
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
|
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->emit('\OC\Updater', 'dbSimulateUpgrade');
|
||||||
|
|
||||||
|
$canUpgrade = true;
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->emit('\OC\Updater', 'dbSimulateUpgrade');
|
else {
|
||||||
|
|
||||||
$canUpgrade = true;
|
$canUpgrade = true;
|
||||||
} catch (\Exception $exception) {
|
|
||||||
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// upgrade from OC6 to OC7
|
// upgrade from OC6 to OC7
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue