update.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  11. * @author Vincent Petry <pvince81@owncloud.com>
  12. *
  13. * @copyright Copyright (c) 2016, ownCloud, Inc.
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. use Symfony\Component\EventDispatcher\GenericEvent;
  30. set_time_limit(0);
  31. require_once '../../lib/base.php';
  32. $l = \OC::$server->getL10N('core');
  33. $eventSource = \OC::$server->createEventSource();
  34. // need to send an initial message to force-init the event source,
  35. // which will then trigger its own CSRF check and produces its own CSRF error
  36. // message
  37. //$eventSource->send('success', (string)$l->t('Preparing update'));
  38. if (OC::checkUpgrade(false)) {
  39. $config = \OC::$server->getSystemConfig();
  40. if ($config->getValue('upgrade.disable-web', true)) {
  41. $eventSource->send('failure', (string)$l->t('Updates need to be installed. Please use the command line updater.'));
  42. $eventSource->close();
  43. exit();
  44. }
  45. // if a user is currently logged in, their session must be ignored to
  46. // avoid side effects
  47. \OC_User::setIncognitoMode(true);
  48. $logger = \OC::$server->getLogger();
  49. $config = \OC::$server->getConfig();
  50. $updater = new \OC\Updater(
  51. \OC::$server->getHTTPHelper(),
  52. $config,
  53. \OC::$server->getIntegrityCodeChecker(),
  54. $logger
  55. );
  56. $incompatibleApps = [];
  57. $disabledThirdPartyApps = [];
  58. $dispatcher = \OC::$server->getEventDispatcher();
  59. $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) {
  60. if ($event instanceof GenericEvent) {
  61. $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
  62. }
  63. });
  64. $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) {
  65. if ($event instanceof GenericEvent) {
  66. $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
  67. }
  68. });
  69. $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
  70. $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
  71. });
  72. $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
  73. $eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
  74. });
  75. $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
  76. $eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
  77. });
  78. $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) {
  79. $eventSource->send('success', (string)$l->t('Updating database schema'));
  80. });
  81. $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
  82. $eventSource->send('success', (string)$l->t('Updated database'));
  83. });
  84. $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) {
  85. $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)'));
  86. });
  87. $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
  88. $eventSource->send('success', (string)$l->t('Checked database schema update'));
  89. });
  90. $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) {
  91. $eventSource->send('success', (string)$l->t('Checking updates of apps'));
  92. });
  93. $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) {
  94. $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app]));
  95. });
  96. $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
  97. $eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
  98. });
  99. $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
  100. $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
  101. });
  102. $updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) {
  103. $eventSource->send('notice', (string)$l->t('Repair warning: ') . $description);
  104. });
  105. $updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) {
  106. $eventSource->send('notice', (string)$l->t('Repair error: ') . $description);
  107. });
  108. $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
  109. $incompatibleApps[]= $app;
  110. });
  111. $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) {
  112. $disabledThirdPartyApps[]= $app;
  113. });
  114. $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) {
  115. $eventSource->send('failure', $message);
  116. $eventSource->close();
  117. $config->setSystemValue('maintenance', false);
  118. });
  119. $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
  120. $eventSource->send('success', (string)$l->t('Set log level to debug'));
  121. });
  122. $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
  123. $eventSource->send('success', (string)$l->t('Reset log level'));
  124. });
  125. $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) {
  126. $eventSource->send('success', (string)$l->t('Starting code integrity check'));
  127. });
  128. $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) {
  129. $eventSource->send('success', (string)$l->t('Finished code integrity check'));
  130. });
  131. try {
  132. $updater->upgrade();
  133. } catch (\Exception $e) {
  134. $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
  135. $eventSource->close();
  136. exit();
  137. }
  138. $disabledApps = [];
  139. foreach ($disabledThirdPartyApps as $app) {
  140. $disabledApps[$app] = (string) $l->t('%s (3rdparty)', [$app]);
  141. }
  142. foreach ($incompatibleApps as $app) {
  143. $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]);
  144. }
  145. if (!empty($disabledApps)) {
  146. $eventSource->send('notice',
  147. (string)$l->t('Following apps have been disabled: %s', implode(', ', $disabledApps)));
  148. }
  149. } else {
  150. $eventSource->send('notice', (string)$l->t('Already up to date'));
  151. }
  152. $eventSource->send('done', '');
  153. $eventSource->close();