upgrade.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Owen Winkler <ringmaster@midnightcircus.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Core\Command;
  9. use OC\Updater;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Upgrade extends Command {
  16. const ERROR_SUCCESS = 0;
  17. const ERROR_NOT_INSTALLED = 1;
  18. const ERROR_MAINTENANCE_MODE = 2;
  19. const ERROR_UP_TO_DATE = 3;
  20. protected function configure() {
  21. $this
  22. ->setName('upgrade')
  23. ->setDescription('run upgrade routines')
  24. ;
  25. }
  26. protected function execute(InputInterface $input, OutputInterface $output) {
  27. global $RUNTIME_NOAPPS;
  28. $RUNTIME_NOAPPS = true; //no apps, yet
  29. require_once \OC::$SERVERROOT . '/lib/base.php';
  30. // Don't do anything if ownCloud has not been installed
  31. if(!\OC_Config::getValue('installed', false)) {
  32. $output->writeln('<error>ownCloud has not yet been installed</error>');
  33. return self::ERROR_NOT_INSTALLED;
  34. }
  35. if(\OC::checkUpgrade(false)) {
  36. $updater = new Updater();
  37. $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
  38. $output->writeln('<info>Turned on maintenance mode</info>');
  39. });
  40. $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) {
  41. $output->writeln('<info>Turned off maintenance mode</info>');
  42. $output->writeln('<info>Update successful</info>');
  43. });
  44. $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
  45. $output->writeln('<info>Updated database</info>');
  46. });
  47. $updater->listen('\OC\Updater', 'filecacheStart', function () use($output) {
  48. $output->writeln('<info>Updating filecache, this may take really long...</info>');
  49. });
  50. $updater->listen('\OC\Updater', 'filecacheDone', function () use($output) {
  51. $output->writeln('<info>Updated filecache</info>');
  52. });
  53. $updater->listen('\OC\Updater', 'filecacheProgress', function ($out) use($output) {
  54. $output->writeln('... ' . $out . '% done ...');
  55. });
  56. $updater->listen('\OC\Updater', 'failure', function ($message) use($output) {
  57. $output->writeln($message);
  58. \OC_Config::setValue('maintenance', false);
  59. });
  60. $updater->upgrade();
  61. return self::ERROR_SUCCESS;
  62. } else if(\OC_Config::getValue('maintenance', false)) {
  63. //Possible scenario: ownCloud core is updated but an app failed
  64. $output->writeln('<warning>ownCloud is in maintenance mode</warning>');
  65. $output->write('<comment>Maybe an upgrade is already in process. Please check the '
  66. . 'logfile (data/owncloud.log). If you want to re-run the '
  67. . 'upgrade procedure, remove the "maintenance mode" from '
  68. . 'config.php and call this script again.</comment>'
  69. , true);
  70. return self::ERROR_MAINTENANCE_MODE;
  71. } else {
  72. $output->writeln('<info>ownCloud is already latest version</info>');
  73. return self::ERROR_UP_TO_DATE;
  74. }
  75. }
  76. }