You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upgrade.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 OCP\IConfig;
  11. use Symfony\Component\Console\Command\Command;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  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. const ERROR_INVALID_ARGUMENTS = 4;
  21. public $upgradeFailed = false;
  22. /**
  23. * @var IConfig
  24. */
  25. private $config;
  26. /**
  27. * @param IConfig $config
  28. */
  29. public function __construct(IConfig $config) {
  30. parent::__construct();
  31. $this->config = $config;
  32. }
  33. protected function configure() {
  34. $this
  35. ->setName('upgrade')
  36. ->setDescription('run upgrade routines')
  37. ->addOption(
  38. '--skip-migration-test',
  39. null,
  40. InputOption::VALUE_NONE,
  41. 'skips the database schema migration simulation and update directly'
  42. )
  43. ->addOption(
  44. '--dry-run',
  45. null,
  46. InputOption::VALUE_NONE,
  47. 'only runs the database schema migration simulation, do not actually update'
  48. );
  49. }
  50. /**
  51. * Execute the upgrade command
  52. *
  53. * @param InputInterface $input input interface
  54. * @param OutputInterface $output output interface
  55. */
  56. protected function execute(InputInterface $input, OutputInterface $output) {
  57. $simulateStepEnabled = true;
  58. $updateStepEnabled = true;
  59. if ($input->getOption('skip-migration-test')) {
  60. $simulateStepEnabled = false;
  61. }
  62. if ($input->getOption('dry-run')) {
  63. $updateStepEnabled = false;
  64. }
  65. if (!$simulateStepEnabled && !$updateStepEnabled) {
  66. $output->writeln(
  67. '<error>Only one of "--skip-migration-test" or "--dry-run" ' .
  68. 'can be specified at a time.</error>'
  69. );
  70. return self::ERROR_INVALID_ARGUMENTS;
  71. }
  72. if(\OC::checkUpgrade(false)) {
  73. $self = $this;
  74. $updater = new Updater(\OC::$server->getHTTPHelper(), \OC::$server->getAppConfig());
  75. $updater->setSimulateStepEnabled($simulateStepEnabled);
  76. $updater->setUpdateStepEnabled($updateStepEnabled);
  77. $updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
  78. $output->writeln('<info>Turned on maintenance mode</info>');
  79. });
  80. $updater->listen('\OC\Updater', 'maintenanceEnd',
  81. function () use($output, $updateStepEnabled, $self) {
  82. $output->writeln('<info>Turned off maintenance mode</info>');
  83. $mode = $updateStepEnabled ? 'Update' : 'Update simulation';
  84. $status = $self->upgradeFailed ? 'failed' : 'successful';
  85. $message = "<info>$mode $status</info>";
  86. $output->writeln($message);
  87. });
  88. $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
  89. $output->writeln('<info>Updated database</info>');
  90. });
  91. $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
  92. $output->writeln('<info>Checked database schema update</info>');
  93. });
  94. $updater->listen('\OC\Updater', 'disabledApps', function ($appList) use($output) {
  95. $output->writeln('<info>Disabled incompatible apps: ' . implode(', ', $appList) . '</info>');
  96. });
  97. $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
  98. $output->writeln("<error>$message</error>");
  99. $self->upgradeFailed = true;
  100. });
  101. $updater->upgrade();
  102. $this->postUpgradeCheck($input, $output);
  103. return self::ERROR_SUCCESS;
  104. } else if($this->config->getSystemValue('maintenance', false)) {
  105. //Possible scenario: ownCloud core is updated but an app failed
  106. $output->writeln('<warning>ownCloud is in maintenance mode</warning>');
  107. $output->write('<comment>Maybe an upgrade is already in process. Please check the '
  108. . 'logfile (data/owncloud.log). If you want to re-run the '
  109. . 'upgrade procedure, remove the "maintenance mode" from '
  110. . 'config.php and call this script again.</comment>'
  111. , true);
  112. return self::ERROR_MAINTENANCE_MODE;
  113. } else {
  114. $output->writeln('<info>ownCloud is already latest version</info>');
  115. return self::ERROR_UP_TO_DATE;
  116. }
  117. }
  118. /**
  119. * Perform a post upgrade check (specific to the command line tool)
  120. *
  121. * @param InputInterface $input input interface
  122. * @param OutputInterface $output output interface
  123. */
  124. protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
  125. $trustedDomains = $this->config->getSystemValue('trusted_domains', array());
  126. if (empty($trustedDomains)) {
  127. $output->write(
  128. '<warning>The setting "trusted_domains" could not be ' .
  129. 'set automatically by the upgrade script, ' .
  130. 'please set it manually</warning>'
  131. );
  132. }
  133. }
  134. }