Blame view
sources/core/command/upgrade.php
4.58 KB
|
31b7f2792
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php /** * Copyright (c) 2013 Owen Winkler <ringmaster@midnightcircus.com> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ namespace OC\Core\Command; use OC\Updater; use Symfony\Component\Console\Command\Command; |
|
31b7f2792
|
13 |
use Symfony\Component\Console\Input\InputInterface; |
|
31b7f2792
|
14 |
use Symfony\Component\Console\Output\OutputInterface; |
|
6d9380f96
|
15 |
use Symfony\Component\Console\Input\InputOption; |
|
31b7f2792
|
16 17 18 19 20 21 22 |
class Upgrade extends Command {
const ERROR_SUCCESS = 0;
const ERROR_NOT_INSTALLED = 1;
const ERROR_MAINTENANCE_MODE = 2;
const ERROR_UP_TO_DATE = 3;
|
|
6d9380f96
|
23 |
const ERROR_INVALID_ARGUMENTS = 4; |
|
31b7f2792
|
24 25 26 27 28 |
protected function configure() {
$this
->setName('upgrade')
->setDescription('run upgrade routines')
|
|
6d9380f96
|
29 30 31 32 33 34 35 36 37 38 39 40 |
->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' ); |
|
31b7f2792
|
41 |
} |
|
837968727
|
42 43 44 45 46 47 |
/** * Execute the upgrade command * * @param InputInterface $input input interface * @param OutputInterface $output output interface */ |
|
31b7f2792
|
48 |
protected function execute(InputInterface $input, OutputInterface $output) {
|
|
31b7f2792
|
49 50 51 52 53 54 55 56 |
require_once \OC::$SERVERROOT . '/lib/base.php';
// Don't do anything if ownCloud has not been installed
if(!\OC_Config::getValue('installed', false)) {
$output->writeln('<error>ownCloud has not yet been installed</error>');
return self::ERROR_NOT_INSTALLED;
}
|
|
6d9380f96
|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
$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;
}
|
|
31b7f2792
|
74 75 |
if(\OC::checkUpgrade(false)) {
$updater = new Updater();
|
|
6d9380f96
|
76 77 |
$updater->setSimulateStepEnabled($simulateStepEnabled); $updater->setUpdateStepEnabled($updateStepEnabled); |
|
31b7f2792
|
78 79 80 |
$updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
$output->writeln('<info>Turned on maintenance mode</info>');
});
|
|
6d9380f96
|
81 |
$updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output, $updateStepEnabled) {
|
|
31b7f2792
|
82 |
$output->writeln('<info>Turned off maintenance mode</info>');
|
|
6d9380f96
|
83 84 85 86 87 88 |
if (!$updateStepEnabled) {
$output->writeln('<info>Update simulation successful</info>');
}
else {
$output->writeln('<info>Update successful</info>');
}
|
|
31b7f2792
|
89 90 91 92 |
});
$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
$output->writeln('<info>Updated database</info>');
});
|
|
6d9380f96
|
93 94 |
$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
$output->writeln('<info>Checked database schema update</info>');
|
|
31b7f2792
|
95 |
}); |
|
6d9380f96
|
96 97 |
$updater->listen('\OC\Updater', 'disabledApps', function ($appList) use($output) {
$output->writeln('<info>Disabled incompatible apps: ' . implode(', ', $appList) . '</info>');
|
|
31b7f2792
|
98 99 100 101 102 103 104 105 |
});
$updater->listen('\OC\Updater', 'failure', function ($message) use($output) {
$output->writeln($message);
\OC_Config::setValue('maintenance', false);
});
$updater->upgrade();
|
|
837968727
|
106 107 |
$this->postUpgradeCheck($input, $output); |
|
31b7f2792
|
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
return self::ERROR_SUCCESS;
} else if(\OC_Config::getValue('maintenance', false)) {
//Possible scenario: ownCloud core is updated but an app failed
$output->writeln('<warning>ownCloud is in maintenance mode</warning>');
$output->write('<comment>Maybe an upgrade is already in process. Please check the '
. 'logfile (data/owncloud.log). If you want to re-run the '
. 'upgrade procedure, remove the "maintenance mode" from '
. 'config.php and call this script again.</comment>'
, true);
return self::ERROR_MAINTENANCE_MODE;
} else {
$output->writeln('<info>ownCloud is already latest version</info>');
return self::ERROR_UP_TO_DATE;
}
}
|
|
837968727
|
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
/**
* Perform a post upgrade check (specific to the command line tool)
*
* @param InputInterface $input input interface
* @param OutputInterface $output output interface
*/
protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
$trustedDomains = \OC_Config::getValue('trusted_domains', array());
if (empty($trustedDomains)) {
$output->write(
'<warning>The setting "trusted_domains" could not be ' .
'set automatically by the upgrade script, ' .
'please set it manually</warning>'
);
}
}
|
|
31b7f2792
|
140 |
} |