Completed
Pull Request — master (#10031)
by Blizzz
18:14 queued 01:24
created
lib/private/BackgroundJob/Job.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,17 +55,17 @@
 block discarded – undo
55 55
 
56 56
 		try {
57 57
 			$jobStartTime = time();
58
-			$logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
58
+			$logger->debug('Run '.get_class($this).' job with ID '.$this->getId(), ['app' => 'cron']);
59 59
 			$this->run($this->argument);
60 60
 			$timeTaken = time() - $jobStartTime;
61 61
 
62
-			$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
62
+			$logger->debug('Finished '.get_class($this).' job with ID '.$this->getId().' in '.$timeTaken.' seconds', ['app' => 'cron']);
63 63
 			$jobList->setExecutionTime($this, $timeTaken);
64 64
 		} catch (\Exception $e) {
65 65
 			if ($logger) {
66 66
 				$logger->logException($e, [
67 67
 					'app' => 'core',
68
-					'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
68
+					'message' => 'Error while running background job (class: '.get_class($this).', arguments: '.print_r($this->argument, true).')'
69 69
 				]);
70 70
 			}
71 71
 		}
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -28,72 +28,72 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 abstract class Job implements IJob {
31
-	/**
32
-	 * @var int $id
33
-	 */
34
-	protected $id;
31
+    /**
32
+     * @var int $id
33
+     */
34
+    protected $id;
35 35
 
36
-	/**
37
-	 * @var int $lastRun
38
-	 */
39
-	protected $lastRun;
36
+    /**
37
+     * @var int $lastRun
38
+     */
39
+    protected $lastRun;
40 40
 
41
-	/**
42
-	 * @var mixed $argument
43
-	 */
44
-	protected $argument;
41
+    /**
42
+     * @var mixed $argument
43
+     */
44
+    protected $argument;
45 45
 
46
-	/**
47
-	 * @param JobList $jobList
48
-	 * @param ILogger|null $logger
49
-	 */
50
-	public function execute($jobList, ILogger $logger = null) {
51
-		$jobList->setLastRun($this);
52
-		if ($logger === null) {
53
-			$logger = \OC::$server->getLogger();
54
-		}
46
+    /**
47
+     * @param JobList $jobList
48
+     * @param ILogger|null $logger
49
+     */
50
+    public function execute($jobList, ILogger $logger = null) {
51
+        $jobList->setLastRun($this);
52
+        if ($logger === null) {
53
+            $logger = \OC::$server->getLogger();
54
+        }
55 55
 
56
-		try {
57
-			$jobStartTime = time();
58
-			$logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
59
-			$this->run($this->argument);
60
-			$timeTaken = time() - $jobStartTime;
56
+        try {
57
+            $jobStartTime = time();
58
+            $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
59
+            $this->run($this->argument);
60
+            $timeTaken = time() - $jobStartTime;
61 61
 
62
-			$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
63
-			$jobList->setExecutionTime($this, $timeTaken);
64
-		} catch (\Exception $e) {
65
-			if ($logger) {
66
-				$logger->logException($e, [
67
-					'app' => 'core',
68
-					'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
69
-				]);
70
-			}
71
-		}
72
-	}
62
+            $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
63
+            $jobList->setExecutionTime($this, $timeTaken);
64
+        } catch (\Exception $e) {
65
+            if ($logger) {
66
+                $logger->logException($e, [
67
+                    'app' => 'core',
68
+                    'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
69
+                ]);
70
+            }
71
+        }
72
+    }
73 73
 
74
-	abstract protected function run($argument);
74
+    abstract protected function run($argument);
75 75
 
76
-	public function setId($id) {
77
-		$this->id = $id;
78
-	}
76
+    public function setId($id) {
77
+        $this->id = $id;
78
+    }
79 79
 
80
-	public function setLastRun($lastRun) {
81
-		$this->lastRun = $lastRun;
82
-	}
80
+    public function setLastRun($lastRun) {
81
+        $this->lastRun = $lastRun;
82
+    }
83 83
 
84
-	public function setArgument($argument) {
85
-		$this->argument = $argument;
86
-	}
84
+    public function setArgument($argument) {
85
+        $this->argument = $argument;
86
+    }
87 87
 
88
-	public function getId() {
89
-		return $this->id;
90
-	}
88
+    public function getId() {
89
+        return $this->id;
90
+    }
91 91
 
92
-	public function getLastRun() {
93
-		return $this->lastRun;
94
-	}
92
+    public function getLastRun() {
93
+        return $this->lastRun;
94
+    }
95 95
 
96
-	public function getArgument() {
97
-		return $this->argument;
98
-	}
96
+    public function getArgument() {
97
+        return $this->argument;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
lib/public/BackgroundJob/IJobList.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -32,100 +32,100 @@
 block discarded – undo
32 32
  * @since 7.0.0
33 33
  */
34 34
 interface IJobList {
35
-	/**
36
-	 * Add a job to the list
37
-	 *
38
-	 * @param \OCP\BackgroundJob\IJob|string $job
39
-	 * @param mixed $argument The argument to be passed to $job->run() when the job is exectured
40
-	 * @since 7.0.0
41
-	 */
42
-	public function add($job, $argument = null);
35
+    /**
36
+     * Add a job to the list
37
+     *
38
+     * @param \OCP\BackgroundJob\IJob|string $job
39
+     * @param mixed $argument The argument to be passed to $job->run() when the job is exectured
40
+     * @since 7.0.0
41
+     */
42
+    public function add($job, $argument = null);
43 43
 
44
-	/**
45
-	 * Remove a job from the list
46
-	 *
47
-	 * @param \OCP\BackgroundJob\IJob|string $job
48
-	 * @param mixed $argument
49
-	 * @since 7.0.0
50
-	 */
51
-	public function remove($job, $argument = null);
44
+    /**
45
+     * Remove a job from the list
46
+     *
47
+     * @param \OCP\BackgroundJob\IJob|string $job
48
+     * @param mixed $argument
49
+     * @since 7.0.0
50
+     */
51
+    public function remove($job, $argument = null);
52 52
 
53
-	/**
54
-	 * check if a job is in the list
55
-	 *
56
-	 * @param \OCP\BackgroundJob\IJob|string $job
57
-	 * @param mixed $argument
58
-	 * @return bool
59
-	 * @since 7.0.0
60
-	 */
61
-	public function has($job, $argument);
53
+    /**
54
+     * check if a job is in the list
55
+     *
56
+     * @param \OCP\BackgroundJob\IJob|string $job
57
+     * @param mixed $argument
58
+     * @return bool
59
+     * @since 7.0.0
60
+     */
61
+    public function has($job, $argument);
62 62
 
63
-	/**
64
-	 * get all jobs in the list
65
-	 *
66
-	 * @return \OCP\BackgroundJob\IJob[]
67
-	 * @since 7.0.0
68
-	 * @deprecated 9.0.0 - This method is dangerous since it can cause load and
69
-	 * memory problems when creating too many instances.
70
-	 */
71
-	public function getAll();
63
+    /**
64
+     * get all jobs in the list
65
+     *
66
+     * @return \OCP\BackgroundJob\IJob[]
67
+     * @since 7.0.0
68
+     * @deprecated 9.0.0 - This method is dangerous since it can cause load and
69
+     * memory problems when creating too many instances.
70
+     */
71
+    public function getAll();
72 72
 
73
-	/**
74
-	 * get the next job in the list
75
-	 *
76
-	 * @return \OCP\BackgroundJob\IJob|null
77
-	 * @since 7.0.0
78
-	 */
79
-	public function getNext();
73
+    /**
74
+     * get the next job in the list
75
+     *
76
+     * @return \OCP\BackgroundJob\IJob|null
77
+     * @since 7.0.0
78
+     */
79
+    public function getNext();
80 80
 
81
-	/**
82
-	 * @param int $id
83
-	 * @return \OCP\BackgroundJob\IJob|null
84
-	 * @since 7.0.0
85
-	 */
86
-	public function getById($id);
81
+    /**
82
+     * @param int $id
83
+     * @return \OCP\BackgroundJob\IJob|null
84
+     * @since 7.0.0
85
+     */
86
+    public function getById($id);
87 87
 
88
-	/**
89
-	 * set the job that was last ran to the current time
90
-	 *
91
-	 * @param \OCP\BackgroundJob\IJob $job
92
-	 * @since 7.0.0
93
-	 */
94
-	public function setLastJob(IJob $job);
88
+    /**
89
+     * set the job that was last ran to the current time
90
+     *
91
+     * @param \OCP\BackgroundJob\IJob $job
92
+     * @since 7.0.0
93
+     */
94
+    public function setLastJob(IJob $job);
95 95
 
96
-	/**
97
-	 * Remove the reservation for a job
98
-	 *
99
-	 * @param IJob $job
100
-	 * @since 9.1.0
101
-	 */
102
-	public function unlockJob(IJob $job);
96
+    /**
97
+     * Remove the reservation for a job
98
+     *
99
+     * @param IJob $job
100
+     * @since 9.1.0
101
+     */
102
+    public function unlockJob(IJob $job);
103 103
 
104
-	/**
105
-	 * get the id of the last ran job
106
-	 *
107
-	 * @return int
108
-	 * @since 7.0.0
109
-	 * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
110
-	 *    only tells you which job finished last, but since we now allow multiple
111
-	 *    executors to run in parallel, it's not used to calculate the next job.
112
-	 */
113
-	public function getLastJob();
104
+    /**
105
+     * get the id of the last ran job
106
+     *
107
+     * @return int
108
+     * @since 7.0.0
109
+     * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
110
+     *    only tells you which job finished last, but since we now allow multiple
111
+     *    executors to run in parallel, it's not used to calculate the next job.
112
+     */
113
+    public function getLastJob();
114 114
 
115
-	/**
116
-	 * set the lastRun of $job to now
117
-	 *
118
-	 * @param IJob $job
119
-	 * @since 7.0.0
120
-	 */
121
-	public function setLastRun(IJob $job);
115
+    /**
116
+     * set the lastRun of $job to now
117
+     *
118
+     * @param IJob $job
119
+     * @since 7.0.0
120
+     */
121
+    public function setLastRun(IJob $job);
122 122
 
123
-	/**
124
-	 * set the run duration of $job
125
-	 *
126
-	 * @param IJob $job
127
-	 * @param $timeTaken
128
-	 * @since 12.0.0
129
-	 */
130
-	public function setExecutionTime(IJob $job, $timeTaken);
123
+    /**
124
+     * set the run duration of $job
125
+     *
126
+     * @param IJob $job
127
+     * @param $timeTaken
128
+     * @since 12.0.0
129
+     */
130
+    public function setExecutionTime(IJob $job, $timeTaken);
131 131
 }
Please login to merge, or discard this patch.
lib/private/Updater.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -431,7 +431,7 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -101,43 +101,43 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -55,563 +55,563 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/CoreBundle.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/GroupwareBundle.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
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
 	/**
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -23,22 +23,22 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/EnterpriseBundle.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,25 +23,25 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
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
 	/**
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/Bundle.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,36 +24,36 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/Command/Db/ConvertMysqlToMB4.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -34,59 +34,59 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/DB/MySqlTools.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -28,22 +28,22 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.