From 29a21466f37a7fed4263ecefcbe658b510d1a3f3 Mon Sep 17 00:00:00 2001 From: ringmaster Date: Thu, 24 Oct 2013 13:59:39 -0400 Subject: Add `occ upgrade` command. --- core/command/upgrade.php | 28 ++++++++++++++++++++++++++++ core/register_command.php | 1 + 2 files changed, 29 insertions(+) create mode 100644 core/command/upgrade.php (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php new file mode 100644 index 00000000000..c6551747d3c --- /dev/null +++ b/core/command/upgrade.php @@ -0,0 +1,28 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class Upgrade extends Command { + protected function configure() { + $this + ->setName('upgrade') + ->setDescription('run upgrade routines') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + include \OC::$SERVERROOT . '/upgrade.php'; + } +} diff --git a/core/register_command.php b/core/register_command.php index 683e7ae1833..cfea1a6b888 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -9,3 +9,4 @@ /** @var $application Symfony\Component\Console\Application */ $application->add(new OC\Core\Command\Status); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); +$application->add(new OC\Core\Command\Upgrade()); -- cgit v1.2.3 From a24cbb50afb0e4fffd6bd045645607c42dc404cb Mon Sep 17 00:00:00 2001 From: ringmaster Date: Mon, 28 Oct 2013 10:15:56 -0400 Subject: Move all upgrade routines into the command-line tool. --- core/command/upgrade.php | 56 ++++++++++++++++++++++++++++++++++- upgrade.php | 77 ------------------------------------------------ 2 files changed, 55 insertions(+), 78 deletions(-) delete mode 100644 upgrade.php (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index c6551747d3c..3424c79bf10 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -8,6 +8,7 @@ namespace OC\Core\Command; +use OC\Updater; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,6 +24,59 @@ class Upgrade extends Command { } protected function execute(InputInterface $input, OutputInterface $output) { - include \OC::$SERVERROOT . '/upgrade.php'; + global $RUNTIME_NOAPPS; + + $RUNTIME_NOAPPS = true; //no apps, yet + + require_once \OC::$SERVERROOT . '/lib/base.php'; + + // Don't do anything if ownCloud has not been installed + if(!\OC_Config::getValue('installed', false)) { + echo 'ownCloud has not yet been installed' . PHP_EOL; + exit(0); + } + + if(\OC::checkUpgrade(false)) { + $updater = new Updater(); + + $updater->listen('\OC\Updater', 'maintenanceStart', function () { + echo 'Turned on maintenance mode' . PHP_EOL; + }); + $updater->listen('\OC\Updater', 'maintenanceEnd', function () { + echo 'Turned off maintenance mode' . PHP_EOL; + echo 'Update successful' . PHP_EOL; + }); + $updater->listen('\OC\Updater', 'dbUpgrade', function () { + echo 'Updated database' . PHP_EOL; + }); + $updater->listen('\OC\Updater', 'filecacheStart', function () { + echo 'Updating filecache, this may take really long...' . PHP_EOL; + }); + $updater->listen('\OC\Updater', 'filecacheDone', function () { + echo 'Updated filecache' . PHP_EOL; + }); + $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) { + echo '... ' . $out . '% done ...' . PHP_EOL; + }); + + $updater->listen('\OC\Updater', 'failure', function ($message) { + echo $message . PHP_EOL; + \OC_Config::setValue('maintenance', false); + }); + + $updater->upgrade(); + } else { + if(\OC_Config::getValue('maintenance', false)) { + //Possible scenario: ownCloud core is updated but an app failed + echo 'ownCloud is in maintenance mode' . PHP_EOL; + echo '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.' + . PHP_EOL; + } else { + echo 'ownCloud is already latest version' . PHP_EOL; + } + } } } diff --git a/upgrade.php b/upgrade.php deleted file mode 100644 index 518b514cd8a..00000000000 --- a/upgrade.php +++ /dev/null @@ -1,77 +0,0 @@ -. -* -*/ - -$RUNTIME_NOAPPS = true; //no apps, yet - -require_once 'lib/base.php'; - -// Don't do anything if ownCloud has not been installed -if(!OC_Config::getValue('installed', false)) { - exit(0); -} - -$br = OC::$CLI ? PHP_EOL : '
'; - -if(OC::checkUpgrade(false)) { - $updater = new \OC\Updater(); - - $updater->listen('\OC\Updater', 'maintenanceStart', function () use ($br) { - echo 'Turned on maintenance mode'.$br; - }); - $updater->listen('\OC\Updater', 'maintenanceEnd', function () use ($br) { - echo 'Turned off maintenance mode'.$br; - echo 'Update successful'.$br; - }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($br) { - echo 'Updated database'.$br; - }); - $updater->listen('\OC\Updater', 'filecacheStart', function () use ($br) { - echo 'Updating filecache, this may take really long...'.$br; - }); - $updater->listen('\OC\Updater', 'filecacheDone', function () use ($br) { - echo 'Updated filecache'.$br; - }); - $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) - use ($br) { - echo '... ' . $out . '% done ...'.$br; - }); - - $updater->listen('\OC\Updater', 'failure', function ($message) use ($br) { - echo $message.$br; - OC_Config::setValue('maintenance', false); - }); - - $updater->upgrade(); -} else { - if(OC_Config::getValue('maintenance', false)) { - //Possible scenario: ownCloud core is updated but an app failed - echo 'ownCloud is in maintenance mode'.$br; - echo '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.' - .$br; - } else { - echo 'ownCloud is already latest version'.$br; - } -} -- cgit v1.2.3 From d1c5e5d777d37cb165130714692b1e8d8c7f4421 Mon Sep 17 00:00:00 2001 From: ringmaster Date: Mon, 28 Oct 2013 16:50:28 -0400 Subject: Use the OutputInterface for output and return error codes. --- core/command/upgrade.php | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index 3424c79bf10..2e49519cae5 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -16,6 +16,12 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Upgrade extends Command { + + const ERROR_SUCCESS = 0; + const ERROR_NOT_INSTALLED = 1; + const ERROR_MAINTENANCE_MODE = 2; + const ERROR_UP_TO_DATE = 3; + protected function configure() { $this ->setName('upgrade') @@ -32,50 +38,53 @@ class Upgrade extends Command { // Don't do anything if ownCloud has not been installed if(!\OC_Config::getValue('installed', false)) { - echo 'ownCloud has not yet been installed' . PHP_EOL; - exit(0); + $output->write('ownCloud has not yet been installed', true); + return self::ERROR_NOT_INSTALLED; } if(\OC::checkUpgrade(false)) { $updater = new Updater(); - $updater->listen('\OC\Updater', 'maintenanceStart', function () { - echo 'Turned on maintenance mode' . PHP_EOL; + $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) { + $output->write('Turned on maintenance mode', true); }); - $updater->listen('\OC\Updater', 'maintenanceEnd', function () { - echo 'Turned off maintenance mode' . PHP_EOL; - echo 'Update successful' . PHP_EOL; + $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) { + $output->write('Turned off maintenance mode', true); + $output->write('Update successful', true); }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () { - echo 'Updated database' . PHP_EOL; + $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { + $output->write('Updated database', true); }); - $updater->listen('\OC\Updater', 'filecacheStart', function () { - echo 'Updating filecache, this may take really long...' . PHP_EOL; + $updater->listen('\OC\Updater', 'filecacheStart', function () use($output) { + $output->write('Updating filecache, this may take really long...', true); }); - $updater->listen('\OC\Updater', 'filecacheDone', function () { - echo 'Updated filecache' . PHP_EOL; + $updater->listen('\OC\Updater', 'filecacheDone', function () use($output) { + $output->write('Updated filecache', true); }); - $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) { - echo '... ' . $out . '% done ...' . PHP_EOL; + $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) use($output) { + $output->write('... ' . $out . '% done ...', true); }); - $updater->listen('\OC\Updater', 'failure', function ($message) { - echo $message . PHP_EOL; + $updater->listen('\OC\Updater', 'failure', function ($message) use($output) { + $output->write($message, true); \OC_Config::setValue('maintenance', false); }); $updater->upgrade(); + return self::ERROR_SUCCESS; } else { if(\OC_Config::getValue('maintenance', false)) { //Possible scenario: ownCloud core is updated but an app failed - echo 'ownCloud is in maintenance mode' . PHP_EOL; - echo 'Maybe an upgrade is already in process. Please check the ' + $output->write('ownCloud is in maintenance mode', true); + $output->write('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.' - . PHP_EOL; + , true); + return self::ERROR_MAINTENANCE_MODE; } else { - echo 'ownCloud is already latest version' . PHP_EOL; + $output->write('ownCloud is already latest version', true); + return self::ERROR_UP_TO_DATE; } } } -- cgit v1.2.3 From bca1e12597c1055868b54e1a49aac4140e3e6cbb Mon Sep 17 00:00:00 2001 From: ringmaster Date: Mon, 28 Oct 2013 16:53:36 -0400 Subject: Use writeln() instead of write() --- core/command/upgrade.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index 2e49519cae5..4d1ad2effb8 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -38,7 +38,7 @@ class Upgrade extends Command { // Don't do anything if ownCloud has not been installed if(!\OC_Config::getValue('installed', false)) { - $output->write('ownCloud has not yet been installed', true); + $output->writeln('ownCloud has not yet been installed'); return self::ERROR_NOT_INSTALLED; } @@ -46,27 +46,27 @@ class Upgrade extends Command { $updater = new Updater(); $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) { - $output->write('Turned on maintenance mode', true); + $output->writeln('Turned on maintenance mode'); }); $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) { - $output->write('Turned off maintenance mode', true); - $output->write('Update successful', true); + $output->write('Turned off maintenance mode'); + $output->writeln('Update successful'); }); $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { - $output->write('Updated database', true); + $output->writeln('Updated database'); }); $updater->listen('\OC\Updater', 'filecacheStart', function () use($output) { - $output->write('Updating filecache, this may take really long...', true); + $output->writeln('Updating filecache, this may take really long...'); }); $updater->listen('\OC\Updater', 'filecacheDone', function () use($output) { - $output->write('Updated filecache', true); + $output->writeln('Updated filecache'); }); $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) use($output) { - $output->write('... ' . $out . '% done ...', true); + $output->writeln('... ' . $out . '% done ...'); }); $updater->listen('\OC\Updater', 'failure', function ($message) use($output) { - $output->write($message, true); + $output->writeln($message); \OC_Config::setValue('maintenance', false); }); @@ -75,7 +75,7 @@ class Upgrade extends Command { } else { if(\OC_Config::getValue('maintenance', false)) { //Possible scenario: ownCloud core is updated but an app failed - $output->write('ownCloud is in maintenance mode', true); + $output->writeln('ownCloud is in maintenance mode'); $output->write('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 ' @@ -83,7 +83,7 @@ class Upgrade extends Command { , true); return self::ERROR_MAINTENANCE_MODE; } else { - $output->write('ownCloud is already latest version', true); + $output->writeln('ownCloud is already latest version'); return self::ERROR_UP_TO_DATE; } } -- cgit v1.2.3 From f130caa4a2158b516cf0f0bc383d3f83f91dfc07 Mon Sep 17 00:00:00 2001 From: ringmaster Date: Mon, 28 Oct 2013 17:06:20 -0400 Subject: Missed one write()->writeln(). Fixed. --- core/command/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index 4d1ad2effb8..7f03769a609 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -49,7 +49,7 @@ class Upgrade extends Command { $output->writeln('Turned on maintenance mode'); }); $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) { - $output->write('Turned off maintenance mode'); + $output->writeln('Turned off maintenance mode'); $output->writeln('Update successful'); }); $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { -- cgit v1.2.3 From b8dbec0da464069cea065eb413b0c3fb0e3971d1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 28 Oct 2013 22:19:15 +0100 Subject: Use "else if" to remove one level of indentation. --- core/command/upgrade.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index 7f03769a609..03976e59bd8 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -72,20 +72,18 @@ class Upgrade extends Command { $updater->upgrade(); return self::ERROR_SUCCESS; + } else if(\OC_Config::getValue('maintenance', false)) { + //Possible scenario: ownCloud core is updated but an app failed + $output->writeln('ownCloud is in maintenance mode'); + $output->write('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.' + , true); + return self::ERROR_MAINTENANCE_MODE; } else { - if(\OC_Config::getValue('maintenance', false)) { - //Possible scenario: ownCloud core is updated but an app failed - $output->writeln('ownCloud is in maintenance mode'); - $output->write('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.' - , true); - return self::ERROR_MAINTENANCE_MODE; - } else { - $output->writeln('ownCloud is already latest version'); - return self::ERROR_UP_TO_DATE; - } + $output->writeln('ownCloud is already latest version'); + return self::ERROR_UP_TO_DATE; } } } -- cgit v1.2.3 From 70111ea299dc52d373ccdbbb3f8a804ff12c6d22 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 28 Oct 2013 22:26:44 +0100 Subject: Add some color to the occ upgrade output. --- core/command/upgrade.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/command/upgrade.php b/core/command/upgrade.php index 03976e59bd8..1d105b67a06 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -38,7 +38,7 @@ class Upgrade extends Command { // Don't do anything if ownCloud has not been installed if(!\OC_Config::getValue('installed', false)) { - $output->writeln('ownCloud has not yet been installed'); + $output->writeln('ownCloud has not yet been installed'); return self::ERROR_NOT_INSTALLED; } @@ -46,20 +46,20 @@ class Upgrade extends Command { $updater = new Updater(); $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) { - $output->writeln('Turned on maintenance mode'); + $output->writeln('Turned on maintenance mode'); }); $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) { - $output->writeln('Turned off maintenance mode'); - $output->writeln('Update successful'); + $output->writeln('Turned off maintenance mode'); + $output->writeln('Update successful'); }); $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { - $output->writeln('Updated database'); + $output->writeln('Updated database'); }); $updater->listen('\OC\Updater', 'filecacheStart', function () use($output) { - $output->writeln('Updating filecache, this may take really long...'); + $output->writeln('Updating filecache, this may take really long...'); }); $updater->listen('\OC\Updater', 'filecacheDone', function () use($output) { - $output->writeln('Updated filecache'); + $output->writeln('Updated filecache'); }); $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) use($output) { $output->writeln('... ' . $out . '% done ...'); @@ -74,15 +74,15 @@ class Upgrade extends Command { return self::ERROR_SUCCESS; } else if(\OC_Config::getValue('maintenance', false)) { //Possible scenario: ownCloud core is updated but an app failed - $output->writeln('ownCloud is in maintenance mode'); - $output->write('Maybe an upgrade is already in process. Please check the ' + $output->writeln('ownCloud is in maintenance mode'); + $output->write('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.' + . 'config.php and call this script again.' , true); return self::ERROR_MAINTENANCE_MODE; } else { - $output->writeln('ownCloud is already latest version'); + $output->writeln('ownCloud is already latest version'); return self::ERROR_UP_TO_DATE; } } -- cgit v1.2.3