@@ -431,7 +431,7 @@ |
||
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
434 | - * @param array $disabledApps |
|
434 | + * @param string[] $disabledApps |
|
435 | 435 | * @throws \Exception |
436 | 436 | */ |
437 | 437 | private function upgradeAppStoreApps(array $disabledApps) { |
@@ -101,43 +101,43 @@ discard block |
||
101 | 101 | $this->logAllEvents(); |
102 | 102 | |
103 | 103 | $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
104 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
104 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
105 | 105 | $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
106 | 106 | |
107 | 107 | $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
108 | 108 | |
109 | - if(!$wasMaintenanceModeEnabled) { |
|
109 | + if (!$wasMaintenanceModeEnabled) { |
|
110 | 110 | $this->config->setSystemValue('maintenance', true); |
111 | 111 | $this->emit('\OC\Updater', 'maintenanceEnabled'); |
112 | 112 | } |
113 | 113 | |
114 | 114 | $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
115 | 115 | $currentVersion = implode('.', \OCP\Util::getVersion()); |
116 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
116 | + $this->log->debug('starting upgrade from '.$installedVersion.' to '.$currentVersion, array('app' => 'core')); |
|
117 | 117 | |
118 | 118 | $success = true; |
119 | 119 | try { |
120 | 120 | $this->doUpgrade($currentVersion, $installedVersion); |
121 | 121 | } catch (HintException $exception) { |
122 | 122 | $this->log->logException($exception, ['app' => 'core']); |
123 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
123 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage().': '.$exception->getHint())); |
|
124 | 124 | $success = false; |
125 | 125 | } catch (\Exception $exception) { |
126 | 126 | $this->log->logException($exception, ['app' => 'core']); |
127 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
127 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception).': '.$exception->getMessage())); |
|
128 | 128 | $success = false; |
129 | 129 | } |
130 | 130 | |
131 | 131 | $this->emit('\OC\Updater', 'updateEnd', array($success)); |
132 | 132 | |
133 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
133 | + if (!$wasMaintenanceModeEnabled && $success) { |
|
134 | 134 | $this->config->setSystemValue('maintenance', false); |
135 | 135 | $this->emit('\OC\Updater', 'maintenanceDisabled'); |
136 | 136 | } else { |
137 | 137 | $this->emit('\OC\Updater', 'maintenanceActive'); |
138 | 138 | } |
139 | 139 | |
140 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
140 | + $this->emit('\OC\Updater', 'resetLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
141 | 141 | $this->config->setSystemValue('loglevel', $logLevel); |
142 | 142 | $this->config->setSystemValue('installed', true); |
143 | 143 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | private function getAllowedPreviousVersions() { |
153 | 153 | // this should really be a JSON file |
154 | - require \OC::$SERVERROOT . '/version.php'; |
|
154 | + require \OC::$SERVERROOT.'/version.php'; |
|
155 | 155 | /** @var array $OC_VersionCanBeUpgradedFrom */ |
156 | 156 | return $OC_VersionCanBeUpgradedFrom; |
157 | 157 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | private function getVendor() { |
165 | 165 | // this should really be a JSON file |
166 | - require \OC::$SERVERROOT . '/version.php'; |
|
166 | + require \OC::$SERVERROOT.'/version.php'; |
|
167 | 167 | /** @var string $vendor */ |
168 | 168 | return (string) $vendor; |
169 | 169 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
179 | 179 | $version = explode('.', $oldVersion); |
180 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
180 | + $majorMinor = $version[0].'.'.$version[1]; |
|
181 | 181 | |
182 | 182 | $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
183 | 183 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // create empty file in data dir, so we can later find |
225 | 225 | // out that this is indeed an ownCloud data directory |
226 | 226 | // (in case it didn't exist before) |
227 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
227 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); |
|
228 | 228 | |
229 | 229 | // pre-upgrade repairs |
230 | 230 | $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | foreach ($errors as $appId => $exception) { |
256 | 256 | /** @var \Exception $exception */ |
257 | 257 | $this->log->logException($exception, ['app' => $appId]); |
258 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
258 | + $this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | // post-upgrade repairs |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $this->config->setAppValue('core', 'lastupdatedat', 0); |
267 | 267 | |
268 | 268 | // Check for code integrity if not disabled |
269 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
269 | + if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
270 | 270 | $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
271 | 271 | $this->checker->runInstanceVerification(); |
272 | 272 | $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
@@ -307,12 +307,12 @@ discard block |
||
307 | 307 | * @link https://github.com/owncloud/core/issues/10980 |
308 | 308 | * @see \OC_App::updateApp |
309 | 309 | */ |
310 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
310 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/preupdate.php')) { |
|
311 | 311 | $this->includePreUpdate($appId); |
312 | 312 | } |
313 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
313 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/database.xml')) { |
|
314 | 314 | $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
315 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
315 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId).'/appinfo/database.xml'); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $appId |
326 | 326 | */ |
327 | 327 | private function includePreUpdate($appId) { |
328 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
328 | + include \OC_App::getAppPath($appId).'/appinfo/preupdate.php'; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | foreach ($apps as $appId) { |
344 | 344 | $priorityType = false; |
345 | 345 | foreach ($priorityTypes as $type) { |
346 | - if(!isset($stacks[$type])) { |
|
346 | + if (!isset($stacks[$type])) { |
|
347 | 347 | $stacks[$type] = array(); |
348 | 348 | } |
349 | 349 | if (\OC_App::isType($appId, [$type])) { |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | \OC_App::updateApp($appId); |
364 | 364 | $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
365 | 365 | } |
366 | - if($type !== $pseudoOtherType) { |
|
366 | + if ($type !== $pseudoOtherType) { |
|
367 | 367 | // load authentication, filesystem and logging apps after |
368 | 368 | // upgrading them. Other apps my need to rely on modifying |
369 | 369 | // user and/or filesystem aspects. |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | foreach ($apps as $app) { |
392 | 392 | // check if the app is compatible with this version of ownCloud |
393 | 393 | $info = OC_App::getAppInfo($app); |
394 | - if($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
394 | + if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
395 | 395 | if ($appManager->isShipped($app)) { |
396 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
396 | + throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update'); |
|
397 | 397 | } |
398 | 398 | \OC::$server->getAppManager()->disableApp($app); |
399 | 399 | $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @throws \Exception |
432 | 432 | */ |
433 | 433 | private function upgradeAppStoreApps(array $disabledApps) { |
434 | - foreach($disabledApps as $app) { |
|
434 | + foreach ($disabledApps as $app) { |
|
435 | 435 | try { |
436 | 436 | $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
437 | 437 | if ($this->installer->isUpdateAvailable($app)) { |
@@ -450,22 +450,22 @@ discard block |
||
450 | 450 | */ |
451 | 451 | private function emitRepairEvents() { |
452 | 452 | $dispatcher = \OC::$server->getEventDispatcher(); |
453 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
453 | + $dispatcher->addListener('\OC\Repair::warning', function($event) { |
|
454 | 454 | if ($event instanceof GenericEvent) { |
455 | 455 | $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
456 | 456 | } |
457 | 457 | }); |
458 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
458 | + $dispatcher->addListener('\OC\Repair::error', function($event) { |
|
459 | 459 | if ($event instanceof GenericEvent) { |
460 | 460 | $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
461 | 461 | } |
462 | 462 | }); |
463 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
463 | + $dispatcher->addListener('\OC\Repair::info', function($event) { |
|
464 | 464 | if ($event instanceof GenericEvent) { |
465 | 465 | $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
466 | 466 | } |
467 | 467 | }); |
468 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
468 | + $dispatcher->addListener('\OC\Repair::step', function($event) { |
|
469 | 469 | if ($event instanceof GenericEvent) { |
470 | 470 | $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
471 | 471 | } |
@@ -480,13 +480,13 @@ discard block |
||
480 | 480 | if (!$event instanceof GenericEvent) { |
481 | 481 | return; |
482 | 482 | } |
483 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
483 | + $log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
484 | 484 | }); |
485 | 485 | $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
486 | 486 | if (!$event instanceof GenericEvent) { |
487 | 487 | return; |
488 | 488 | } |
489 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
489 | + $log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
490 | 490 | }); |
491 | 491 | |
492 | 492 | $repairListener = function($event) use ($log) { |
@@ -495,30 +495,30 @@ discard block |
||
495 | 495 | } |
496 | 496 | switch ($event->getSubject()) { |
497 | 497 | case '\OC\Repair::startProgress': |
498 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
498 | + $log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
499 | 499 | break; |
500 | 500 | case '\OC\Repair::advance': |
501 | 501 | $desc = $event->getArgument(1); |
502 | 502 | if (empty($desc)) { |
503 | 503 | $desc = ''; |
504 | 504 | } |
505 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
505 | + $log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
506 | 506 | |
507 | 507 | break; |
508 | 508 | case '\OC\Repair::finishProgress': |
509 | 509 | $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
510 | 510 | break; |
511 | 511 | case '\OC\Repair::step': |
512 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
512 | + $log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']); |
|
513 | 513 | break; |
514 | 514 | case '\OC\Repair::info': |
515 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
515 | + $log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']); |
|
516 | 516 | break; |
517 | 517 | case '\OC\Repair::warning': |
518 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
518 | + $log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']); |
|
519 | 519 | break; |
520 | 520 | case '\OC\Repair::error': |
521 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
521 | + $log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']); |
|
522 | 522 | break; |
523 | 523 | } |
524 | 524 | }; |
@@ -532,74 +532,74 @@ discard block |
||
532 | 532 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
533 | 533 | |
534 | 534 | |
535 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
535 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function() use($log) { |
|
536 | 536 | $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
537 | 537 | }); |
538 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
538 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function() use($log) { |
|
539 | 539 | $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
540 | 540 | }); |
541 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
541 | + $this->listen('\OC\Updater', 'maintenanceActive', function() use($log) { |
|
542 | 542 | $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
543 | 543 | }); |
544 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
544 | + $this->listen('\OC\Updater', 'updateEnd', function($success) use($log) { |
|
545 | 545 | if ($success) { |
546 | 546 | $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
547 | 547 | } else { |
548 | 548 | $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
549 | 549 | } |
550 | 550 | }); |
551 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
551 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function() use($log) { |
|
552 | 552 | $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
553 | 553 | }); |
554 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
554 | + $this->listen('\OC\Updater', 'dbUpgrade', function() use($log) { |
|
555 | 555 | $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
556 | 556 | }); |
557 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
557 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($log) { |
|
558 | 558 | $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']); |
559 | 559 | }); |
560 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
560 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($log) { |
|
561 | 561 | $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
562 | 562 | }); |
563 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
564 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
563 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($log) { |
|
564 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']); |
|
565 | 565 | }); |
566 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
567 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
566 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($log) { |
|
567 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
568 | 568 | }); |
569 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
570 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
569 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($log) { |
|
570 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']); |
|
571 | 571 | }); |
572 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
573 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
572 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($log) { |
|
573 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
574 | 574 | }); |
575 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
575 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($log) { |
|
576 | 576 | $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
577 | 577 | }); |
578 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
579 | - $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']); |
|
578 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) { |
|
579 | + $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']); |
|
580 | 580 | }); |
581 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
581 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function() use ($log) { |
|
582 | 582 | $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
583 | 583 | }); |
584 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
585 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
584 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) { |
|
585 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']); |
|
586 | 586 | }); |
587 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
588 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
587 | + $this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) { |
|
588 | + $log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']); |
|
589 | 589 | }); |
590 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
591 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
590 | + $this->listen('\OC\Updater', 'failure', function($message) use($log) { |
|
591 | + $log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']); |
|
592 | 592 | }); |
593 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
593 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function() use($log) { |
|
594 | 594 | $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
595 | 595 | }); |
596 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
597 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
596 | + $this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($log) { |
|
597 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']); |
|
598 | 598 | }); |
599 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
599 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($log) { |
|
600 | 600 | $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
601 | 601 | }); |
602 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
602 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($log) { |
|
603 | 603 | $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
604 | 604 | }); |
605 | 605 |
@@ -55,563 +55,563 @@ |
||
55 | 55 | */ |
56 | 56 | class Updater extends BasicEmitter { |
57 | 57 | |
58 | - /** @var ILogger $log */ |
|
59 | - private $log; |
|
60 | - |
|
61 | - /** @var IConfig */ |
|
62 | - private $config; |
|
63 | - |
|
64 | - /** @var Checker */ |
|
65 | - private $checker; |
|
66 | - |
|
67 | - /** @var Installer */ |
|
68 | - private $installer; |
|
69 | - |
|
70 | - /** @var IJobList */ |
|
71 | - private $jobList; |
|
72 | - |
|
73 | - private $logLevelNames = [ |
|
74 | - 0 => 'Debug', |
|
75 | - 1 => 'Info', |
|
76 | - 2 => 'Warning', |
|
77 | - 3 => 'Error', |
|
78 | - 4 => 'Fatal', |
|
79 | - ]; |
|
80 | - |
|
81 | - public function __construct(IConfig $config, |
|
82 | - Checker $checker, |
|
83 | - ILogger $log, |
|
84 | - Installer $installer, |
|
85 | - IJobList $jobList) { |
|
86 | - $this->log = $log; |
|
87 | - $this->config = $config; |
|
88 | - $this->checker = $checker; |
|
89 | - $this->installer = $installer; |
|
90 | - $this->jobList = $jobList; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
95 | - * except the main .htaccess file |
|
96 | - * |
|
97 | - * @return bool true if the operation succeeded, false otherwise |
|
98 | - */ |
|
99 | - public function upgrade() { |
|
100 | - $this->emitRepairEvents(); |
|
101 | - $this->logAllEvents(); |
|
102 | - |
|
103 | - $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
104 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
105 | - $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
106 | - |
|
107 | - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
108 | - |
|
109 | - if(!$wasMaintenanceModeEnabled) { |
|
110 | - $this->config->setSystemValue('maintenance', true); |
|
111 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
112 | - } |
|
113 | - |
|
114 | - $this->waitForCronToFinish(); |
|
115 | - |
|
116 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
117 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
118 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
119 | - |
|
120 | - $success = true; |
|
121 | - try { |
|
122 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
123 | - } catch (HintException $exception) { |
|
124 | - $this->log->logException($exception, ['app' => 'core']); |
|
125 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
126 | - $success = false; |
|
127 | - } catch (\Exception $exception) { |
|
128 | - $this->log->logException($exception, ['app' => 'core']); |
|
129 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
130 | - $success = false; |
|
131 | - } |
|
132 | - |
|
133 | - $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
134 | - |
|
135 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
136 | - $this->config->setSystemValue('maintenance', false); |
|
137 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
138 | - } else { |
|
139 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
140 | - } |
|
141 | - |
|
142 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
143 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
144 | - $this->config->setSystemValue('installed', true); |
|
145 | - |
|
146 | - return $success; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Return version from which this version is allowed to upgrade from |
|
151 | - * |
|
152 | - * @return array allowed previous versions per vendor |
|
153 | - */ |
|
154 | - private function getAllowedPreviousVersions() { |
|
155 | - // this should really be a JSON file |
|
156 | - require \OC::$SERVERROOT . '/version.php'; |
|
157 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
158 | - return $OC_VersionCanBeUpgradedFrom; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Return vendor from which this version was published |
|
163 | - * |
|
164 | - * @return string Get the vendor |
|
165 | - */ |
|
166 | - private function getVendor() { |
|
167 | - // this should really be a JSON file |
|
168 | - require \OC::$SERVERROOT . '/version.php'; |
|
169 | - /** @var string $vendor */ |
|
170 | - return (string) $vendor; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Whether an upgrade to a specified version is possible |
|
175 | - * @param string $oldVersion |
|
176 | - * @param string $newVersion |
|
177 | - * @param array $allowedPreviousVersions |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
181 | - $version = explode('.', $oldVersion); |
|
182 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
183 | - |
|
184 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
185 | - |
|
186 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
187 | - if ($currentVendor === '' && isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
188 | - $currentVendor = 'owncloud'; |
|
189 | - } |
|
190 | - |
|
191 | - if ($currentVendor === 'nextcloud') { |
|
192 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
193 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
194 | - $this->config->getSystemValue('debug', false)); |
|
195 | - } |
|
196 | - |
|
197 | - // Check if the instance can be migrated |
|
198 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
199 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
204 | - * except the main .htaccess file |
|
205 | - * |
|
206 | - * @param string $currentVersion current version to upgrade to |
|
207 | - * @param string $installedVersion previous version from which to upgrade from |
|
208 | - * |
|
209 | - * @throws \Exception |
|
210 | - */ |
|
211 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
212 | - // Stop update if the update is over several major versions |
|
213 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
214 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
215 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
216 | - } |
|
217 | - |
|
218 | - // Update .htaccess files |
|
219 | - try { |
|
220 | - Setup::updateHtaccess(); |
|
221 | - Setup::protectDataDirectory(); |
|
222 | - } catch (\Exception $e) { |
|
223 | - throw new \Exception($e->getMessage()); |
|
224 | - } |
|
225 | - |
|
226 | - // create empty file in data dir, so we can later find |
|
227 | - // out that this is indeed an ownCloud data directory |
|
228 | - // (in case it didn't exist before) |
|
229 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
230 | - |
|
231 | - // pre-upgrade repairs |
|
232 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
233 | - $repair->run(); |
|
234 | - |
|
235 | - $this->doCoreUpgrade(); |
|
236 | - |
|
237 | - try { |
|
238 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
239 | - Setup::installBackgroundJobs(); |
|
240 | - } catch (\Exception $e) { |
|
241 | - throw new \Exception($e->getMessage()); |
|
242 | - } |
|
243 | - |
|
244 | - // update all shipped apps |
|
245 | - $this->checkAppsRequirements(); |
|
246 | - $this->doAppUpgrade(); |
|
247 | - |
|
248 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
249 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
250 | - |
|
251 | - // upgrade appstore apps |
|
252 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
253 | - |
|
254 | - // install new shipped apps on upgrade |
|
255 | - OC_App::loadApps(['authentication']); |
|
256 | - $errors = Installer::installShippedApps(true); |
|
257 | - foreach ($errors as $appId => $exception) { |
|
258 | - /** @var \Exception $exception */ |
|
259 | - $this->log->logException($exception, ['app' => $appId]); |
|
260 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
261 | - } |
|
262 | - |
|
263 | - // post-upgrade repairs |
|
264 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
265 | - $repair->run(); |
|
266 | - |
|
267 | - //Invalidate update feed |
|
268 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
269 | - |
|
270 | - // Check for code integrity if not disabled |
|
271 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
272 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
273 | - $this->checker->runInstanceVerification(); |
|
274 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
275 | - } |
|
276 | - |
|
277 | - // only set the final version if everything went well |
|
278 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
279 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
280 | - } |
|
281 | - |
|
282 | - protected function doCoreUpgrade() { |
|
283 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
284 | - |
|
285 | - // execute core migrations |
|
286 | - $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
287 | - $ms->migrate(); |
|
288 | - |
|
289 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $version the oc version to check app compatibility with |
|
294 | - */ |
|
295 | - protected function checkAppUpgrade($version) { |
|
296 | - $apps = \OC_App::getEnabledApps(); |
|
297 | - $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
298 | - |
|
299 | - $appManager = \OC::$server->getAppManager(); |
|
300 | - foreach ($apps as $appId) { |
|
301 | - $info = \OC_App::getAppInfo($appId); |
|
302 | - $compatible = \OC_App::isAppCompatible($version, $info); |
|
303 | - $isShipped = $appManager->isShipped($appId); |
|
304 | - |
|
305 | - if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
306 | - /** |
|
307 | - * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
308 | - * are not possible anymore within it. - Consider this when touching the code. |
|
309 | - * @link https://github.com/owncloud/core/issues/10980 |
|
310 | - * @see \OC_App::updateApp |
|
311 | - */ |
|
312 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
313 | - $this->includePreUpdate($appId); |
|
314 | - } |
|
315 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
316 | - $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
317 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
318 | - } |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Includes the pre-update file. Done here to prevent namespace mixups. |
|
327 | - * @param string $appId |
|
328 | - */ |
|
329 | - private function includePreUpdate($appId) { |
|
330 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
335 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
336 | - * |
|
337 | - * @throws NeedsUpdateException |
|
338 | - */ |
|
339 | - protected function doAppUpgrade() { |
|
340 | - $apps = \OC_App::getEnabledApps(); |
|
341 | - $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
342 | - $pseudoOtherType = 'other'; |
|
343 | - $stacks = array($pseudoOtherType => array()); |
|
344 | - |
|
345 | - foreach ($apps as $appId) { |
|
346 | - $priorityType = false; |
|
347 | - foreach ($priorityTypes as $type) { |
|
348 | - if(!isset($stacks[$type])) { |
|
349 | - $stacks[$type] = array(); |
|
350 | - } |
|
351 | - if (\OC_App::isType($appId, [$type])) { |
|
352 | - $stacks[$type][] = $appId; |
|
353 | - $priorityType = true; |
|
354 | - break; |
|
355 | - } |
|
356 | - } |
|
357 | - if (!$priorityType) { |
|
358 | - $stacks[$pseudoOtherType][] = $appId; |
|
359 | - } |
|
360 | - } |
|
361 | - foreach ($stacks as $type => $stack) { |
|
362 | - foreach ($stack as $appId) { |
|
363 | - if (\OC_App::shouldUpgrade($appId)) { |
|
364 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
365 | - \OC_App::updateApp($appId); |
|
366 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
367 | - } |
|
368 | - if($type !== $pseudoOtherType) { |
|
369 | - // load authentication, filesystem and logging apps after |
|
370 | - // upgrading them. Other apps my need to rely on modifying |
|
371 | - // user and/or filesystem aspects. |
|
372 | - \OC_App::loadApp($appId); |
|
373 | - } |
|
374 | - } |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * check if the current enabled apps are compatible with the current |
|
380 | - * ownCloud version. disable them if not. |
|
381 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
382 | - * party apps installed. |
|
383 | - * |
|
384 | - * @return array |
|
385 | - * @throws \Exception |
|
386 | - */ |
|
387 | - private function checkAppsRequirements() { |
|
388 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
389 | - $apps = OC_App::getEnabledApps(); |
|
390 | - $version = implode('.', Util::getVersion()); |
|
391 | - $disabledApps = []; |
|
392 | - $appManager = \OC::$server->getAppManager(); |
|
393 | - foreach ($apps as $app) { |
|
394 | - // check if the app is compatible with this version of ownCloud |
|
395 | - $info = OC_App::getAppInfo($app); |
|
396 | - if($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
397 | - if ($appManager->isShipped($app)) { |
|
398 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
399 | - } |
|
400 | - \OC::$server->getAppManager()->disableApp($app); |
|
401 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
402 | - } |
|
403 | - // no need to disable any app in case this is a non-core upgrade |
|
404 | - if (!$isCoreUpgrade) { |
|
405 | - continue; |
|
406 | - } |
|
407 | - // shipped apps will remain enabled |
|
408 | - if ($appManager->isShipped($app)) { |
|
409 | - continue; |
|
410 | - } |
|
411 | - // authentication and session apps will remain enabled as well |
|
412 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
413 | - continue; |
|
414 | - } |
|
415 | - } |
|
416 | - return $disabledApps; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - private function isCodeUpgrade() { |
|
423 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
424 | - $currentVersion = implode('.', Util::getVersion()); |
|
425 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
426 | - return true; |
|
427 | - } |
|
428 | - return false; |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * @param array $disabledApps |
|
433 | - * @throws \Exception |
|
434 | - */ |
|
435 | - private function upgradeAppStoreApps(array $disabledApps) { |
|
436 | - foreach($disabledApps as $app) { |
|
437 | - try { |
|
438 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
439 | - if ($this->installer->isUpdateAvailable($app)) { |
|
440 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
441 | - $this->installer->updateAppstoreApp($app); |
|
442 | - } |
|
443 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
444 | - } catch (\Exception $ex) { |
|
445 | - $this->log->logException($ex, ['app' => 'core']); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Forward messages emitted by the repair routine |
|
452 | - */ |
|
453 | - private function emitRepairEvents() { |
|
454 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
455 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
456 | - if ($event instanceof GenericEvent) { |
|
457 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
458 | - } |
|
459 | - }); |
|
460 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
461 | - if ($event instanceof GenericEvent) { |
|
462 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
463 | - } |
|
464 | - }); |
|
465 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
466 | - if ($event instanceof GenericEvent) { |
|
467 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
468 | - } |
|
469 | - }); |
|
470 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
471 | - if ($event instanceof GenericEvent) { |
|
472 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
473 | - } |
|
474 | - }); |
|
475 | - } |
|
476 | - |
|
477 | - private function logAllEvents() { |
|
478 | - $log = $this->log; |
|
479 | - |
|
480 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
481 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
482 | - if (!$event instanceof GenericEvent) { |
|
483 | - return; |
|
484 | - } |
|
485 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
486 | - }); |
|
487 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
488 | - if (!$event instanceof GenericEvent) { |
|
489 | - return; |
|
490 | - } |
|
491 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
492 | - }); |
|
493 | - |
|
494 | - $repairListener = function($event) use ($log) { |
|
495 | - if (!$event instanceof GenericEvent) { |
|
496 | - return; |
|
497 | - } |
|
498 | - switch ($event->getSubject()) { |
|
499 | - case '\OC\Repair::startProgress': |
|
500 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
501 | - break; |
|
502 | - case '\OC\Repair::advance': |
|
503 | - $desc = $event->getArgument(1); |
|
504 | - if (empty($desc)) { |
|
505 | - $desc = ''; |
|
506 | - } |
|
507 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
508 | - |
|
509 | - break; |
|
510 | - case '\OC\Repair::finishProgress': |
|
511 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
512 | - break; |
|
513 | - case '\OC\Repair::step': |
|
514 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
515 | - break; |
|
516 | - case '\OC\Repair::info': |
|
517 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
518 | - break; |
|
519 | - case '\OC\Repair::warning': |
|
520 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
521 | - break; |
|
522 | - case '\OC\Repair::error': |
|
523 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
524 | - break; |
|
525 | - } |
|
526 | - }; |
|
527 | - |
|
528 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
529 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
530 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
531 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
532 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
533 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
534 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
535 | - |
|
536 | - |
|
537 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
538 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
539 | - }); |
|
540 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
541 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
542 | - }); |
|
543 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
544 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
545 | - }); |
|
546 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
547 | - if ($success) { |
|
548 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
549 | - } else { |
|
550 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
551 | - } |
|
552 | - }); |
|
553 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
554 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
555 | - }); |
|
556 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
557 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
558 | - }); |
|
559 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
560 | - $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']); |
|
561 | - }); |
|
562 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
563 | - $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
564 | - }); |
|
565 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
566 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
567 | - }); |
|
568 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
569 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
570 | - }); |
|
571 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
572 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
573 | - }); |
|
574 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
575 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
576 | - }); |
|
577 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
578 | - $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
579 | - }); |
|
580 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
581 | - $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']); |
|
582 | - }); |
|
583 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
584 | - $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
585 | - }); |
|
586 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
587 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
588 | - }); |
|
589 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
590 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
591 | - }); |
|
592 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
593 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
594 | - }); |
|
595 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
596 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
597 | - }); |
|
598 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
599 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
600 | - }); |
|
601 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
602 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
603 | - }); |
|
604 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
605 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
606 | - }); |
|
607 | - |
|
608 | - } |
|
609 | - private function waitForCronToFinish() { |
|
610 | - while ($this->jobList->isAnyJobRunning()) { |
|
611 | - $this->emit('\OC\Updater', 'waitForCronToFinish'); |
|
612 | - sleep(5); |
|
613 | - } |
|
614 | - } |
|
58 | + /** @var ILogger $log */ |
|
59 | + private $log; |
|
60 | + |
|
61 | + /** @var IConfig */ |
|
62 | + private $config; |
|
63 | + |
|
64 | + /** @var Checker */ |
|
65 | + private $checker; |
|
66 | + |
|
67 | + /** @var Installer */ |
|
68 | + private $installer; |
|
69 | + |
|
70 | + /** @var IJobList */ |
|
71 | + private $jobList; |
|
72 | + |
|
73 | + private $logLevelNames = [ |
|
74 | + 0 => 'Debug', |
|
75 | + 1 => 'Info', |
|
76 | + 2 => 'Warning', |
|
77 | + 3 => 'Error', |
|
78 | + 4 => 'Fatal', |
|
79 | + ]; |
|
80 | + |
|
81 | + public function __construct(IConfig $config, |
|
82 | + Checker $checker, |
|
83 | + ILogger $log, |
|
84 | + Installer $installer, |
|
85 | + IJobList $jobList) { |
|
86 | + $this->log = $log; |
|
87 | + $this->config = $config; |
|
88 | + $this->checker = $checker; |
|
89 | + $this->installer = $installer; |
|
90 | + $this->jobList = $jobList; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
95 | + * except the main .htaccess file |
|
96 | + * |
|
97 | + * @return bool true if the operation succeeded, false otherwise |
|
98 | + */ |
|
99 | + public function upgrade() { |
|
100 | + $this->emitRepairEvents(); |
|
101 | + $this->logAllEvents(); |
|
102 | + |
|
103 | + $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
104 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
105 | + $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
106 | + |
|
107 | + $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
108 | + |
|
109 | + if(!$wasMaintenanceModeEnabled) { |
|
110 | + $this->config->setSystemValue('maintenance', true); |
|
111 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
112 | + } |
|
113 | + |
|
114 | + $this->waitForCronToFinish(); |
|
115 | + |
|
116 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
117 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
118 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
119 | + |
|
120 | + $success = true; |
|
121 | + try { |
|
122 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
123 | + } catch (HintException $exception) { |
|
124 | + $this->log->logException($exception, ['app' => 'core']); |
|
125 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
126 | + $success = false; |
|
127 | + } catch (\Exception $exception) { |
|
128 | + $this->log->logException($exception, ['app' => 'core']); |
|
129 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
130 | + $success = false; |
|
131 | + } |
|
132 | + |
|
133 | + $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
134 | + |
|
135 | + if(!$wasMaintenanceModeEnabled && $success) { |
|
136 | + $this->config->setSystemValue('maintenance', false); |
|
137 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
138 | + } else { |
|
139 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
140 | + } |
|
141 | + |
|
142 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
143 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
144 | + $this->config->setSystemValue('installed', true); |
|
145 | + |
|
146 | + return $success; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Return version from which this version is allowed to upgrade from |
|
151 | + * |
|
152 | + * @return array allowed previous versions per vendor |
|
153 | + */ |
|
154 | + private function getAllowedPreviousVersions() { |
|
155 | + // this should really be a JSON file |
|
156 | + require \OC::$SERVERROOT . '/version.php'; |
|
157 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
158 | + return $OC_VersionCanBeUpgradedFrom; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Return vendor from which this version was published |
|
163 | + * |
|
164 | + * @return string Get the vendor |
|
165 | + */ |
|
166 | + private function getVendor() { |
|
167 | + // this should really be a JSON file |
|
168 | + require \OC::$SERVERROOT . '/version.php'; |
|
169 | + /** @var string $vendor */ |
|
170 | + return (string) $vendor; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Whether an upgrade to a specified version is possible |
|
175 | + * @param string $oldVersion |
|
176 | + * @param string $newVersion |
|
177 | + * @param array $allowedPreviousVersions |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
181 | + $version = explode('.', $oldVersion); |
|
182 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
183 | + |
|
184 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
185 | + |
|
186 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
187 | + if ($currentVendor === '' && isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
188 | + $currentVendor = 'owncloud'; |
|
189 | + } |
|
190 | + |
|
191 | + if ($currentVendor === 'nextcloud') { |
|
192 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
193 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
194 | + $this->config->getSystemValue('debug', false)); |
|
195 | + } |
|
196 | + |
|
197 | + // Check if the instance can be migrated |
|
198 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
199 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
204 | + * except the main .htaccess file |
|
205 | + * |
|
206 | + * @param string $currentVersion current version to upgrade to |
|
207 | + * @param string $installedVersion previous version from which to upgrade from |
|
208 | + * |
|
209 | + * @throws \Exception |
|
210 | + */ |
|
211 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
212 | + // Stop update if the update is over several major versions |
|
213 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
214 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
215 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
216 | + } |
|
217 | + |
|
218 | + // Update .htaccess files |
|
219 | + try { |
|
220 | + Setup::updateHtaccess(); |
|
221 | + Setup::protectDataDirectory(); |
|
222 | + } catch (\Exception $e) { |
|
223 | + throw new \Exception($e->getMessage()); |
|
224 | + } |
|
225 | + |
|
226 | + // create empty file in data dir, so we can later find |
|
227 | + // out that this is indeed an ownCloud data directory |
|
228 | + // (in case it didn't exist before) |
|
229 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
230 | + |
|
231 | + // pre-upgrade repairs |
|
232 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
233 | + $repair->run(); |
|
234 | + |
|
235 | + $this->doCoreUpgrade(); |
|
236 | + |
|
237 | + try { |
|
238 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
239 | + Setup::installBackgroundJobs(); |
|
240 | + } catch (\Exception $e) { |
|
241 | + throw new \Exception($e->getMessage()); |
|
242 | + } |
|
243 | + |
|
244 | + // update all shipped apps |
|
245 | + $this->checkAppsRequirements(); |
|
246 | + $this->doAppUpgrade(); |
|
247 | + |
|
248 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
249 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
250 | + |
|
251 | + // upgrade appstore apps |
|
252 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
253 | + |
|
254 | + // install new shipped apps on upgrade |
|
255 | + OC_App::loadApps(['authentication']); |
|
256 | + $errors = Installer::installShippedApps(true); |
|
257 | + foreach ($errors as $appId => $exception) { |
|
258 | + /** @var \Exception $exception */ |
|
259 | + $this->log->logException($exception, ['app' => $appId]); |
|
260 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
261 | + } |
|
262 | + |
|
263 | + // post-upgrade repairs |
|
264 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
265 | + $repair->run(); |
|
266 | + |
|
267 | + //Invalidate update feed |
|
268 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
269 | + |
|
270 | + // Check for code integrity if not disabled |
|
271 | + if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
272 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
273 | + $this->checker->runInstanceVerification(); |
|
274 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
275 | + } |
|
276 | + |
|
277 | + // only set the final version if everything went well |
|
278 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
279 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
280 | + } |
|
281 | + |
|
282 | + protected function doCoreUpgrade() { |
|
283 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
284 | + |
|
285 | + // execute core migrations |
|
286 | + $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
287 | + $ms->migrate(); |
|
288 | + |
|
289 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $version the oc version to check app compatibility with |
|
294 | + */ |
|
295 | + protected function checkAppUpgrade($version) { |
|
296 | + $apps = \OC_App::getEnabledApps(); |
|
297 | + $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
298 | + |
|
299 | + $appManager = \OC::$server->getAppManager(); |
|
300 | + foreach ($apps as $appId) { |
|
301 | + $info = \OC_App::getAppInfo($appId); |
|
302 | + $compatible = \OC_App::isAppCompatible($version, $info); |
|
303 | + $isShipped = $appManager->isShipped($appId); |
|
304 | + |
|
305 | + if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
306 | + /** |
|
307 | + * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
308 | + * are not possible anymore within it. - Consider this when touching the code. |
|
309 | + * @link https://github.com/owncloud/core/issues/10980 |
|
310 | + * @see \OC_App::updateApp |
|
311 | + */ |
|
312 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
313 | + $this->includePreUpdate($appId); |
|
314 | + } |
|
315 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
316 | + $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
317 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
318 | + } |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Includes the pre-update file. Done here to prevent namespace mixups. |
|
327 | + * @param string $appId |
|
328 | + */ |
|
329 | + private function includePreUpdate($appId) { |
|
330 | + include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
335 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
336 | + * |
|
337 | + * @throws NeedsUpdateException |
|
338 | + */ |
|
339 | + protected function doAppUpgrade() { |
|
340 | + $apps = \OC_App::getEnabledApps(); |
|
341 | + $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
342 | + $pseudoOtherType = 'other'; |
|
343 | + $stacks = array($pseudoOtherType => array()); |
|
344 | + |
|
345 | + foreach ($apps as $appId) { |
|
346 | + $priorityType = false; |
|
347 | + foreach ($priorityTypes as $type) { |
|
348 | + if(!isset($stacks[$type])) { |
|
349 | + $stacks[$type] = array(); |
|
350 | + } |
|
351 | + if (\OC_App::isType($appId, [$type])) { |
|
352 | + $stacks[$type][] = $appId; |
|
353 | + $priorityType = true; |
|
354 | + break; |
|
355 | + } |
|
356 | + } |
|
357 | + if (!$priorityType) { |
|
358 | + $stacks[$pseudoOtherType][] = $appId; |
|
359 | + } |
|
360 | + } |
|
361 | + foreach ($stacks as $type => $stack) { |
|
362 | + foreach ($stack as $appId) { |
|
363 | + if (\OC_App::shouldUpgrade($appId)) { |
|
364 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
365 | + \OC_App::updateApp($appId); |
|
366 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
367 | + } |
|
368 | + if($type !== $pseudoOtherType) { |
|
369 | + // load authentication, filesystem and logging apps after |
|
370 | + // upgrading them. Other apps my need to rely on modifying |
|
371 | + // user and/or filesystem aspects. |
|
372 | + \OC_App::loadApp($appId); |
|
373 | + } |
|
374 | + } |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * check if the current enabled apps are compatible with the current |
|
380 | + * ownCloud version. disable them if not. |
|
381 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
382 | + * party apps installed. |
|
383 | + * |
|
384 | + * @return array |
|
385 | + * @throws \Exception |
|
386 | + */ |
|
387 | + private function checkAppsRequirements() { |
|
388 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
389 | + $apps = OC_App::getEnabledApps(); |
|
390 | + $version = implode('.', Util::getVersion()); |
|
391 | + $disabledApps = []; |
|
392 | + $appManager = \OC::$server->getAppManager(); |
|
393 | + foreach ($apps as $app) { |
|
394 | + // check if the app is compatible with this version of ownCloud |
|
395 | + $info = OC_App::getAppInfo($app); |
|
396 | + if($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
397 | + if ($appManager->isShipped($app)) { |
|
398 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
399 | + } |
|
400 | + \OC::$server->getAppManager()->disableApp($app); |
|
401 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
402 | + } |
|
403 | + // no need to disable any app in case this is a non-core upgrade |
|
404 | + if (!$isCoreUpgrade) { |
|
405 | + continue; |
|
406 | + } |
|
407 | + // shipped apps will remain enabled |
|
408 | + if ($appManager->isShipped($app)) { |
|
409 | + continue; |
|
410 | + } |
|
411 | + // authentication and session apps will remain enabled as well |
|
412 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
413 | + continue; |
|
414 | + } |
|
415 | + } |
|
416 | + return $disabledApps; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + private function isCodeUpgrade() { |
|
423 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
424 | + $currentVersion = implode('.', Util::getVersion()); |
|
425 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
426 | + return true; |
|
427 | + } |
|
428 | + return false; |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * @param array $disabledApps |
|
433 | + * @throws \Exception |
|
434 | + */ |
|
435 | + private function upgradeAppStoreApps(array $disabledApps) { |
|
436 | + foreach($disabledApps as $app) { |
|
437 | + try { |
|
438 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
439 | + if ($this->installer->isUpdateAvailable($app)) { |
|
440 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
441 | + $this->installer->updateAppstoreApp($app); |
|
442 | + } |
|
443 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
444 | + } catch (\Exception $ex) { |
|
445 | + $this->log->logException($ex, ['app' => 'core']); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Forward messages emitted by the repair routine |
|
452 | + */ |
|
453 | + private function emitRepairEvents() { |
|
454 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
455 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
456 | + if ($event instanceof GenericEvent) { |
|
457 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
458 | + } |
|
459 | + }); |
|
460 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
461 | + if ($event instanceof GenericEvent) { |
|
462 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
463 | + } |
|
464 | + }); |
|
465 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
466 | + if ($event instanceof GenericEvent) { |
|
467 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
468 | + } |
|
469 | + }); |
|
470 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
471 | + if ($event instanceof GenericEvent) { |
|
472 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
473 | + } |
|
474 | + }); |
|
475 | + } |
|
476 | + |
|
477 | + private function logAllEvents() { |
|
478 | + $log = $this->log; |
|
479 | + |
|
480 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
481 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
482 | + if (!$event instanceof GenericEvent) { |
|
483 | + return; |
|
484 | + } |
|
485 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
486 | + }); |
|
487 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
488 | + if (!$event instanceof GenericEvent) { |
|
489 | + return; |
|
490 | + } |
|
491 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
492 | + }); |
|
493 | + |
|
494 | + $repairListener = function($event) use ($log) { |
|
495 | + if (!$event instanceof GenericEvent) { |
|
496 | + return; |
|
497 | + } |
|
498 | + switch ($event->getSubject()) { |
|
499 | + case '\OC\Repair::startProgress': |
|
500 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
501 | + break; |
|
502 | + case '\OC\Repair::advance': |
|
503 | + $desc = $event->getArgument(1); |
|
504 | + if (empty($desc)) { |
|
505 | + $desc = ''; |
|
506 | + } |
|
507 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
508 | + |
|
509 | + break; |
|
510 | + case '\OC\Repair::finishProgress': |
|
511 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
512 | + break; |
|
513 | + case '\OC\Repair::step': |
|
514 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
515 | + break; |
|
516 | + case '\OC\Repair::info': |
|
517 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
518 | + break; |
|
519 | + case '\OC\Repair::warning': |
|
520 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
521 | + break; |
|
522 | + case '\OC\Repair::error': |
|
523 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
524 | + break; |
|
525 | + } |
|
526 | + }; |
|
527 | + |
|
528 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
529 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
530 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
531 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
532 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
533 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
534 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
535 | + |
|
536 | + |
|
537 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
538 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
539 | + }); |
|
540 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
541 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
542 | + }); |
|
543 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
544 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
545 | + }); |
|
546 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
547 | + if ($success) { |
|
548 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
549 | + } else { |
|
550 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
551 | + } |
|
552 | + }); |
|
553 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
554 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
555 | + }); |
|
556 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
557 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
558 | + }); |
|
559 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
560 | + $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']); |
|
561 | + }); |
|
562 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
563 | + $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
564 | + }); |
|
565 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
566 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
567 | + }); |
|
568 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
569 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
570 | + }); |
|
571 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
572 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
573 | + }); |
|
574 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
575 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
576 | + }); |
|
577 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
578 | + $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
579 | + }); |
|
580 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
581 | + $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']); |
|
582 | + }); |
|
583 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
584 | + $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
585 | + }); |
|
586 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
587 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
588 | + }); |
|
589 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
590 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
591 | + }); |
|
592 | + $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
593 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
594 | + }); |
|
595 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
596 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
597 | + }); |
|
598 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
599 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
600 | + }); |
|
601 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
602 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
603 | + }); |
|
604 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
605 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
606 | + }); |
|
607 | + |
|
608 | + } |
|
609 | + private function waitForCronToFinish() { |
|
610 | + while ($this->jobList->isAnyJobRunning()) { |
|
611 | + $this->emit('\OC\Updater', 'waitForCronToFinish'); |
|
612 | + sleep(5); |
|
613 | + } |
|
614 | + } |
|
615 | 615 | |
616 | 616 | } |
617 | 617 |
@@ -23,20 +23,20 @@ |
||
23 | 23 | |
24 | 24 | class CoreBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return 'Core bundle'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return 'Core bundle'; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'bruteforcesettings', |
|
39 | - ]; |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'bruteforcesettings', |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
30 | + return (string) $this->l10n->t('Groupware bundle'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -23,22 +23,22 @@ |
||
23 | 23 | |
24 | 24 | class GroupwareBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return (string)$this->l10n->t('Groupware bundle'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'calendar', |
|
39 | - 'contacts', |
|
40 | - 'spreed', |
|
41 | - ]; |
|
42 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'calendar', |
|
39 | + 'contacts', |
|
40 | + 'spreed', |
|
41 | + ]; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
@@ -23,25 +23,25 @@ |
||
23 | 23 | |
24 | 24 | class EnterpriseBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return (string)$this->l10n->t('Enterprise bundle'); |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return (string)$this->l10n->t('Enterprise bundle'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'admin_audit', |
|
39 | - 'user_ldap', |
|
40 | - 'files_retention', |
|
41 | - 'files_automatedtagging', |
|
42 | - 'user_saml', |
|
43 | - 'files_accesscontrol', |
|
44 | - ]; |
|
45 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'admin_audit', |
|
39 | + 'user_ldap', |
|
40 | + 'files_retention', |
|
41 | + 'files_automatedtagging', |
|
42 | + 'user_saml', |
|
43 | + 'files_accesscontrol', |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Enterprise bundle'); |
|
30 | + return (string) $this->l10n->t('Enterprise bundle'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public final function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public final function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public abstract function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public abstract function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public abstract function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public abstract function getAppIdentifiers(); |
|
59 | 59 | } |
@@ -34,59 +34,59 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class ConvertMysqlToMB4 extends Command { |
37 | - /** @var IConfig */ |
|
38 | - private $config; |
|
37 | + /** @var IConfig */ |
|
38 | + private $config; |
|
39 | 39 | |
40 | - /** @var IDBConnection */ |
|
41 | - private $connection; |
|
40 | + /** @var IDBConnection */ |
|
41 | + private $connection; |
|
42 | 42 | |
43 | - /** @var IURLGenerator */ |
|
44 | - private $urlGenerator; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + private $urlGenerator; |
|
45 | 45 | |
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IConfig $config |
|
51 | - * @param IDBConnection $connection |
|
52 | - * @param IURLGenerator $urlGenerator |
|
53 | - * @param ILogger $logger |
|
54 | - */ |
|
55 | - public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | - $this->config = $config; |
|
57 | - $this->connection = $connection; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - $this->logger = $logger; |
|
60 | - parent::__construct(); |
|
61 | - } |
|
49 | + /** |
|
50 | + * @param IConfig $config |
|
51 | + * @param IDBConnection $connection |
|
52 | + * @param IURLGenerator $urlGenerator |
|
53 | + * @param ILogger $logger |
|
54 | + */ |
|
55 | + public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | + $this->config = $config; |
|
57 | + $this->connection = $connection; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + $this->logger = $logger; |
|
60 | + parent::__construct(); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('db:convert-mysql-charset') |
|
66 | - ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('db:convert-mysql-charset') |
|
66 | + ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | - $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | - return 1; |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | + $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | + return 1; |
|
73 | + } |
|
74 | 74 | |
75 | - $tools = new MySqlTools(); |
|
76 | - if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | - $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | - $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | - $output->writeln("For more information please read the documentation at $url"); |
|
80 | - return 1; |
|
81 | - } |
|
75 | + $tools = new MySqlTools(); |
|
76 | + if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | + $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | + $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | + $output->writeln("For more information please read the documentation at $url"); |
|
80 | + return 1; |
|
81 | + } |
|
82 | 82 | |
83 | - // enable charset |
|
84 | - $this->config->setSystemValue('mysql.utf8mb4', true); |
|
83 | + // enable charset |
|
84 | + $this->config->setSystemValue('mysql.utf8mb4', true); |
|
85 | 85 | |
86 | - // run conversion |
|
87 | - $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | - $coll->run(new ConsoleOutput($output)); |
|
86 | + // run conversion |
|
87 | + $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | + $coll->run(new ConsoleOutput($output)); |
|
89 | 89 | |
90 | - return 0; |
|
91 | - } |
|
90 | + return 0; |
|
91 | + } |
|
92 | 92 | } |
@@ -28,22 +28,22 @@ |
||
28 | 28 | */ |
29 | 29 | class MySqlTools { |
30 | 30 | |
31 | - /** |
|
32 | - * @param Connection $connection |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function supports4ByteCharset(IDBConnection $connection) { |
|
36 | - foreach (['innodb_file_format' => 'Barracuda', 'innodb_large_prefix' => 'ON', 'innodb_file_per_table' => 'ON'] as $var => $val) { |
|
37 | - $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'"); |
|
38 | - $rows = $result->fetch(); |
|
39 | - $result->closeCursor(); |
|
40 | - if ($rows === false) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - if (strcasecmp($rows['Value'], $val) !== 0) { |
|
44 | - return false; |
|
45 | - } |
|
46 | - } |
|
47 | - return true; |
|
48 | - } |
|
31 | + /** |
|
32 | + * @param Connection $connection |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function supports4ByteCharset(IDBConnection $connection) { |
|
36 | + foreach (['innodb_file_format' => 'Barracuda', 'innodb_large_prefix' => 'ON', 'innodb_file_per_table' => 'ON'] as $var => $val) { |
|
37 | + $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'"); |
|
38 | + $rows = $result->fetch(); |
|
39 | + $result->closeCursor(); |
|
40 | + if ($rows === false) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + if (strcasecmp($rows['Value'], $val) !== 0) { |
|
44 | + return false; |
|
45 | + } |
|
46 | + } |
|
47 | + return true; |
|
48 | + } |
|
49 | 49 | } |
@@ -195,38 +195,38 @@ |
||
195 | 195 | $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
196 | 196 | |
197 | 197 | // keep old verification status if we don't have a new one |
198 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
198 | + if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
199 | 199 | // keep old verification status if value didn't changed and an old value exists |
200 | 200 | $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
201 | 201 | $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
202 | 202 | } |
203 | 203 | |
204 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
204 | + if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
205 | 205 | // keep old verification status if value didn't changed and an old value exists |
206 | 206 | $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
207 | 207 | $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
208 | 208 | } |
209 | 209 | |
210 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
210 | + if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
211 | 211 | // keep old verification status if value didn't changed and an old value exists |
212 | 212 | $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
213 | 213 | $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // reset verification status if a value from a previously verified data was changed |
217 | - if($twitterVerified && |
|
217 | + if ($twitterVerified && |
|
218 | 218 | $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
219 | 219 | ) { |
220 | 220 | $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
221 | 221 | } |
222 | 222 | |
223 | - if($websiteVerified && |
|
223 | + if ($websiteVerified && |
|
224 | 224 | $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
225 | 225 | ) { |
226 | 226 | $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
227 | 227 | } |
228 | 228 | |
229 | - if($emailVerified && |
|
229 | + if ($emailVerified && |
|
230 | 230 | $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
231 | 231 | ) { |
232 | 232 | $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
@@ -43,305 +43,305 @@ |
||
43 | 43 | */ |
44 | 44 | class AccountManager { |
45 | 45 | |
46 | - /** nobody can see my account details */ |
|
47 | - const VISIBILITY_PRIVATE = 'private'; |
|
48 | - /** only contacts, especially trusted servers can see my contact details */ |
|
49 | - const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
50 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
51 | - const VISIBILITY_PUBLIC = 'public'; |
|
52 | - |
|
53 | - const PROPERTY_AVATAR = 'avatar'; |
|
54 | - const PROPERTY_DISPLAYNAME = 'displayname'; |
|
55 | - const PROPERTY_PHONE = 'phone'; |
|
56 | - const PROPERTY_EMAIL = 'email'; |
|
57 | - const PROPERTY_WEBSITE = 'website'; |
|
58 | - const PROPERTY_ADDRESS = 'address'; |
|
59 | - const PROPERTY_TWITTER = 'twitter'; |
|
60 | - |
|
61 | - const NOT_VERIFIED = '0'; |
|
62 | - const VERIFICATION_IN_PROGRESS = '1'; |
|
63 | - const VERIFIED = '2'; |
|
64 | - |
|
65 | - /** @var IDBConnection database connection */ |
|
66 | - private $connection; |
|
67 | - |
|
68 | - /** @var string table name */ |
|
69 | - private $table = 'accounts'; |
|
70 | - |
|
71 | - /** @var EventDispatcherInterface */ |
|
72 | - private $eventDispatcher; |
|
73 | - |
|
74 | - /** @var IJobList */ |
|
75 | - private $jobList; |
|
76 | - |
|
77 | - /** |
|
78 | - * AccountManager constructor. |
|
79 | - * |
|
80 | - * @param IDBConnection $connection |
|
81 | - * @param EventDispatcherInterface $eventDispatcher |
|
82 | - * @param IJobList $jobList |
|
83 | - */ |
|
84 | - public function __construct(IDBConnection $connection, |
|
85 | - EventDispatcherInterface $eventDispatcher, |
|
86 | - IJobList $jobList) { |
|
87 | - $this->connection = $connection; |
|
88 | - $this->eventDispatcher = $eventDispatcher; |
|
89 | - $this->jobList = $jobList; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * update user record |
|
94 | - * |
|
95 | - * @param IUser $user |
|
96 | - * @param $data |
|
97 | - */ |
|
98 | - public function updateUser(IUser $user, $data) { |
|
99 | - $userData = $this->getUser($user); |
|
100 | - $updated = true; |
|
101 | - if (empty($userData)) { |
|
102 | - $this->insertNewUser($user, $data); |
|
103 | - } elseif ($userData !== $data) { |
|
104 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
105 | - $data = $this->updateVerifyStatus($userData, $data); |
|
106 | - $this->updateExistingUser($user, $data); |
|
107 | - } else { |
|
108 | - // nothing needs to be done if new and old data set are the same |
|
109 | - $updated = false; |
|
110 | - } |
|
111 | - |
|
112 | - if ($updated) { |
|
113 | - $this->eventDispatcher->dispatch( |
|
114 | - 'OC\AccountManager::userUpdated', |
|
115 | - new GenericEvent($user, $data) |
|
116 | - ); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * delete user from accounts table |
|
122 | - * |
|
123 | - * @param IUser $user |
|
124 | - */ |
|
125 | - public function deleteUser(IUser $user) { |
|
126 | - $uid = $user->getUID(); |
|
127 | - $query = $this->connection->getQueryBuilder(); |
|
128 | - $query->delete($this->table) |
|
129 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
130 | - ->execute(); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * get stored data from a given user |
|
135 | - * |
|
136 | - * @param IUser $user |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function getUser(IUser $user) { |
|
140 | - $uid = $user->getUID(); |
|
141 | - $query = $this->connection->getQueryBuilder(); |
|
142 | - $query->select('data')->from($this->table) |
|
143 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
144 | - ->setParameter('uid', $uid); |
|
145 | - $query->execute(); |
|
146 | - $result = $query->execute()->fetchAll(); |
|
147 | - |
|
148 | - if (empty($result)) { |
|
149 | - $userData = $this->buildDefaultUserRecord($user); |
|
150 | - $this->insertNewUser($user, $userData); |
|
151 | - return $userData; |
|
152 | - } |
|
153 | - |
|
154 | - $userDataArray = json_decode($result[0]['data'], true); |
|
155 | - |
|
156 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
157 | - |
|
158 | - return $userDataArray; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
163 | - * |
|
164 | - * @param $oldData |
|
165 | - * @param $newData |
|
166 | - * @param IUser $user |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
170 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
171 | - $this->jobList->add(VerifyUserData::class, |
|
172 | - [ |
|
173 | - 'verificationCode' => '', |
|
174 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
175 | - 'type' => self::PROPERTY_EMAIL, |
|
176 | - 'uid' => $user->getUID(), |
|
177 | - 'try' => 0, |
|
178 | - 'lastRun' => time() |
|
179 | - ] |
|
180 | - ); |
|
181 | - $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
182 | - } |
|
183 | - |
|
184 | - return $newData; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * make sure that all expected data are set |
|
189 | - * |
|
190 | - * @param array $userData |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function addMissingDefaultValues(array $userData) { |
|
194 | - |
|
195 | - foreach ($userData as $key => $value) { |
|
196 | - if (!isset($userData[$key]['verified'])) { |
|
197 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $userData; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * reset verification status if personal data changed |
|
206 | - * |
|
207 | - * @param array $oldData |
|
208 | - * @param array $newData |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - protected function updateVerifyStatus($oldData, $newData) { |
|
212 | - |
|
213 | - // which account was already verified successfully? |
|
214 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
215 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
216 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
217 | - |
|
218 | - // keep old verification status if we don't have a new one |
|
219 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
220 | - // keep old verification status if value didn't changed and an old value exists |
|
221 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
222 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
223 | - } |
|
224 | - |
|
225 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
226 | - // keep old verification status if value didn't changed and an old value exists |
|
227 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
228 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
229 | - } |
|
230 | - |
|
231 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
232 | - // keep old verification status if value didn't changed and an old value exists |
|
233 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
234 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
235 | - } |
|
236 | - |
|
237 | - // reset verification status if a value from a previously verified data was changed |
|
238 | - if($twitterVerified && |
|
239 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
240 | - ) { |
|
241 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
242 | - } |
|
243 | - |
|
244 | - if($websiteVerified && |
|
245 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
246 | - ) { |
|
247 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
248 | - } |
|
249 | - |
|
250 | - if($emailVerified && |
|
251 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
252 | - ) { |
|
253 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
254 | - } |
|
255 | - |
|
256 | - return $newData; |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * add new user to accounts table |
|
262 | - * |
|
263 | - * @param IUser $user |
|
264 | - * @param array $data |
|
265 | - */ |
|
266 | - protected function insertNewUser(IUser $user, $data) { |
|
267 | - $uid = $user->getUID(); |
|
268 | - $jsonEncodedData = json_encode($data); |
|
269 | - $query = $this->connection->getQueryBuilder(); |
|
270 | - $query->insert($this->table) |
|
271 | - ->values( |
|
272 | - [ |
|
273 | - 'uid' => $query->createNamedParameter($uid), |
|
274 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
275 | - ] |
|
276 | - ) |
|
277 | - ->execute(); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * update existing user in accounts table |
|
282 | - * |
|
283 | - * @param IUser $user |
|
284 | - * @param array $data |
|
285 | - */ |
|
286 | - protected function updateExistingUser(IUser $user, $data) { |
|
287 | - $uid = $user->getUID(); |
|
288 | - $jsonEncodedData = json_encode($data); |
|
289 | - $query = $this->connection->getQueryBuilder(); |
|
290 | - $query->update($this->table) |
|
291 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
292 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
293 | - ->execute(); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * build default user record in case not data set exists yet |
|
298 | - * |
|
299 | - * @param IUser $user |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - protected function buildDefaultUserRecord(IUser $user) { |
|
303 | - return [ |
|
304 | - self::PROPERTY_DISPLAYNAME => |
|
305 | - [ |
|
306 | - 'value' => $user->getDisplayName(), |
|
307 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
308 | - 'verified' => self::NOT_VERIFIED, |
|
309 | - ], |
|
310 | - self::PROPERTY_ADDRESS => |
|
311 | - [ |
|
312 | - 'value' => '', |
|
313 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
314 | - 'verified' => self::NOT_VERIFIED, |
|
315 | - ], |
|
316 | - self::PROPERTY_WEBSITE => |
|
317 | - [ |
|
318 | - 'value' => '', |
|
319 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
320 | - 'verified' => self::NOT_VERIFIED, |
|
321 | - ], |
|
322 | - self::PROPERTY_EMAIL => |
|
323 | - [ |
|
324 | - 'value' => $user->getEMailAddress(), |
|
325 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
326 | - 'verified' => self::NOT_VERIFIED, |
|
327 | - ], |
|
328 | - self::PROPERTY_AVATAR => |
|
329 | - [ |
|
330 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
331 | - ], |
|
332 | - self::PROPERTY_PHONE => |
|
333 | - [ |
|
334 | - 'value' => '', |
|
335 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
336 | - 'verified' => self::NOT_VERIFIED, |
|
337 | - ], |
|
338 | - self::PROPERTY_TWITTER => |
|
339 | - [ |
|
340 | - 'value' => '', |
|
341 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
342 | - 'verified' => self::NOT_VERIFIED, |
|
343 | - ], |
|
344 | - ]; |
|
345 | - } |
|
46 | + /** nobody can see my account details */ |
|
47 | + const VISIBILITY_PRIVATE = 'private'; |
|
48 | + /** only contacts, especially trusted servers can see my contact details */ |
|
49 | + const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
50 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
51 | + const VISIBILITY_PUBLIC = 'public'; |
|
52 | + |
|
53 | + const PROPERTY_AVATAR = 'avatar'; |
|
54 | + const PROPERTY_DISPLAYNAME = 'displayname'; |
|
55 | + const PROPERTY_PHONE = 'phone'; |
|
56 | + const PROPERTY_EMAIL = 'email'; |
|
57 | + const PROPERTY_WEBSITE = 'website'; |
|
58 | + const PROPERTY_ADDRESS = 'address'; |
|
59 | + const PROPERTY_TWITTER = 'twitter'; |
|
60 | + |
|
61 | + const NOT_VERIFIED = '0'; |
|
62 | + const VERIFICATION_IN_PROGRESS = '1'; |
|
63 | + const VERIFIED = '2'; |
|
64 | + |
|
65 | + /** @var IDBConnection database connection */ |
|
66 | + private $connection; |
|
67 | + |
|
68 | + /** @var string table name */ |
|
69 | + private $table = 'accounts'; |
|
70 | + |
|
71 | + /** @var EventDispatcherInterface */ |
|
72 | + private $eventDispatcher; |
|
73 | + |
|
74 | + /** @var IJobList */ |
|
75 | + private $jobList; |
|
76 | + |
|
77 | + /** |
|
78 | + * AccountManager constructor. |
|
79 | + * |
|
80 | + * @param IDBConnection $connection |
|
81 | + * @param EventDispatcherInterface $eventDispatcher |
|
82 | + * @param IJobList $jobList |
|
83 | + */ |
|
84 | + public function __construct(IDBConnection $connection, |
|
85 | + EventDispatcherInterface $eventDispatcher, |
|
86 | + IJobList $jobList) { |
|
87 | + $this->connection = $connection; |
|
88 | + $this->eventDispatcher = $eventDispatcher; |
|
89 | + $this->jobList = $jobList; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * update user record |
|
94 | + * |
|
95 | + * @param IUser $user |
|
96 | + * @param $data |
|
97 | + */ |
|
98 | + public function updateUser(IUser $user, $data) { |
|
99 | + $userData = $this->getUser($user); |
|
100 | + $updated = true; |
|
101 | + if (empty($userData)) { |
|
102 | + $this->insertNewUser($user, $data); |
|
103 | + } elseif ($userData !== $data) { |
|
104 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
105 | + $data = $this->updateVerifyStatus($userData, $data); |
|
106 | + $this->updateExistingUser($user, $data); |
|
107 | + } else { |
|
108 | + // nothing needs to be done if new and old data set are the same |
|
109 | + $updated = false; |
|
110 | + } |
|
111 | + |
|
112 | + if ($updated) { |
|
113 | + $this->eventDispatcher->dispatch( |
|
114 | + 'OC\AccountManager::userUpdated', |
|
115 | + new GenericEvent($user, $data) |
|
116 | + ); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * delete user from accounts table |
|
122 | + * |
|
123 | + * @param IUser $user |
|
124 | + */ |
|
125 | + public function deleteUser(IUser $user) { |
|
126 | + $uid = $user->getUID(); |
|
127 | + $query = $this->connection->getQueryBuilder(); |
|
128 | + $query->delete($this->table) |
|
129 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
130 | + ->execute(); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * get stored data from a given user |
|
135 | + * |
|
136 | + * @param IUser $user |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function getUser(IUser $user) { |
|
140 | + $uid = $user->getUID(); |
|
141 | + $query = $this->connection->getQueryBuilder(); |
|
142 | + $query->select('data')->from($this->table) |
|
143 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
144 | + ->setParameter('uid', $uid); |
|
145 | + $query->execute(); |
|
146 | + $result = $query->execute()->fetchAll(); |
|
147 | + |
|
148 | + if (empty($result)) { |
|
149 | + $userData = $this->buildDefaultUserRecord($user); |
|
150 | + $this->insertNewUser($user, $userData); |
|
151 | + return $userData; |
|
152 | + } |
|
153 | + |
|
154 | + $userDataArray = json_decode($result[0]['data'], true); |
|
155 | + |
|
156 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
157 | + |
|
158 | + return $userDataArray; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
163 | + * |
|
164 | + * @param $oldData |
|
165 | + * @param $newData |
|
166 | + * @param IUser $user |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
170 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
171 | + $this->jobList->add(VerifyUserData::class, |
|
172 | + [ |
|
173 | + 'verificationCode' => '', |
|
174 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
175 | + 'type' => self::PROPERTY_EMAIL, |
|
176 | + 'uid' => $user->getUID(), |
|
177 | + 'try' => 0, |
|
178 | + 'lastRun' => time() |
|
179 | + ] |
|
180 | + ); |
|
181 | + $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
182 | + } |
|
183 | + |
|
184 | + return $newData; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * make sure that all expected data are set |
|
189 | + * |
|
190 | + * @param array $userData |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function addMissingDefaultValues(array $userData) { |
|
194 | + |
|
195 | + foreach ($userData as $key => $value) { |
|
196 | + if (!isset($userData[$key]['verified'])) { |
|
197 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $userData; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * reset verification status if personal data changed |
|
206 | + * |
|
207 | + * @param array $oldData |
|
208 | + * @param array $newData |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + protected function updateVerifyStatus($oldData, $newData) { |
|
212 | + |
|
213 | + // which account was already verified successfully? |
|
214 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
215 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
216 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
217 | + |
|
218 | + // keep old verification status if we don't have a new one |
|
219 | + if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
220 | + // keep old verification status if value didn't changed and an old value exists |
|
221 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
222 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
223 | + } |
|
224 | + |
|
225 | + if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
226 | + // keep old verification status if value didn't changed and an old value exists |
|
227 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
228 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
229 | + } |
|
230 | + |
|
231 | + if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
232 | + // keep old verification status if value didn't changed and an old value exists |
|
233 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
234 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
235 | + } |
|
236 | + |
|
237 | + // reset verification status if a value from a previously verified data was changed |
|
238 | + if($twitterVerified && |
|
239 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
240 | + ) { |
|
241 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
242 | + } |
|
243 | + |
|
244 | + if($websiteVerified && |
|
245 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
246 | + ) { |
|
247 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
248 | + } |
|
249 | + |
|
250 | + if($emailVerified && |
|
251 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
252 | + ) { |
|
253 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
254 | + } |
|
255 | + |
|
256 | + return $newData; |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * add new user to accounts table |
|
262 | + * |
|
263 | + * @param IUser $user |
|
264 | + * @param array $data |
|
265 | + */ |
|
266 | + protected function insertNewUser(IUser $user, $data) { |
|
267 | + $uid = $user->getUID(); |
|
268 | + $jsonEncodedData = json_encode($data); |
|
269 | + $query = $this->connection->getQueryBuilder(); |
|
270 | + $query->insert($this->table) |
|
271 | + ->values( |
|
272 | + [ |
|
273 | + 'uid' => $query->createNamedParameter($uid), |
|
274 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
275 | + ] |
|
276 | + ) |
|
277 | + ->execute(); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * update existing user in accounts table |
|
282 | + * |
|
283 | + * @param IUser $user |
|
284 | + * @param array $data |
|
285 | + */ |
|
286 | + protected function updateExistingUser(IUser $user, $data) { |
|
287 | + $uid = $user->getUID(); |
|
288 | + $jsonEncodedData = json_encode($data); |
|
289 | + $query = $this->connection->getQueryBuilder(); |
|
290 | + $query->update($this->table) |
|
291 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
292 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
293 | + ->execute(); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * build default user record in case not data set exists yet |
|
298 | + * |
|
299 | + * @param IUser $user |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + protected function buildDefaultUserRecord(IUser $user) { |
|
303 | + return [ |
|
304 | + self::PROPERTY_DISPLAYNAME => |
|
305 | + [ |
|
306 | + 'value' => $user->getDisplayName(), |
|
307 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
308 | + 'verified' => self::NOT_VERIFIED, |
|
309 | + ], |
|
310 | + self::PROPERTY_ADDRESS => |
|
311 | + [ |
|
312 | + 'value' => '', |
|
313 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
314 | + 'verified' => self::NOT_VERIFIED, |
|
315 | + ], |
|
316 | + self::PROPERTY_WEBSITE => |
|
317 | + [ |
|
318 | + 'value' => '', |
|
319 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
320 | + 'verified' => self::NOT_VERIFIED, |
|
321 | + ], |
|
322 | + self::PROPERTY_EMAIL => |
|
323 | + [ |
|
324 | + 'value' => $user->getEMailAddress(), |
|
325 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
326 | + 'verified' => self::NOT_VERIFIED, |
|
327 | + ], |
|
328 | + self::PROPERTY_AVATAR => |
|
329 | + [ |
|
330 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
331 | + ], |
|
332 | + self::PROPERTY_PHONE => |
|
333 | + [ |
|
334 | + 'value' => '', |
|
335 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
336 | + 'verified' => self::NOT_VERIFIED, |
|
337 | + ], |
|
338 | + self::PROPERTY_TWITTER => |
|
339 | + [ |
|
340 | + 'value' => '', |
|
341 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
342 | + 'verified' => self::NOT_VERIFIED, |
|
343 | + ], |
|
344 | + ]; |
|
345 | + } |
|
346 | 346 | |
347 | 347 | } |
@@ -48,6 +48,9 @@ discard block |
||
48 | 48 | $this->stack = $stack; |
49 | 49 | } |
50 | 50 | |
51 | + /** |
|
52 | + * @param double $time |
|
53 | + */ |
|
51 | 54 | public function end($time) { |
52 | 55 | $this->end = $time; |
53 | 56 | } |
@@ -67,7 +70,7 @@ discard block |
||
67 | 70 | } |
68 | 71 | |
69 | 72 | /** |
70 | - * @return float |
|
73 | + * @return integer |
|
71 | 74 | */ |
72 | 75 | public function getStart() { |
73 | 76 | return $this->start; |
@@ -26,65 +26,65 @@ |
||
26 | 26 | use OCP\Diagnostics\IQuery; |
27 | 27 | |
28 | 28 | class Query implements IQuery { |
29 | - private $sql; |
|
29 | + private $sql; |
|
30 | 30 | |
31 | - private $params; |
|
31 | + private $params; |
|
32 | 32 | |
33 | - private $start; |
|
33 | + private $start; |
|
34 | 34 | |
35 | - private $end; |
|
35 | + private $end; |
|
36 | 36 | |
37 | - private $stack; |
|
37 | + private $stack; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $sql |
|
41 | - * @param array $params |
|
42 | - * @param int $start |
|
43 | - */ |
|
44 | - public function __construct($sql, $params, $start, array $stack) { |
|
45 | - $this->sql = $sql; |
|
46 | - $this->params = $params; |
|
47 | - $this->start = $start; |
|
48 | - $this->stack = $stack; |
|
49 | - } |
|
39 | + /** |
|
40 | + * @param string $sql |
|
41 | + * @param array $params |
|
42 | + * @param int $start |
|
43 | + */ |
|
44 | + public function __construct($sql, $params, $start, array $stack) { |
|
45 | + $this->sql = $sql; |
|
46 | + $this->params = $params; |
|
47 | + $this->start = $start; |
|
48 | + $this->stack = $stack; |
|
49 | + } |
|
50 | 50 | |
51 | - public function end($time) { |
|
52 | - $this->end = $time; |
|
53 | - } |
|
51 | + public function end($time) { |
|
52 | + $this->end = $time; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getParams() { |
|
59 | - return $this->params; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getParams() { |
|
59 | + return $this->params; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getSql() { |
|
66 | - return $this->sql; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getSql() { |
|
66 | + return $this->sql; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return float |
|
71 | - */ |
|
72 | - public function getStart() { |
|
73 | - return $this->start; |
|
74 | - } |
|
69 | + /** |
|
70 | + * @return float |
|
71 | + */ |
|
72 | + public function getStart() { |
|
73 | + return $this->start; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public function getDuration() { |
|
80 | - return $this->end - $this->start; |
|
81 | - } |
|
76 | + /** |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public function getDuration() { |
|
80 | + return $this->end - $this->start; |
|
81 | + } |
|
82 | 82 | |
83 | - public function getStartTime() { |
|
84 | - return $this->start; |
|
85 | - } |
|
83 | + public function getStartTime() { |
|
84 | + return $this->start; |
|
85 | + } |
|
86 | 86 | |
87 | - public function getStacktrace() { |
|
88 | - return $this->stack; |
|
89 | - } |
|
87 | + public function getStacktrace() { |
|
88 | + return $this->stack; |
|
89 | + } |
|
90 | 90 | } |