Updater.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Bjoern Schiessle <bjoern@schiessle.org>
  8. * @author Frank Karlitschek <frank@karlitschek.de>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Steffen Lindner <mail@steffen-lindner.de>
  15. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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. namespace OC;
  35. use OC\DB\MigrationService;
  36. use OC\Hooks\BasicEmitter;
  37. use OC\IntegrityCheck\Checker;
  38. use OC_App;
  39. use OCP\BackgroundJob\IJobList;
  40. use OCP\IConfig;
  41. use OCP\ILogger;
  42. use OCP\Util;
  43. use Symfony\Component\EventDispatcher\GenericEvent;
  44. /**
  45. * Class that handles autoupdating of ownCloud
  46. *
  47. * Hooks provided in scope \OC\Updater
  48. * - maintenanceStart()
  49. * - maintenanceEnd()
  50. * - dbUpgrade()
  51. * - failure(string $message)
  52. */
  53. class Updater extends BasicEmitter {
  54. /** @var ILogger $log */
  55. private $log;
  56. /** @var IConfig */
  57. private $config;
  58. /** @var Checker */
  59. private $checker;
  60. /** @var Installer */
  61. private $installer;
  62. /** @var IJobList */
  63. private $jobList;
  64. private $logLevelNames = [
  65. 0 => 'Debug',
  66. 1 => 'Info',
  67. 2 => 'Warning',
  68. 3 => 'Error',
  69. 4 => 'Fatal',
  70. ];
  71. public function __construct(IConfig $config,
  72. Checker $checker,
  73. ILogger $log,
  74. Installer $installer,
  75. IJobList $jobList) {
  76. $this->log = $log;
  77. $this->config = $config;
  78. $this->checker = $checker;
  79. $this->installer = $installer;
  80. $this->jobList = $jobList;
  81. }
  82. /**
  83. * runs the update actions in maintenance mode, does not upgrade the source files
  84. * except the main .htaccess file
  85. *
  86. * @return bool true if the operation succeeded, false otherwise
  87. */
  88. public function upgrade() {
  89. $this->emitRepairEvents();
  90. $this->logAllEvents();
  91. $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN);
  92. $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
  93. $this->config->setSystemValue('loglevel', ILogger::DEBUG);
  94. $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
  95. if(!$wasMaintenanceModeEnabled) {
  96. $this->config->setSystemValue('maintenance', true);
  97. $this->emit('\OC\Updater', 'maintenanceEnabled');
  98. }
  99. $installedVersion = $this->config->getSystemValue('version', '0.0.0');
  100. $currentVersion = implode('.', \OCP\Util::getVersion());
  101. // see https://github.com/nextcloud/server/issues/9992 for potential problem
  102. if (version_compare($installedVersion, '14.0.0.9', '>=')) {
  103. $this->waitForCronToFinish();
  104. }
  105. $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
  106. $success = true;
  107. try {
  108. $this->doUpgrade($currentVersion, $installedVersion);
  109. } catch (HintException $exception) {
  110. $this->log->logException($exception, ['app' => 'core']);
  111. $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint()));
  112. $success = false;
  113. } catch (\Exception $exception) {
  114. $this->log->logException($exception, ['app' => 'core']);
  115. $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
  116. $success = false;
  117. }
  118. $this->emit('\OC\Updater', 'updateEnd', array($success));
  119. if(!$wasMaintenanceModeEnabled && $success) {
  120. $this->config->setSystemValue('maintenance', false);
  121. $this->emit('\OC\Updater', 'maintenanceDisabled');
  122. } else {
  123. $this->emit('\OC\Updater', 'maintenanceActive');
  124. }
  125. $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
  126. $this->config->setSystemValue('loglevel', $logLevel);
  127. $this->config->setSystemValue('installed', true);
  128. return $success;
  129. }
  130. /**
  131. * Return version from which this version is allowed to upgrade from
  132. *
  133. * @return array allowed previous versions per vendor
  134. */
  135. private function getAllowedPreviousVersions() {
  136. // this should really be a JSON file
  137. require \OC::$SERVERROOT . '/version.php';
  138. /** @var array $OC_VersionCanBeUpgradedFrom */
  139. return $OC_VersionCanBeUpgradedFrom;
  140. }
  141. /**
  142. * Return vendor from which this version was published
  143. *
  144. * @return string Get the vendor
  145. */
  146. private function getVendor() {
  147. // this should really be a JSON file
  148. require \OC::$SERVERROOT . '/version.php';
  149. /** @var string $vendor */
  150. return (string) $vendor;
  151. }
  152. /**
  153. * Whether an upgrade to a specified version is possible
  154. * @param string $oldVersion
  155. * @param string $newVersion
  156. * @param array $allowedPreviousVersions
  157. * @return bool
  158. */
  159. public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
  160. $version = explode('.', $oldVersion);
  161. $majorMinor = $version[0] . '.' . $version[1];
  162. $currentVendor = $this->config->getAppValue('core', 'vendor', '');
  163. // Vendor was not set correctly on install, so we have to white-list known versions
  164. if ($currentVendor === '' && isset($allowedPreviousVersions['owncloud'][$oldVersion])) {
  165. $currentVendor = 'owncloud';
  166. }
  167. if ($currentVendor === 'nextcloud') {
  168. return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
  169. && (version_compare($oldVersion, $newVersion, '<=') ||
  170. $this->config->getSystemValue('debug', false));
  171. }
  172. // Check if the instance can be migrated
  173. return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) ||
  174. isset($allowedPreviousVersions[$currentVendor][$oldVersion]);
  175. }
  176. /**
  177. * runs the update actions in maintenance mode, does not upgrade the source files
  178. * except the main .htaccess file
  179. *
  180. * @param string $currentVersion current version to upgrade to
  181. * @param string $installedVersion previous version from which to upgrade from
  182. *
  183. * @throws \Exception
  184. */
  185. private function doUpgrade($currentVersion, $installedVersion) {
  186. // Stop update if the update is over several major versions
  187. $allowedPreviousVersions = $this->getAllowedPreviousVersions();
  188. if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
  189. throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
  190. }
  191. // Update .htaccess files
  192. try {
  193. Setup::updateHtaccess();
  194. Setup::protectDataDirectory();
  195. } catch (\Exception $e) {
  196. throw new \Exception($e->getMessage());
  197. }
  198. // create empty file in data dir, so we can later find
  199. // out that this is indeed an ownCloud data directory
  200. // (in case it didn't exist before)
  201. file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
  202. // pre-upgrade repairs
  203. $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
  204. $repair->run();
  205. $this->doCoreUpgrade();
  206. try {
  207. // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
  208. Setup::installBackgroundJobs();
  209. } catch (\Exception $e) {
  210. throw new \Exception($e->getMessage());
  211. }
  212. // update all shipped apps
  213. $this->checkAppsRequirements();
  214. $this->doAppUpgrade();
  215. // Update the appfetchers version so it downloads the correct list from the appstore
  216. \OC::$server->getAppFetcher()->setVersion($currentVersion);
  217. // upgrade appstore apps
  218. $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps());
  219. $this->upgradeAppStoreApps(\OC_App::$autoDisabledApps, true);
  220. // install new shipped apps on upgrade
  221. OC_App::loadApps(['authentication']);
  222. $errors = Installer::installShippedApps(true);
  223. foreach ($errors as $appId => $exception) {
  224. /** @var \Exception $exception */
  225. $this->log->logException($exception, ['app' => $appId]);
  226. $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
  227. }
  228. // post-upgrade repairs
  229. $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
  230. $repair->run();
  231. //Invalidate update feed
  232. $this->config->setAppValue('core', 'lastupdatedat', 0);
  233. // Check for code integrity if not disabled
  234. if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
  235. $this->emit('\OC\Updater', 'startCheckCodeIntegrity');
  236. $this->checker->runInstanceVerification();
  237. $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
  238. }
  239. // only set the final version if everything went well
  240. $this->config->setSystemValue('version', implode('.', Util::getVersion()));
  241. $this->config->setAppValue('core', 'vendor', $this->getVendor());
  242. }
  243. protected function doCoreUpgrade() {
  244. $this->emit('\OC\Updater', 'dbUpgradeBefore');
  245. // execute core migrations
  246. $ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
  247. $ms->migrate();
  248. $this->emit('\OC\Updater', 'dbUpgrade');
  249. }
  250. /**
  251. * @param string $version the oc version to check app compatibility with
  252. */
  253. protected function checkAppUpgrade($version) {
  254. $apps = \OC_App::getEnabledApps();
  255. $this->emit('\OC\Updater', 'appUpgradeCheckBefore');
  256. $appManager = \OC::$server->getAppManager();
  257. foreach ($apps as $appId) {
  258. $info = \OC_App::getAppInfo($appId);
  259. $compatible = \OC_App::isAppCompatible($version, $info);
  260. $isShipped = $appManager->isShipped($appId);
  261. if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) {
  262. /**
  263. * FIXME: The preupdate check is performed before the database migration, otherwise database changes
  264. * are not possible anymore within it. - Consider this when touching the code.
  265. * @link https://github.com/owncloud/core/issues/10980
  266. * @see \OC_App::updateApp
  267. */
  268. if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
  269. $this->includePreUpdate($appId);
  270. }
  271. if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
  272. $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
  273. \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
  274. }
  275. }
  276. }
  277. $this->emit('\OC\Updater', 'appUpgradeCheck');
  278. }
  279. /**
  280. * Includes the pre-update file. Done here to prevent namespace mixups.
  281. * @param string $appId
  282. */
  283. private function includePreUpdate($appId) {
  284. include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
  285. }
  286. /**
  287. * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
  288. * (types authentication, filesystem, logging, in that order) afterwards.
  289. *
  290. * @throws NeedsUpdateException
  291. */
  292. protected function doAppUpgrade() {
  293. $apps = \OC_App::getEnabledApps();
  294. $priorityTypes = array('authentication', 'filesystem', 'logging');
  295. $pseudoOtherType = 'other';
  296. $stacks = array($pseudoOtherType => array());
  297. foreach ($apps as $appId) {
  298. $priorityType = false;
  299. foreach ($priorityTypes as $type) {
  300. if(!isset($stacks[$type])) {
  301. $stacks[$type] = array();
  302. }
  303. if (\OC_App::isType($appId, [$type])) {
  304. $stacks[$type][] = $appId;
  305. $priorityType = true;
  306. break;
  307. }
  308. }
  309. if (!$priorityType) {
  310. $stacks[$pseudoOtherType][] = $appId;
  311. }
  312. }
  313. foreach ($stacks as $type => $stack) {
  314. foreach ($stack as $appId) {
  315. if (\OC_App::shouldUpgrade($appId)) {
  316. $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
  317. \OC_App::updateApp($appId);
  318. $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
  319. }
  320. if($type !== $pseudoOtherType) {
  321. // load authentication, filesystem and logging apps after
  322. // upgrading them. Other apps my need to rely on modifying
  323. // user and/or filesystem aspects.
  324. \OC_App::loadApp($appId);
  325. }
  326. }
  327. }
  328. }
  329. /**
  330. * check if the current enabled apps are compatible with the current
  331. * ownCloud version. disable them if not.
  332. * This is important if you upgrade ownCloud and have non ported 3rd
  333. * party apps installed.
  334. *
  335. * @return array
  336. * @throws \Exception
  337. */
  338. private function checkAppsRequirements() {
  339. $isCoreUpgrade = $this->isCodeUpgrade();
  340. $apps = OC_App::getEnabledApps();
  341. $version = implode('.', Util::getVersion());
  342. $disabledApps = [];
  343. $appManager = \OC::$server->getAppManager();
  344. foreach ($apps as $app) {
  345. // check if the app is compatible with this version of ownCloud
  346. $info = OC_App::getAppInfo($app);
  347. if($info === null || !OC_App::isAppCompatible($version, $info)) {
  348. if ($appManager->isShipped($app)) {
  349. throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
  350. }
  351. \OC::$server->getAppManager()->disableApp($app);
  352. $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
  353. }
  354. // no need to disable any app in case this is a non-core upgrade
  355. if (!$isCoreUpgrade) {
  356. continue;
  357. }
  358. // shipped apps will remain enabled
  359. if ($appManager->isShipped($app)) {
  360. continue;
  361. }
  362. // authentication and session apps will remain enabled as well
  363. if (OC_App::isType($app, ['session', 'authentication'])) {
  364. continue;
  365. }
  366. }
  367. return $disabledApps;
  368. }
  369. /**
  370. * @return bool
  371. */
  372. private function isCodeUpgrade() {
  373. $installedVersion = $this->config->getSystemValue('version', '0.0.0');
  374. $currentVersion = implode('.', Util::getVersion());
  375. if (version_compare($currentVersion, $installedVersion, '>')) {
  376. return true;
  377. }
  378. return false;
  379. }
  380. /**
  381. * @param array $disabledApps
  382. * @param bool $reenable
  383. * @throws \Exception
  384. */
  385. private function upgradeAppStoreApps(array $disabledApps, $reenable = false) {
  386. foreach($disabledApps as $app) {
  387. try {
  388. $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
  389. if ($this->installer->isUpdateAvailable($app)) {
  390. $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
  391. $this->installer->updateAppstoreApp($app);
  392. }
  393. $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
  394. if ($reenable) {
  395. $ocApp = new \OC_App();
  396. $ocApp->enable($app);
  397. }
  398. } catch (\Exception $ex) {
  399. $this->log->logException($ex, ['app' => 'core']);
  400. }
  401. }
  402. }
  403. /**
  404. * Forward messages emitted by the repair routine
  405. */
  406. private function emitRepairEvents() {
  407. $dispatcher = \OC::$server->getEventDispatcher();
  408. $dispatcher->addListener('\OC\Repair::warning', function ($event) {
  409. if ($event instanceof GenericEvent) {
  410. $this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
  411. }
  412. });
  413. $dispatcher->addListener('\OC\Repair::error', function ($event) {
  414. if ($event instanceof GenericEvent) {
  415. $this->emit('\OC\Updater', 'repairError', $event->getArguments());
  416. }
  417. });
  418. $dispatcher->addListener('\OC\Repair::info', function ($event) {
  419. if ($event instanceof GenericEvent) {
  420. $this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
  421. }
  422. });
  423. $dispatcher->addListener('\OC\Repair::step', function ($event) {
  424. if ($event instanceof GenericEvent) {
  425. $this->emit('\OC\Updater', 'repairStep', $event->getArguments());
  426. }
  427. });
  428. }
  429. private function logAllEvents() {
  430. $log = $this->log;
  431. $dispatcher = \OC::$server->getEventDispatcher();
  432. $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
  433. if (!$event instanceof GenericEvent) {
  434. return;
  435. }
  436. $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
  437. });
  438. $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
  439. if (!$event instanceof GenericEvent) {
  440. return;
  441. }
  442. $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
  443. });
  444. $repairListener = function($event) use ($log) {
  445. if (!$event instanceof GenericEvent) {
  446. return;
  447. }
  448. switch ($event->getSubject()) {
  449. case '\OC\Repair::startProgress':
  450. $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
  451. break;
  452. case '\OC\Repair::advance':
  453. $desc = $event->getArgument(1);
  454. if (empty($desc)) {
  455. $desc = '';
  456. }
  457. $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
  458. break;
  459. case '\OC\Repair::finishProgress':
  460. $log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
  461. break;
  462. case '\OC\Repair::step':
  463. $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
  464. break;
  465. case '\OC\Repair::info':
  466. $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
  467. break;
  468. case '\OC\Repair::warning':
  469. $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
  470. break;
  471. case '\OC\Repair::error':
  472. $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
  473. break;
  474. }
  475. };
  476. $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
  477. $dispatcher->addListener('\OC\Repair::advance', $repairListener);
  478. $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
  479. $dispatcher->addListener('\OC\Repair::step', $repairListener);
  480. $dispatcher->addListener('\OC\Repair::info', $repairListener);
  481. $dispatcher->addListener('\OC\Repair::warning', $repairListener);
  482. $dispatcher->addListener('\OC\Repair::error', $repairListener);
  483. $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
  484. $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
  485. });
  486. $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
  487. $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
  488. });
  489. $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
  490. $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
  491. });
  492. $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
  493. if ($success) {
  494. $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
  495. } else {
  496. $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
  497. }
  498. });
  499. $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
  500. $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
  501. });
  502. $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
  503. $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
  504. });
  505. $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
  506. $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
  507. });
  508. $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
  509. $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
  510. });
  511. $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
  512. $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
  513. });
  514. $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) {
  515. $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']);
  516. });
  517. $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
  518. $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']);
  519. });
  520. $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) {
  521. $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']);
  522. });
  523. $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
  524. $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
  525. });
  526. $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
  527. $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
  528. });
  529. $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
  530. $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
  531. });
  532. $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
  533. $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
  534. });
  535. $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
  536. $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
  537. });
  538. $this->listen('\OC\Updater', 'failure', function ($message) use($log) {
  539. $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
  540. });
  541. $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
  542. $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
  543. });
  544. $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
  545. $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
  546. });
  547. $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
  548. $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
  549. });
  550. $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
  551. $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
  552. });
  553. }
  554. private function waitForCronToFinish() {
  555. while ($this->jobList->isAnyJobRunning()) {
  556. $this->emit('\OC\Updater', 'waitForCronToFinish');
  557. sleep(5);
  558. }
  559. }
  560. }