Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

update.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Ko- <k.stoffelen@cs.ru.nl>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. * @author Valdnet <47037905+Valdnet@users.noreply.github.com>
  16. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  17. * @author Vincent Petry <pvince81@owncloud.com>
  18. *
  19. * @license AGPL-3.0
  20. *
  21. * This code is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU Affero General Public License, version 3,
  23. * as published by the Free Software Foundation.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU Affero General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Affero General Public License, version 3,
  31. * along with this program. If not, see <http://www.gnu.org/licenses/>
  32. *
  33. */
  34. use OCP\ILogger;
  35. use Symfony\Component\EventDispatcher\GenericEvent;
  36. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  37. @set_time_limit(0);
  38. }
  39. require_once '../../lib/base.php';
  40. $l = \OC::$server->getL10N('core');
  41. $eventSource = \OC::$server->createEventSource();
  42. // need to send an initial message to force-init the event source,
  43. // which will then trigger its own CSRF check and produces its own CSRF error
  44. // message
  45. $eventSource->send('success', (string)$l->t('Preparing update'));
  46. class FeedBackHandler {
  47. /** @var integer */
  48. private $progressStateMax = 100;
  49. /** @var integer */
  50. private $progressStateStep = 0;
  51. /** @var string */
  52. private $currentStep;
  53. /** @var \OCP\IEventSource */
  54. private $eventSource;
  55. /** @var \OCP\IL10N */
  56. private $l10n;
  57. public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) {
  58. $this->eventSource = $eventSource;
  59. $this->l10n = $l10n;
  60. }
  61. public function handleRepairFeedback($event) {
  62. if (!$event instanceof GenericEvent) {
  63. return;
  64. }
  65. switch ($event->getSubject()) {
  66. case '\OC\Repair::startProgress':
  67. $this->progressStateMax = $event->getArgument(0);
  68. $this->progressStateStep = 0;
  69. $this->currentStep = $event->getArgument(1);
  70. break;
  71. case '\OC\Repair::advance':
  72. $this->progressStateStep += $event->getArgument(0);
  73. $desc = $event->getArgument(1);
  74. if (empty($desc)) {
  75. $desc = $this->currentStep;
  76. }
  77. $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
  78. break;
  79. case '\OC\Repair::finishProgress':
  80. $this->progressStateMax = $this->progressStateStep;
  81. $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
  82. break;
  83. case '\OC\Repair::step':
  84. $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0));
  85. break;
  86. case '\OC\Repair::info':
  87. $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0));
  88. break;
  89. case '\OC\Repair::warning':
  90. $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0));
  91. break;
  92. case '\OC\Repair::error':
  93. $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0));
  94. break;
  95. }
  96. }
  97. }
  98. if (\OCP\Util::needUpgrade()) {
  99. $config = \OC::$server->getSystemConfig();
  100. if ($config->getValue('upgrade.disable-web', false)) {
  101. $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
  102. $eventSource->close();
  103. exit();
  104. }
  105. // if a user is currently logged in, their session must be ignored to
  106. // avoid side effects
  107. \OC_User::setIncognitoMode(true);
  108. $logger = \OC::$server->getLogger();
  109. $config = \OC::$server->getConfig();
  110. $updater = new \OC\Updater(
  111. $config,
  112. \OC::$server->getIntegrityCodeChecker(),
  113. $logger,
  114. \OC::$server->query(\OC\Installer::class)
  115. );
  116. $incompatibleApps = [];
  117. $dispatcher = \OC::$server->getEventDispatcher();
  118. $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) {
  119. if ($event instanceof GenericEvent) {
  120. $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
  121. }
  122. });
  123. $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) {
  124. if ($event instanceof GenericEvent) {
  125. $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
  126. }
  127. });
  128. $feedBack = new FeedBackHandler($eventSource, $l);
  129. $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']);
  130. $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']);
  131. $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']);
  132. $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']);
  133. $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']);
  134. $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']);
  135. $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']);
  136. $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
  137. $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
  138. });
  139. $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
  140. $eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
  141. });
  142. $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
  143. $eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
  144. });
  145. $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) {
  146. $eventSource->send('success', (string)$l->t('Updating database schema'));
  147. });
  148. $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
  149. $eventSource->send('success', (string)$l->t('Updated database'));
  150. });
  151. $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) {
  152. $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)'));
  153. });
  154. $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
  155. $eventSource->send('success', (string)$l->t('Checked database schema update'));
  156. });
  157. $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) {
  158. $eventSource->send('success', (string)$l->t('Checking updates of apps'));
  159. });
  160. $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) {
  161. $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app]));
  162. });
  163. $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) {
  164. $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app]));
  165. });
  166. $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) {
  167. $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app]));
  168. });
  169. $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) {
  170. $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]));
  171. });
  172. $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
  173. $eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
  174. });
  175. $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
  176. $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version]));
  177. });
  178. $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
  179. $incompatibleApps[] = $app;
  180. });
  181. $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) {
  182. $eventSource->send('failure', $message);
  183. $eventSource->close();
  184. $config->setSystemValue('maintenance', false);
  185. });
  186. $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) {
  187. $eventSource->send('success', (string)$l->t('Set log level to debug'));
  188. });
  189. $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) {
  190. $eventSource->send('success', (string)$l->t('Reset log level'));
  191. });
  192. $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) {
  193. $eventSource->send('success', (string)$l->t('Starting code integrity check'));
  194. });
  195. $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) {
  196. $eventSource->send('success', (string)$l->t('Finished code integrity check'));
  197. });
  198. try {
  199. $updater->upgrade();
  200. } catch (\Exception $e) {
  201. \OC::$server->getLogger()->logException($e, [
  202. 'level' => ILogger::ERROR,
  203. 'app' => 'update',
  204. ]);
  205. $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
  206. $eventSource->close();
  207. exit();
  208. }
  209. $disabledApps = [];
  210. foreach ($incompatibleApps as $app) {
  211. $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]);
  212. }
  213. if (!empty($disabledApps)) {
  214. $eventSource->send('notice',
  215. (string)$l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)]));
  216. }
  217. } else {
  218. $eventSource->send('notice', (string)$l->t('Already up to date'));
  219. }
  220. $eventSource->send('done', '');
  221. $eventSource->close();