upgrade.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class Upgrade extends Command {
  14. const ERROR_SUCCESS = 0;
  15. const ERROR_NOT_INSTALLED = 1;
  16. const ERROR_MAINTENANCE_MODE = 2;
  17. const ERROR_UP_TO_DATE = 3;
  18. protected function configure() {
  19. $this
  20. ->setName('upgrade')
  21. ->setDescription('run upgrade routines')
  22. ;
  23. }
  24. /**
  25. * Execute the upgrade command
  26. *
  27. * @param InputInterface $input input interface
  28. * @param OutputInterface $output output interface
  29. */
  30. protected function execute(InputInterface $input, OutputInterface $output) {
  31. require_once \OC::$SERVERROOT . '/lib/base.php';
  32. // Don't do anything if ownCloud has not been installed
  33. if(!\OC_Config::getValue('installed', false)) {
  34. $output->writeln('<error>ownCloud has not yet been installed</error>');
  35. return self::ERROR_NOT_INSTALLED;
  36. }
  37. if(\OC::checkUpgrade(false)) {
  38. $updater = new Updater();
  39. $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
  40. $output->writeln('<info>Turned on maintenance mode</info>');
  41. });
  42. $updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) {
  43. $output->writeln('<info>Turned off maintenance mode</info>');
  44. $output->writeln('<info>Update successful</info>');
  45. });
  46. $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
  47. $output->writeln('<info>Updated database</info>');
  48. });
  49. $updater->listen('\OC\Updater', 'failure', function ($message) use($output) {
  50. $output->writeln($message);
  51. \OC_Config::setValue('maintenance', false);
  52. });
  53. $updater->upgrade();
  54. $this->postUpgradeCheck($input, $output);
  55. return self::ERROR_SUCCESS;
  56. } else if(\OC_Config::getValue('maintenance', false)) {
  57. //Possible scenario: ownCloud core is updated but an app failed
  58. $output->writeln('<warning>ownCloud is in maintenance mode</warning>');
  59. $output->write('<comment>Maybe an upgrade is already in process. Please check the '
  60. . 'logfile (data/owncloud.log). If you want to re-run the '
  61. . 'upgrade procedure, remove the "maintenance mode" from '
  62. . 'config.php and call this script again.</comment>'
  63. , true);
  64. return self::ERROR_MAINTENANCE_MODE;
  65. } else {
  66. $output->writeln('<info>ownCloud is already latest version</info>');
  67. return self::ERROR_UP_TO_DATE;
  68. }
  69. }
  70. /**
  71. * Perform a post upgrade check (specific to the command line tool)
  72. *
  73. * @param InputInterface $input input interface
  74. * @param OutputInterface $output output interface
  75. */
  76. protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
  77. $trustedDomains = \OC_Config::getValue('trusted_domains', array());
  78. if (empty($trustedDomains)) {
  79. $output->write(
  80. '<warning>The setting "trusted_domains" could not be ' .
  81. 'set automatically by the upgrade script, ' .
  82. 'please set it manually</warning>'
  83. );
  84. }
  85. }
  86. }