update.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  9. * @author Vincent Petry <pvince81@owncloud.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. set_time_limit(0);
  28. require_once '../../lib/base.php';
  29. \OCP\JSON::callCheck();
  30. if (OC::checkUpgrade(false)) {
  31. // if a user is currently logged in, their session must be ignored to
  32. // avoid side effects
  33. \OC_User::setIncognitoMode(true);
  34. $l = new \OC_L10N('core');
  35. $eventSource = \OC::$server->createEventSource();
  36. $updater = new \OC\Updater(
  37. \OC::$server->getHTTPHelper(),
  38. \OC::$server->getConfig(),
  39. \OC_Log::$object
  40. );
  41. $incompatibleApps = [];
  42. $disabledThirdPartyApps = [];
  43. $updater->listen('\OC\Updater', 'maintenanceStart', function () use ($eventSource, $l) {
  44. $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
  45. });
  46. $updater->listen('\OC\Updater', 'maintenanceEnd', function () use ($eventSource, $l) {
  47. $eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
  48. });
  49. $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
  50. $eventSource->send('success', (string)$l->t('Updated database'));
  51. });
  52. $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
  53. $eventSource->send('success', (string)$l->t('Checked database schema update'));
  54. });
  55. $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
  56. $eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
  57. });
  58. $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
  59. $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
  60. });
  61. $updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) {
  62. $eventSource->send('notice', (string)$l->t('Repair warning: ') . $description);
  63. });
  64. $updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) {
  65. $eventSource->send('notice', (string)$l->t('Repair error: ') . $description);
  66. });
  67. $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
  68. $incompatibleApps[]= $app;
  69. });
  70. $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) {
  71. $disabledThirdPartyApps[]= $app;
  72. });
  73. $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource) {
  74. $eventSource->send('failure', $message);
  75. $eventSource->close();
  76. OC_Config::setValue('maintenance', false);
  77. });
  78. $updater->upgrade();
  79. if (!empty($incompatibleApps)) {
  80. $eventSource->send('notice',
  81. (string)$l->t('Following incompatible apps have been disabled: %s', implode(', ', $incompatibleApps)));
  82. }
  83. if (!empty($disabledThirdPartyApps)) {
  84. $eventSource->send('notice',
  85. (string)$l->t('Following 3rd party apps have been disabled: %s', implode(', ', $disabledThirdPartyApps)));
  86. }
  87. $eventSource->send('done', '');
  88. $eventSource->close();
  89. }