mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
Merge pull request #8905 from owncloud/update-cli-skipcheckmigrate
Added CLI arguments for upgrade simulation steps
This commit is contained in:
commit
ff12969276
2 changed files with 93 additions and 20 deletions
|
|
@ -12,6 +12,7 @@ use OC\Updater;
|
|||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class Upgrade extends Command {
|
||||
|
||||
|
|
@ -19,12 +20,24 @@ class Upgrade extends Command {
|
|||
const ERROR_NOT_INSTALLED = 1;
|
||||
const ERROR_MAINTENANCE_MODE = 2;
|
||||
const ERROR_UP_TO_DATE = 3;
|
||||
const ERROR_INVALID_ARGUMENTS = 4;
|
||||
|
||||
protected function configure() {
|
||||
$this
|
||||
->setName('upgrade')
|
||||
->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;
|
||||
}
|
||||
|
||||
$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)) {
|
||||
$updater = new Updater();
|
||||
|
||||
$updater->setSimulateStepEnabled($simulateStepEnabled);
|
||||
$updater->setUpdateStepEnabled($updateStepEnabled);
|
||||
|
||||
$updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
|
||||
$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>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) {
|
||||
$output->writeln('<info>Updated database</info>');
|
||||
|
|
|
|||
|
|
@ -25,11 +25,38 @@ class Updater extends BasicEmitter {
|
|||
*/
|
||||
private $log;
|
||||
|
||||
private $simulateStepEnabled;
|
||||
|
||||
private $updateStepEnabled;
|
||||
|
||||
/**
|
||||
* @param \OC\Log $log
|
||||
*/
|
||||
public function __construct($log = null) {
|
||||
$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
|
||||
* except the main .htaccess file
|
||||
*
|
||||
* @return bool true if the operation succeeded, false otherwise
|
||||
*/
|
||||
public function upgrade() {
|
||||
\OC_DB::enableCaching(false);
|
||||
|
|
@ -128,27 +157,32 @@ class Updater extends BasicEmitter {
|
|||
$canUpgrade = false;
|
||||
|
||||
// simulate DB upgrade
|
||||
try {
|
||||
// simulate core DB upgrade
|
||||
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||
if ($this->simulateStepEnabled) {
|
||||
try {
|
||||
// simulate core DB upgrade
|
||||
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||
|
||||
// simulate apps DB upgrade
|
||||
$version = \OC_Util::getVersion();
|
||||
$apps = \OC_App::getEnabledApps();
|
||||
foreach ($apps as $appId) {
|
||||
$info = \OC_App::getAppInfo($appId);
|
||||
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
||||
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
||||
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
|
||||
// simulate apps DB upgrade
|
||||
$version = \OC_Util::getVersion();
|
||||
$apps = \OC_App::getEnabledApps();
|
||||
foreach ($apps as $appId) {
|
||||
$info = \OC_App::getAppInfo($appId);
|
||||
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
||||
if (file_exists(\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;
|
||||
} catch (\Exception $exception) {
|
||||
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
||||
}
|
||||
|
||||
// upgrade from OC6 to OC7
|
||||
|
|
@ -158,7 +192,7 @@ class Updater extends BasicEmitter {
|
|||
\OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes');
|
||||
}
|
||||
|
||||
if ($canUpgrade) {
|
||||
if ($this->updateStepEnabled && $canUpgrade) {
|
||||
// proceed with real upgrade
|
||||
try {
|
||||
// do the real upgrade
|
||||
|
|
|
|||
Loading…
Reference in a new issue