Completed
Pull Request — master (#7955)
by Morris
18:42
created
core/Command/Upgrade.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,6 @@
 block discarded – undo
43 43
 use Symfony\Component\Console\Helper\ProgressBar;
44 44
 use Symfony\Component\Console\Input\InputInterface;
45 45
 use Symfony\Component\Console\Output\OutputInterface;
46
-use Symfony\Component\Console\Input\InputOption;
47 46
 use Symfony\Component\EventDispatcher\GenericEvent;
48 47
 
49 48
 class Upgrade extends Command {
Please login to merge, or discard this patch.
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -48,251 +48,251 @@
 block discarded – undo
48 48
 
49 49
 class Upgrade extends Command {
50 50
 
51
-	const ERROR_SUCCESS = 0;
52
-	const ERROR_NOT_INSTALLED = 1;
53
-	const ERROR_MAINTENANCE_MODE = 2;
54
-	const ERROR_UP_TO_DATE = 0;
55
-	const ERROR_INVALID_ARGUMENTS = 4;
56
-	const ERROR_FAILURE = 5;
51
+    const ERROR_SUCCESS = 0;
52
+    const ERROR_NOT_INSTALLED = 1;
53
+    const ERROR_MAINTENANCE_MODE = 2;
54
+    const ERROR_UP_TO_DATE = 0;
55
+    const ERROR_INVALID_ARGUMENTS = 4;
56
+    const ERROR_FAILURE = 5;
57 57
 
58
-	/** @var IConfig */
59
-	private $config;
58
+    /** @var IConfig */
59
+    private $config;
60 60
 
61
-	/** @var ILogger */
62
-	private $logger;
61
+    /** @var ILogger */
62
+    private $logger;
63 63
 
64
-	/**
65
-	 * @param IConfig $config
66
-	 * @param ILogger $logger
67
-	 * @param Installer $installer
68
-	 */
69
-	public function __construct(IConfig $config, ILogger $logger, Installer $installer) {
70
-		parent::__construct();
71
-		$this->config = $config;
72
-		$this->logger = $logger;
73
-		$this->installer = $installer;
74
-	}
64
+    /**
65
+     * @param IConfig $config
66
+     * @param ILogger $logger
67
+     * @param Installer $installer
68
+     */
69
+    public function __construct(IConfig $config, ILogger $logger, Installer $installer) {
70
+        parent::__construct();
71
+        $this->config = $config;
72
+        $this->logger = $logger;
73
+        $this->installer = $installer;
74
+    }
75 75
 
76
-	protected function configure() {
77
-		$this
78
-			->setName('upgrade')
79
-			->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.');
80
-	}
76
+    protected function configure() {
77
+        $this
78
+            ->setName('upgrade')
79
+            ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.');
80
+    }
81 81
 
82
-	/**
83
-	 * Execute the upgrade command
84
-	 *
85
-	 * @param InputInterface $input input interface
86
-	 * @param OutputInterface $output output interface
87
-	 */
88
-	protected function execute(InputInterface $input, OutputInterface $output) {
82
+    /**
83
+     * Execute the upgrade command
84
+     *
85
+     * @param InputInterface $input input interface
86
+     * @param OutputInterface $output output interface
87
+     */
88
+    protected function execute(InputInterface $input, OutputInterface $output) {
89 89
 
90
-		if(\OC::checkUpgrade(false)) {
91
-			if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
92
-				// Prepend each line with a little timestamp
93
-				$timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter());
94
-				$output->setFormatter($timestampFormatter);
95
-			}
90
+        if(\OC::checkUpgrade(false)) {
91
+            if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
92
+                // Prepend each line with a little timestamp
93
+                $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter());
94
+                $output->setFormatter($timestampFormatter);
95
+            }
96 96
 
97
-			$self = $this;
98
-			$updater = new Updater(
99
-					$this->config,
100
-					\OC::$server->getIntegrityCodeChecker(),
101
-					$this->logger,
102
-					$this->installer
103
-			);
97
+            $self = $this;
98
+            $updater = new Updater(
99
+                    $this->config,
100
+                    \OC::$server->getIntegrityCodeChecker(),
101
+                    $this->logger,
102
+                    $this->installer
103
+            );
104 104
 
105
-			$dispatcher = \OC::$server->getEventDispatcher();
106
-			$progress = new ProgressBar($output);
107
-			$progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%");
108
-			$listener = function($event) use ($progress, $output) {
109
-				if ($event instanceof GenericEvent) {
110
-					$message = $event->getSubject();
111
-					if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
112
-						$output->writeln(' Checking table ' . $message);
113
-					} else {
114
-						if (strlen($message) > 60) {
115
-							$message = substr($message, 0, 57) . '...';
116
-						}
117
-						$progress->setMessage($message);
118
-						if ($event[0] === 1) {
119
-							$output->writeln('');
120
-							$progress->start($event[1]);
121
-						}
122
-						$progress->setProgress($event[0]);
123
-						if ($event[0] === $event[1]) {
124
-							$progress->setMessage('Done');
125
-							$progress->finish();
126
-							$output->writeln('');
127
-						}
128
-					}
129
-				}
130
-			};
131
-			$repairListener = function($event) use ($progress, $output) {
132
-				if (!$event instanceof GenericEvent) {
133
-					return;
134
-				}
135
-				switch ($event->getSubject()) {
136
-					case '\OC\Repair::startProgress':
137
-						$progress->setMessage('Starting ...');
138
-						$output->writeln($event->getArgument(1));
139
-						$output->writeln('');
140
-						$progress->start($event->getArgument(0));
141
-						break;
142
-					case '\OC\Repair::advance':
143
-						$desc = $event->getArgument(1);
144
-						if (!empty($desc)) {
145
-							$progress->setMessage($desc);
146
-						}
147
-						$progress->advance($event->getArgument(0));
105
+            $dispatcher = \OC::$server->getEventDispatcher();
106
+            $progress = new ProgressBar($output);
107
+            $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%");
108
+            $listener = function($event) use ($progress, $output) {
109
+                if ($event instanceof GenericEvent) {
110
+                    $message = $event->getSubject();
111
+                    if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
112
+                        $output->writeln(' Checking table ' . $message);
113
+                    } else {
114
+                        if (strlen($message) > 60) {
115
+                            $message = substr($message, 0, 57) . '...';
116
+                        }
117
+                        $progress->setMessage($message);
118
+                        if ($event[0] === 1) {
119
+                            $output->writeln('');
120
+                            $progress->start($event[1]);
121
+                        }
122
+                        $progress->setProgress($event[0]);
123
+                        if ($event[0] === $event[1]) {
124
+                            $progress->setMessage('Done');
125
+                            $progress->finish();
126
+                            $output->writeln('');
127
+                        }
128
+                    }
129
+                }
130
+            };
131
+            $repairListener = function($event) use ($progress, $output) {
132
+                if (!$event instanceof GenericEvent) {
133
+                    return;
134
+                }
135
+                switch ($event->getSubject()) {
136
+                    case '\OC\Repair::startProgress':
137
+                        $progress->setMessage('Starting ...');
138
+                        $output->writeln($event->getArgument(1));
139
+                        $output->writeln('');
140
+                        $progress->start($event->getArgument(0));
141
+                        break;
142
+                    case '\OC\Repair::advance':
143
+                        $desc = $event->getArgument(1);
144
+                        if (!empty($desc)) {
145
+                            $progress->setMessage($desc);
146
+                        }
147
+                        $progress->advance($event->getArgument(0));
148 148
 
149
-						break;
150
-					case '\OC\Repair::finishProgress':
151
-						$progress->setMessage('Done');
152
-						$progress->finish();
153
-						$output->writeln('');
154
-						break;
155
-					case '\OC\Repair::step':
156
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
157
-							$output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>');
158
-						}
159
-						break;
160
-					case '\OC\Repair::info':
161
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
162
-							$output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>');
163
-						}
164
-						break;
165
-					case '\OC\Repair::warning':
166
-						$output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>');
167
-						break;
168
-					case '\OC\Repair::error':
169
-						$output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>');
170
-						break;
171
-				}
172
-			};
149
+                        break;
150
+                    case '\OC\Repair::finishProgress':
151
+                        $progress->setMessage('Done');
152
+                        $progress->finish();
153
+                        $output->writeln('');
154
+                        break;
155
+                    case '\OC\Repair::step':
156
+                        if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
157
+                            $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>');
158
+                        }
159
+                        break;
160
+                    case '\OC\Repair::info':
161
+                        if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
162
+                            $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>');
163
+                        }
164
+                        break;
165
+                    case '\OC\Repair::warning':
166
+                        $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>');
167
+                        break;
168
+                    case '\OC\Repair::error':
169
+                        $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>');
170
+                        break;
171
+                }
172
+            };
173 173
 
174
-			$dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener);
175
-			$dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener);
176
-			$dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
177
-			$dispatcher->addListener('\OC\Repair::advance', $repairListener);
178
-			$dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
179
-			$dispatcher->addListener('\OC\Repair::step', $repairListener);
180
-			$dispatcher->addListener('\OC\Repair::info', $repairListener);
181
-			$dispatcher->addListener('\OC\Repair::warning', $repairListener);
182
-			$dispatcher->addListener('\OC\Repair::error', $repairListener);
174
+            $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener);
175
+            $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener);
176
+            $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
177
+            $dispatcher->addListener('\OC\Repair::advance', $repairListener);
178
+            $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
179
+            $dispatcher->addListener('\OC\Repair::step', $repairListener);
180
+            $dispatcher->addListener('\OC\Repair::info', $repairListener);
181
+            $dispatcher->addListener('\OC\Repair::warning', $repairListener);
182
+            $dispatcher->addListener('\OC\Repair::error', $repairListener);
183 183
 			
184 184
 
185
-			$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
186
-				$output->writeln('<info>Turned on maintenance mode</info>');
187
-			});
188
-			$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) {
189
-				$output->writeln('<info>Turned off maintenance mode</info>');
190
-			});
191
-			$updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
192
-				$output->writeln('<info>Maintenance mode is kept active</info>');
193
-			});
194
-			$updater->listen('\OC\Updater', 'updateEnd',
195
-				function ($success) use($output, $self) {
196
-					if ($success) {
197
-						$message = "<info>Update successful</info>";
198
-					} else {
199
-						$message = "<error>Update failed</error>";
200
-					}
201
-					$output->writeln($message);
202
-				});
203
-			$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) {
204
-				$output->writeln('<info>Updating database schema</info>');
205
-			});
206
-			$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
207
-				$output->writeln('<info>Updated database</info>');
208
-			});
209
-			$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) {
210
-				$output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>');
211
-			});
212
-			$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
213
-				$output->writeln('<info>Checked database schema update</info>');
214
-			});
215
-			$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) {
216
-				$output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>');
217
-			});
218
-			$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) {
219
-				$output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>');
220
-			});
221
-			$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) {
222
-				$output->writeln('<info>Update app ' . $app . ' from appstore</info>');
223
-			});
224
-			$updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) {
225
-				$output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>');
226
-			});
227
-			$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) {
228
-				$output->writeln('<info>Checking updates of apps</info>');
229
-			});
230
-			$updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) {
231
-				$output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>");
232
-			});
233
-			$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) {
234
-				$output->writeln('<info>Checked database schema update for apps</info>');
235
-			});
236
-			$updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) {
237
-				$output->writeln("<info>Updating <$app> ...</info>");
238
-			});
239
-			$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) {
240
-				$output->writeln("<info>Updated <$app> to $version</info>");
241
-			});
242
-			$updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
243
-				$output->writeln("<error>$message</error>");
244
-			});
245
-			$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) {
246
-				$output->writeln("<info>Set log level to debug</info>");
247
-			});
248
-			$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) {
249
-				$output->writeln("<info>Reset log level</info>");
250
-			});
251
-			$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) {
252
-				$output->writeln("<info>Starting code integrity check...</info>");
253
-			});
254
-			$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) {
255
-				$output->writeln("<info>Finished code integrity check</info>");
256
-			});
185
+            $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
186
+                $output->writeln('<info>Turned on maintenance mode</info>');
187
+            });
188
+            $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) {
189
+                $output->writeln('<info>Turned off maintenance mode</info>');
190
+            });
191
+            $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
192
+                $output->writeln('<info>Maintenance mode is kept active</info>');
193
+            });
194
+            $updater->listen('\OC\Updater', 'updateEnd',
195
+                function ($success) use($output, $self) {
196
+                    if ($success) {
197
+                        $message = "<info>Update successful</info>";
198
+                    } else {
199
+                        $message = "<error>Update failed</error>";
200
+                    }
201
+                    $output->writeln($message);
202
+                });
203
+            $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) {
204
+                $output->writeln('<info>Updating database schema</info>');
205
+            });
206
+            $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
207
+                $output->writeln('<info>Updated database</info>');
208
+            });
209
+            $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) {
210
+                $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>');
211
+            });
212
+            $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
213
+                $output->writeln('<info>Checked database schema update</info>');
214
+            });
215
+            $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) {
216
+                $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>');
217
+            });
218
+            $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) {
219
+                $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>');
220
+            });
221
+            $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) {
222
+                $output->writeln('<info>Update app ' . $app . ' from appstore</info>');
223
+            });
224
+            $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) {
225
+                $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>');
226
+            });
227
+            $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) {
228
+                $output->writeln('<info>Checking updates of apps</info>');
229
+            });
230
+            $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) {
231
+                $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>");
232
+            });
233
+            $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) {
234
+                $output->writeln('<info>Checked database schema update for apps</info>');
235
+            });
236
+            $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) {
237
+                $output->writeln("<info>Updating <$app> ...</info>");
238
+            });
239
+            $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) {
240
+                $output->writeln("<info>Updated <$app> to $version</info>");
241
+            });
242
+            $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
243
+                $output->writeln("<error>$message</error>");
244
+            });
245
+            $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) {
246
+                $output->writeln("<info>Set log level to debug</info>");
247
+            });
248
+            $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) {
249
+                $output->writeln("<info>Reset log level</info>");
250
+            });
251
+            $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) {
252
+                $output->writeln("<info>Starting code integrity check...</info>");
253
+            });
254
+            $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) {
255
+                $output->writeln("<info>Finished code integrity check</info>");
256
+            });
257 257
 
258
-			$success = $updater->upgrade();
258
+            $success = $updater->upgrade();
259 259
 
260
-			$this->postUpgradeCheck($input, $output);
260
+            $this->postUpgradeCheck($input, $output);
261 261
 
262
-			if(!$success) {
263
-				return self::ERROR_FAILURE;
264
-			}
262
+            if(!$success) {
263
+                return self::ERROR_FAILURE;
264
+            }
265 265
 
266
-			return self::ERROR_SUCCESS;
267
-		} else if($this->config->getSystemValue('maintenance', false)) {
268
-			//Possible scenario: Nextcloud core is updated but an app failed
269
-			$output->writeln('<warning>Nextcloud is in maintenance mode</warning>');
270
-			$output->write('<comment>Maybe an upgrade is already in process. Please check the '
271
-				. 'logfile (data/nextcloud.log). If you want to re-run the '
272
-				. 'upgrade procedure, remove the "maintenance mode" from '
273
-				. 'config.php and call this script again.</comment>'
274
-				, true);
275
-			return self::ERROR_MAINTENANCE_MODE;
276
-		} else {
277
-			$output->writeln('<info>Nextcloud is already latest version</info>');
278
-			return self::ERROR_UP_TO_DATE;
279
-		}
280
-	}
266
+            return self::ERROR_SUCCESS;
267
+        } else if($this->config->getSystemValue('maintenance', false)) {
268
+            //Possible scenario: Nextcloud core is updated but an app failed
269
+            $output->writeln('<warning>Nextcloud is in maintenance mode</warning>');
270
+            $output->write('<comment>Maybe an upgrade is already in process. Please check the '
271
+                . 'logfile (data/nextcloud.log). If you want to re-run the '
272
+                . 'upgrade procedure, remove the "maintenance mode" from '
273
+                . 'config.php and call this script again.</comment>'
274
+                , true);
275
+            return self::ERROR_MAINTENANCE_MODE;
276
+        } else {
277
+            $output->writeln('<info>Nextcloud is already latest version</info>');
278
+            return self::ERROR_UP_TO_DATE;
279
+        }
280
+    }
281 281
 
282
-	/**
283
-	 * Perform a post upgrade check (specific to the command line tool)
284
-	 *
285
-	 * @param InputInterface $input input interface
286
-	 * @param OutputInterface $output output interface
287
-	 */
288
-	protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
289
-		$trustedDomains = $this->config->getSystemValue('trusted_domains', array());
290
-		if (empty($trustedDomains)) {
291
-			$output->write(
292
-				'<warning>The setting "trusted_domains" could not be ' .
293
-				'set automatically by the upgrade script, ' .
294
-				'please set it manually</warning>'
295
-			);
296
-		}
297
-	}
282
+    /**
283
+     * Perform a post upgrade check (specific to the command line tool)
284
+     *
285
+     * @param InputInterface $input input interface
286
+     * @param OutputInterface $output output interface
287
+     */
288
+    protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
289
+        $trustedDomains = $this->config->getSystemValue('trusted_domains', array());
290
+        if (empty($trustedDomains)) {
291
+            $output->write(
292
+                '<warning>The setting "trusted_domains" could not be ' .
293
+                'set automatically by the upgrade script, ' .
294
+                'please set it manually</warning>'
295
+            );
296
+        }
297
+    }
298 298
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	protected function execute(InputInterface $input, OutputInterface $output) {
89 89
 
90
-		if(\OC::checkUpgrade(false)) {
90
+		if (\OC::checkUpgrade(false)) {
91 91
 			if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
92 92
 				// Prepend each line with a little timestamp
93 93
 				$timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter());
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 				if ($event instanceof GenericEvent) {
110 110
 					$message = $event->getSubject();
111 111
 					if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
112
-						$output->writeln(' Checking table ' . $message);
112
+						$output->writeln(' Checking table '.$message);
113 113
 					} else {
114 114
 						if (strlen($message) > 60) {
115
-							$message = substr($message, 0, 57) . '...';
115
+							$message = substr($message, 0, 57).'...';
116 116
 						}
117 117
 						$progress->setMessage($message);
118 118
 						if ($event[0] === 1) {
@@ -153,20 +153,20 @@  discard block
 block discarded – undo
153 153
 						$output->writeln('');
154 154
 						break;
155 155
 					case '\OC\Repair::step':
156
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
157
-							$output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>');
156
+						if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
157
+							$output->writeln('<info>Repair step: '.$event->getArgument(0).'</info>');
158 158
 						}
159 159
 						break;
160 160
 					case '\OC\Repair::info':
161
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
162
-							$output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>');
161
+						if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
162
+							$output->writeln('<info>Repair info: '.$event->getArgument(0).'</info>');
163 163
 						}
164 164
 						break;
165 165
 					case '\OC\Repair::warning':
166
-						$output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>');
166
+						$output->writeln('<error>Repair warning: '.$event->getArgument(0).'</error>');
167 167
 						break;
168 168
 					case '\OC\Repair::error':
169
-						$output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>');
169
+						$output->writeln('<error>Repair error: '.$event->getArgument(0).'</error>');
170 170
 						break;
171 171
 				}
172 172
 			};
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 			$dispatcher->addListener('\OC\Repair::error', $repairListener);
183 183
 			
184 184
 
185
-			$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
185
+			$updater->listen('\OC\Updater', 'maintenanceEnabled', function() use($output) {
186 186
 				$output->writeln('<info>Turned on maintenance mode</info>');
187 187
 			});
188
-			$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) {
188
+			$updater->listen('\OC\Updater', 'maintenanceDisabled', function() use($output) {
189 189
 				$output->writeln('<info>Turned off maintenance mode</info>');
190 190
 			});
191
-			$updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
191
+			$updater->listen('\OC\Updater', 'maintenanceActive', function() use($output) {
192 192
 				$output->writeln('<info>Maintenance mode is kept active</info>');
193 193
 			});
194 194
 			$updater->listen('\OC\Updater', 'updateEnd',
195
-				function ($success) use($output, $self) {
195
+				function($success) use($output, $self) {
196 196
 					if ($success) {
197 197
 						$message = "<info>Update successful</info>";
198 198
 					} else {
@@ -200,58 +200,58 @@  discard block
 block discarded – undo
200 200
 					}
201 201
 					$output->writeln($message);
202 202
 				});
203
-			$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) {
203
+			$updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use($output) {
204 204
 				$output->writeln('<info>Updating database schema</info>');
205 205
 			});
206
-			$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
206
+			$updater->listen('\OC\Updater', 'dbUpgrade', function() use($output) {
207 207
 				$output->writeln('<info>Updated database</info>');
208 208
 			});
209
-			$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) {
209
+			$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($output) {
210 210
 				$output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>');
211 211
 			});
212
-			$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
212
+			$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($output) {
213 213
 				$output->writeln('<info>Checked database schema update</info>');
214 214
 			});
215
-			$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) {
216
-				$output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>');
215
+			$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($output) {
216
+				$output->writeln('<comment>Disabled incompatible app: '.$app.'</comment>');
217 217
 			});
218
-			$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) {
219
-				$output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>');
218
+			$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($output) {
219
+				$output->writeln('<info>Checking for update of app '.$app.' in appstore</info>');
220 220
 			});
221
-			$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) {
222
-				$output->writeln('<info>Update app ' . $app . ' from appstore</info>');
221
+			$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($output) {
222
+				$output->writeln('<info>Update app '.$app.' from appstore</info>');
223 223
 			});
224
-			$updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) {
225
-				$output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>');
224
+			$updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($output) {
225
+				$output->writeln('<info>Checked for update of app "'.$app.'" in appstore </info>');
226 226
 			});
227
-			$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) {
227
+			$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($output) {
228 228
 				$output->writeln('<info>Checking updates of apps</info>');
229 229
 			});
230
-			$updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) {
230
+			$updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($output) {
231 231
 				$output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>");
232 232
 			});
233
-			$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) {
233
+			$updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($output) {
234 234
 				$output->writeln('<info>Checked database schema update for apps</info>');
235 235
 			});
236
-			$updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) {
236
+			$updater->listen('\OC\Updater', 'appUpgradeStarted', function($app, $version) use ($output) {
237 237
 				$output->writeln("<info>Updating <$app> ...</info>");
238 238
 			});
239
-			$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) {
239
+			$updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($output) {
240 240
 				$output->writeln("<info>Updated <$app> to $version</info>");
241 241
 			});
242
-			$updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
242
+			$updater->listen('\OC\Updater', 'failure', function($message) use($output, $self) {
243 243
 				$output->writeln("<error>$message</error>");
244 244
 			});
245
-			$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) {
245
+			$updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use($output) {
246 246
 				$output->writeln("<info>Set log level to debug</info>");
247 247
 			});
248
-			$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) {
248
+			$updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($output) {
249 249
 				$output->writeln("<info>Reset log level</info>");
250 250
 			});
251
-			$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) {
251
+			$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($output) {
252 252
 				$output->writeln("<info>Starting code integrity check...</info>");
253 253
 			});
254
-			$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) {
254
+			$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($output) {
255 255
 				$output->writeln("<info>Finished code integrity check</info>");
256 256
 			});
257 257
 
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 
260 260
 			$this->postUpgradeCheck($input, $output);
261 261
 
262
-			if(!$success) {
262
+			if (!$success) {
263 263
 				return self::ERROR_FAILURE;
264 264
 			}
265 265
 
266 266
 			return self::ERROR_SUCCESS;
267
-		} else if($this->config->getSystemValue('maintenance', false)) {
267
+		} else if ($this->config->getSystemValue('maintenance', false)) {
268 268
 			//Possible scenario: Nextcloud core is updated but an app failed
269 269
 			$output->writeln('<warning>Nextcloud is in maintenance mode</warning>');
270 270
 			$output->write('<comment>Maybe an upgrade is already in process. Please check the '
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 		$trustedDomains = $this->config->getSystemValue('trusted_domains', array());
290 290
 		if (empty($trustedDomains)) {
291 291
 			$output->write(
292
-				'<warning>The setting "trusted_domains" could not be ' .
293
-				'set automatically by the upgrade script, ' .
292
+				'<warning>The setting "trusted_domains" could not be '.
293
+				'set automatically by the upgrade script, '.
294 294
 				'please set it manually</warning>'
295 295
 			);
296 296
 		}
Please login to merge, or discard this patch.
core/ajax/update.php 2 patches
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 use Symfony\Component\EventDispatcher\GenericEvent;
32 32
 
33 33
 if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
34
-	@set_time_limit(0);
34
+    @set_time_limit(0);
35 35
 }
36 36
 
37 37
 require_once '../../lib/base.php';
@@ -45,184 +45,184 @@  discard block
 block discarded – undo
45 45
 $eventSource->send('success', (string)$l->t('Preparing update'));
46 46
 
47 47
 class FeedBackHandler {
48
-	/** @var integer */
49
-	private $progressStateMax = 100;
50
-	/** @var integer */
51
-	private $progressStateStep = 0;
52
-	/** @var string */
53
-	private $currentStep;
54
-	/** @var \OCP\IEventSource */
55
-	private $eventSource;
56
-	/** @var \OCP\IL10N */
57
-	private $l10n;
58
-
59
-	public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) {
60
-		$this->eventSource = $eventSource;
61
-		$this->l10n = $l10n;
62
-	}
63
-
64
-	public function handleRepairFeedback($event) {
65
-		if (!$event instanceof GenericEvent) {
66
-			return;
67
-		}
68
-
69
-		switch ($event->getSubject()) {
70
-			case '\OC\Repair::startProgress':
71
-				$this->progressStateMax = $event->getArgument(0);
72
-				$this->progressStateStep = 0;
73
-				$this->currentStep = $event->getArgument(1);
74
-				break;
75
-			case '\OC\Repair::advance':
76
-				$this->progressStateStep += $event->getArgument(0);
77
-				$desc = $event->getArgument(1);
78
-				if (empty($desc)) {
79
-					$desc = $this->currentStep;
80
-				}
81
-				$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
82
-				break;
83
-			case '\OC\Repair::finishProgress':
84
-				$this->progressStateMax = $this->progressStateStep;
85
-				$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
86
-				break;
87
-			case '\OC\Repair::step':
88
-				break;
89
-			case '\OC\Repair::info':
90
-				break;
91
-			case '\OC\Repair::warning':
92
-				$this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0));
93
-				break;
94
-			case '\OC\Repair::error':
95
-				$this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0));
96
-				break;
97
-		}
98
-	}
48
+    /** @var integer */
49
+    private $progressStateMax = 100;
50
+    /** @var integer */
51
+    private $progressStateStep = 0;
52
+    /** @var string */
53
+    private $currentStep;
54
+    /** @var \OCP\IEventSource */
55
+    private $eventSource;
56
+    /** @var \OCP\IL10N */
57
+    private $l10n;
58
+
59
+    public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) {
60
+        $this->eventSource = $eventSource;
61
+        $this->l10n = $l10n;
62
+    }
63
+
64
+    public function handleRepairFeedback($event) {
65
+        if (!$event instanceof GenericEvent) {
66
+            return;
67
+        }
68
+
69
+        switch ($event->getSubject()) {
70
+            case '\OC\Repair::startProgress':
71
+                $this->progressStateMax = $event->getArgument(0);
72
+                $this->progressStateStep = 0;
73
+                $this->currentStep = $event->getArgument(1);
74
+                break;
75
+            case '\OC\Repair::advance':
76
+                $this->progressStateStep += $event->getArgument(0);
77
+                $desc = $event->getArgument(1);
78
+                if (empty($desc)) {
79
+                    $desc = $this->currentStep;
80
+                }
81
+                $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
82
+                break;
83
+            case '\OC\Repair::finishProgress':
84
+                $this->progressStateMax = $this->progressStateStep;
85
+                $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
86
+                break;
87
+            case '\OC\Repair::step':
88
+                break;
89
+            case '\OC\Repair::info':
90
+                break;
91
+            case '\OC\Repair::warning':
92
+                $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0));
93
+                break;
94
+            case '\OC\Repair::error':
95
+                $this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0));
96
+                break;
97
+        }
98
+    }
99 99
 }
100 100
 
101 101
 if (OC::checkUpgrade(false)) {
102 102
 
103
-	$config = \OC::$server->getSystemConfig();
104
-	if ($config->getValue('upgrade.disable-web', false)) {
105
-		$eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
106
-		$eventSource->close();
107
-		exit();
108
-	}
109
-
110
-	// if a user is currently logged in, their session must be ignored to
111
-	// avoid side effects
112
-	\OC_User::setIncognitoMode(true);
113
-
114
-	$logger = \OC::$server->getLogger();
115
-	$config = \OC::$server->getConfig();
116
-	$updater = new \OC\Updater(
117
-			$config,
118
-			\OC::$server->getIntegrityCodeChecker(),
119
-			$logger,
120
-			\OC::$server->query(\OC\Installer::class)
121
-	);
122
-	$incompatibleApps = [];
123
-
124
-	$dispatcher = \OC::$server->getEventDispatcher();
125
-	$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) {
126
-		if ($event instanceof GenericEvent) {
127
-			$eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
128
-		}
129
-	});
130
-	$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) {
131
-		if ($event instanceof GenericEvent) {
132
-			$eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
133
-		}
134
-	});
135
-	$feedBack = new FeedBackHandler($eventSource, $l);
136
-	$dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']);
137
-	$dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']);
138
-	$dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']);
139
-	$dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']);
140
-	$dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']);
141
-	$dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']);
142
-	$dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']);
143
-
144
-	$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
145
-		$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
146
-	});
147
-	$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
148
-		$eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
149
-	});
150
-	$updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
151
-		$eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
152
-	});
153
-	$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) {
154
-		$eventSource->send('success', (string)$l->t('Updating database schema'));
155
-	});
156
-	$updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
157
-		$eventSource->send('success', (string)$l->t('Updated database'));
158
-	});
159
-	$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) {
160
-		$eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)'));
161
-	});
162
-	$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
163
-		$eventSource->send('success', (string)$l->t('Checked database schema update'));
164
-	});
165
-	$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) {
166
-		$eventSource->send('success', (string)$l->t('Checking updates of apps'));
167
-	});
168
-	$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) {
169
-		$eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app]));
170
-	});
171
-	$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) {
172
-		$eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app]));
173
-	});
174
-	$updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) {
175
-		$eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app]));
176
-	});
177
-	$updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) {
178
-		$eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app]));
179
-	});
180
-	$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
181
-		$eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
182
-	});
183
-	$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
184
-		$eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
185
-	});
186
-	$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
187
-		$incompatibleApps[]= $app;
188
-	});
189
-	$updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) {
190
-		$eventSource->send('failure', $message);
191
-		$eventSource->close();
192
-		$config->setSystemValue('maintenance', false);
193
-	});
194
-	$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
195
-		$eventSource->send('success', (string)$l->t('Set log level to debug'));
196
-	});
197
-	$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
198
-		$eventSource->send('success', (string)$l->t('Reset log level'));
199
-	});
200
-	$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) {
201
-		$eventSource->send('success', (string)$l->t('Starting code integrity check'));
202
-	});
203
-	$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) {
204
-		$eventSource->send('success', (string)$l->t('Finished code integrity check'));
205
-	});
206
-
207
-	try {
208
-		$updater->upgrade();
209
-	} catch (\Exception $e) {
210
-		$eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
211
-		$eventSource->close();
212
-		exit();
213
-	}
214
-
215
-	$disabledApps = [];
216
-	foreach ($incompatibleApps as $app) {
217
-		$disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]);
218
-	}
219
-
220
-	if (!empty($disabledApps)) {
221
-		$eventSource->send('notice',
222
-			(string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)]));
223
-	}
103
+    $config = \OC::$server->getSystemConfig();
104
+    if ($config->getValue('upgrade.disable-web', false)) {
105
+        $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
106
+        $eventSource->close();
107
+        exit();
108
+    }
109
+
110
+    // if a user is currently logged in, their session must be ignored to
111
+    // avoid side effects
112
+    \OC_User::setIncognitoMode(true);
113
+
114
+    $logger = \OC::$server->getLogger();
115
+    $config = \OC::$server->getConfig();
116
+    $updater = new \OC\Updater(
117
+            $config,
118
+            \OC::$server->getIntegrityCodeChecker(),
119
+            $logger,
120
+            \OC::$server->query(\OC\Installer::class)
121
+    );
122
+    $incompatibleApps = [];
123
+
124
+    $dispatcher = \OC::$server->getEventDispatcher();
125
+    $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) {
126
+        if ($event instanceof GenericEvent) {
127
+            $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
128
+        }
129
+    });
130
+    $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) {
131
+        if ($event instanceof GenericEvent) {
132
+            $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
133
+        }
134
+    });
135
+    $feedBack = new FeedBackHandler($eventSource, $l);
136
+    $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']);
137
+    $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']);
138
+    $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']);
139
+    $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']);
140
+    $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']);
141
+    $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']);
142
+    $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']);
143
+
144
+    $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
145
+        $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
146
+    });
147
+    $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
148
+        $eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
149
+    });
150
+    $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
151
+        $eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
152
+    });
153
+    $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) {
154
+        $eventSource->send('success', (string)$l->t('Updating database schema'));
155
+    });
156
+    $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
157
+        $eventSource->send('success', (string)$l->t('Updated database'));
158
+    });
159
+    $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) {
160
+        $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)'));
161
+    });
162
+    $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
163
+        $eventSource->send('success', (string)$l->t('Checked database schema update'));
164
+    });
165
+    $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) {
166
+        $eventSource->send('success', (string)$l->t('Checking updates of apps'));
167
+    });
168
+    $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) {
169
+        $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app]));
170
+    });
171
+    $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) {
172
+        $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app]));
173
+    });
174
+    $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) {
175
+        $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app]));
176
+    });
177
+    $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) {
178
+        $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app]));
179
+    });
180
+    $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
181
+        $eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
182
+    });
183
+    $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
184
+        $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
185
+    });
186
+    $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
187
+        $incompatibleApps[]= $app;
188
+    });
189
+    $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) {
190
+        $eventSource->send('failure', $message);
191
+        $eventSource->close();
192
+        $config->setSystemValue('maintenance', false);
193
+    });
194
+    $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
195
+        $eventSource->send('success', (string)$l->t('Set log level to debug'));
196
+    });
197
+    $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
198
+        $eventSource->send('success', (string)$l->t('Reset log level'));
199
+    });
200
+    $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) {
201
+        $eventSource->send('success', (string)$l->t('Starting code integrity check'));
202
+    });
203
+    $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) {
204
+        $eventSource->send('success', (string)$l->t('Finished code integrity check'));
205
+    });
206
+
207
+    try {
208
+        $updater->upgrade();
209
+    } catch (\Exception $e) {
210
+        $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
211
+        $eventSource->close();
212
+        exit();
213
+    }
214
+
215
+    $disabledApps = [];
216
+    foreach ($incompatibleApps as $app) {
217
+        $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]);
218
+    }
219
+
220
+    if (!empty($disabledApps)) {
221
+        $eventSource->send('notice',
222
+            (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)]));
223
+    }
224 224
 } else {
225
-	$eventSource->send('notice', (string)$l->t('Already up to date'));
225
+    $eventSource->send('notice', (string)$l->t('Already up to date'));
226 226
 }
227 227
 
228 228
 $eventSource->send('done', '');
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 // need to send an initial message to force-init the event source,
43 43
 // which will then trigger its own CSRF check and produces its own CSRF error
44 44
 // message
45
-$eventSource->send('success', (string)$l->t('Preparing update'));
45
+$eventSource->send('success', (string) $l->t('Preparing update'));
46 46
 
47 47
 class FeedBackHandler {
48 48
 	/** @var integer */
@@ -78,21 +78,21 @@  discard block
 block discarded – undo
78 78
 				if (empty($desc)) {
79 79
 					$desc = $this->currentStep;
80 80
 				}
81
-				$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
81
+				$this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
82 82
 				break;
83 83
 			case '\OC\Repair::finishProgress':
84 84
 				$this->progressStateMax = $this->progressStateStep;
85
-				$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
85
+				$this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
86 86
 				break;
87 87
 			case '\OC\Repair::step':
88 88
 				break;
89 89
 			case '\OC\Repair::info':
90 90
 				break;
91 91
 			case '\OC\Repair::warning':
92
-				$this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0));
92
+				$this->eventSource->send('notice', (string) $this->l10n->t('Repair warning: ').$event->getArgument(0));
93 93
 				break;
94 94
 			case '\OC\Repair::error':
95
-				$this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0));
95
+				$this->eventSource->send('notice', (string) $this->l10n->t('Repair error: ').$event->getArgument(0));
96 96
 				break;
97 97
 		}
98 98
 	}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
 	$config = \OC::$server->getSystemConfig();
104 104
 	if ($config->getValue('upgrade.disable-web', false)) {
105
-		$eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
105
+		$eventSource->send('failure', (string) $l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
106 106
 		$eventSource->close();
107 107
 		exit();
108 108
 	}
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	$dispatcher = \OC::$server->getEventDispatcher();
125 125
 	$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) {
126 126
 		if ($event instanceof GenericEvent) {
127
-			$eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
127
+			$eventSource->send('success', (string) $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
128 128
 		}
129 129
 	});
130 130
 	$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) {
131 131
 		if ($event instanceof GenericEvent) {
132
-			$eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
132
+			$eventSource->send('success', (string) $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
133 133
 		}
134 134
 	});
135 135
 	$feedBack = new FeedBackHandler($eventSource, $l);
@@ -141,73 +141,73 @@  discard block
 block discarded – undo
141 141
 	$dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']);
142 142
 	$dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']);
143 143
 
144
-	$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
145
-		$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
144
+	$updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($eventSource, $l) {
145
+		$eventSource->send('success', (string) $l->t('Turned on maintenance mode'));
146 146
 	});
147
-	$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
148
-		$eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
147
+	$updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($eventSource, $l) {
148
+		$eventSource->send('success', (string) $l->t('Turned off maintenance mode'));
149 149
 	});
150
-	$updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
151
-		$eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
150
+	$updater->listen('\OC\Updater', 'maintenanceActive', function() use ($eventSource, $l) {
151
+		$eventSource->send('success', (string) $l->t('Maintenance mode is kept active'));
152 152
 	});
153
-	$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) {
154
-		$eventSource->send('success', (string)$l->t('Updating database schema'));
153
+	$updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use($eventSource, $l) {
154
+		$eventSource->send('success', (string) $l->t('Updating database schema'));
155 155
 	});
156
-	$updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
157
-		$eventSource->send('success', (string)$l->t('Updated database'));
156
+	$updater->listen('\OC\Updater', 'dbUpgrade', function() use ($eventSource, $l) {
157
+		$eventSource->send('success', (string) $l->t('Updated database'));
158 158
 	});
159
-	$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) {
160
-		$eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)'));
159
+	$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($eventSource, $l) {
160
+		$eventSource->send('success', (string) $l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)'));
161 161
 	});
162
-	$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
163
-		$eventSource->send('success', (string)$l->t('Checked database schema update'));
162
+	$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use ($eventSource, $l) {
163
+		$eventSource->send('success', (string) $l->t('Checked database schema update'));
164 164
 	});
165
-	$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) {
166
-		$eventSource->send('success', (string)$l->t('Checking updates of apps'));
165
+	$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($eventSource, $l) {
166
+		$eventSource->send('success', (string) $l->t('Checking updates of apps'));
167 167
 	});
168
-	$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) {
169
-		$eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app]));
168
+	$updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($eventSource, $l) {
169
+		$eventSource->send('success', (string) $l->t('Checking for update of app "%s" in appstore', [$app]));
170 170
 	});
171
-	$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) {
172
-		$eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app]));
171
+	$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($eventSource, $l) {
172
+		$eventSource->send('success', (string) $l->t('Update app "%s" from appstore', [$app]));
173 173
 	});
174
-	$updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) {
175
-		$eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app]));
174
+	$updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($eventSource, $l) {
175
+		$eventSource->send('success', (string) $l->t('Checked for update of app "%s" in appstore', [$app]));
176 176
 	});
177
-	$updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) {
178
-		$eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app]));
177
+	$updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($eventSource, $l) {
178
+		$eventSource->send('success', (string) $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app]));
179 179
 	});
180
-	$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
181
-		$eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
180
+	$updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($eventSource, $l) {
181
+		$eventSource->send('success', (string) $l->t('Checked database schema update for apps'));
182 182
 	});
183
-	$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
184
-		$eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
183
+	$updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($eventSource, $l) {
184
+		$eventSource->send('success', (string) $l->t('Updated "%s" to %s', array($app, $version)));
185 185
 	});
186
-	$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
187
-		$incompatibleApps[]= $app;
186
+	$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use (&$incompatibleApps) {
187
+		$incompatibleApps[] = $app;
188 188
 	});
189
-	$updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) {
189
+	$updater->listen('\OC\Updater', 'failure', function($message) use ($eventSource, $config) {
190 190
 		$eventSource->send('failure', $message);
191 191
 		$eventSource->close();
192 192
 		$config->setSystemValue('maintenance', false);
193 193
 	});
194
-	$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
195
-		$eventSource->send('success', (string)$l->t('Set log level to debug'));
194
+	$updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use($eventSource, $l) {
195
+		$eventSource->send('success', (string) $l->t('Set log level to debug'));
196 196
 	});
197
-	$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
198
-		$eventSource->send('success', (string)$l->t('Reset log level'));
197
+	$updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($eventSource, $l) {
198
+		$eventSource->send('success', (string) $l->t('Reset log level'));
199 199
 	});
200
-	$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) {
201
-		$eventSource->send('success', (string)$l->t('Starting code integrity check'));
200
+	$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($eventSource, $l) {
201
+		$eventSource->send('success', (string) $l->t('Starting code integrity check'));
202 202
 	});
203
-	$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) {
204
-		$eventSource->send('success', (string)$l->t('Finished code integrity check'));
203
+	$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($eventSource, $l) {
204
+		$eventSource->send('success', (string) $l->t('Finished code integrity check'));
205 205
 	});
206 206
 
207 207
 	try {
208 208
 		$updater->upgrade();
209 209
 	} catch (\Exception $e) {
210
-		$eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
210
+		$eventSource->send('failure', get_class($e).': '.$e->getMessage());
211 211
 		$eventSource->close();
212 212
 		exit();
213 213
 	}
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 
220 220
 	if (!empty($disabledApps)) {
221 221
 		$eventSource->send('notice',
222
-			(string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)]));
222
+			(string) $l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)]));
223 223
 	}
224 224
 } else {
225
-	$eventSource->send('notice', (string)$l->t('Already up to date'));
225
+	$eventSource->send('notice', (string) $l->t('Already up to date'));
226 226
 }
227 227
 
228 228
 $eventSource->send('done', '');
Please login to merge, or discard this patch.
lib/private/Updater.php 2 patches
Indentation   +558 added lines, -558 removed lines patch added patch discarded remove patch
@@ -54,564 +54,564 @@
 block discarded – undo
54 54
  */
55 55
 class Updater extends BasicEmitter {
56 56
 
57
-	/** @var ILogger $log */
58
-	private $log;
59
-
60
-	/** @var IConfig */
61
-	private $config;
62
-
63
-	/** @var Checker */
64
-	private $checker;
65
-
66
-	/** @var Installer */
67
-	private $installer;
68
-
69
-	private $logLevelNames = [
70
-		0 => 'Debug',
71
-		1 => 'Info',
72
-		2 => 'Warning',
73
-		3 => 'Error',
74
-		4 => 'Fatal',
75
-	];
76
-
77
-	/**
78
-	 * @param IConfig $config
79
-	 * @param Checker $checker
80
-	 * @param ILogger $log
81
-	 * @param Installer $installer
82
-	 */
83
-	public function __construct(IConfig $config,
84
-								Checker $checker,
85
-								ILogger $log = null,
86
-								Installer $installer) {
87
-		$this->log = $log;
88
-		$this->config = $config;
89
-		$this->checker = $checker;
90
-		$this->installer = $installer;
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', Util::WARN);
104
-		$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
105
-		$this->config->setSystemValue('loglevel', Util::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
-		$installedVersion = $this->config->getSystemValue('version', '0.0.0');
115
-		$currentVersion = implode('.', \OCP\Util::getVersion());
116
-		$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
117
-
118
-		$success = true;
119
-		try {
120
-			$this->doUpgrade($currentVersion, $installedVersion);
121
-		} catch (HintException $exception) {
122
-			$this->log->logException($exception, ['app' => 'core']);
123
-			$this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint()));
124
-			$success = false;
125
-		} catch (\Exception $exception) {
126
-			$this->log->logException($exception, ['app' => 'core']);
127
-			$this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
128
-			$success = false;
129
-		}
130
-
131
-		$this->emit('\OC\Updater', 'updateEnd', array($success));
132
-
133
-		if(!$wasMaintenanceModeEnabled && $success) {
134
-			$this->config->setSystemValue('maintenance', false);
135
-			$this->emit('\OC\Updater', 'maintenanceDisabled');
136
-		} else {
137
-			$this->emit('\OC\Updater', 'maintenanceActive');
138
-		}
139
-
140
-		$this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
141
-		$this->config->setSystemValue('loglevel', $logLevel);
142
-		$this->config->setSystemValue('installed', true);
143
-
144
-		return $success;
145
-	}
146
-
147
-	/**
148
-	 * Return version from which this version is allowed to upgrade from
149
-	 *
150
-	 * @return array allowed previous versions per vendor
151
-	 */
152
-	private function getAllowedPreviousVersions() {
153
-		// this should really be a JSON file
154
-		require \OC::$SERVERROOT . '/version.php';
155
-		/** @var array $OC_VersionCanBeUpgradedFrom */
156
-		return $OC_VersionCanBeUpgradedFrom;
157
-	}
158
-
159
-	/**
160
-	 * Return vendor from which this version was published
161
-	 *
162
-	 * @return string Get the vendor
163
-	 */
164
-	private function getVendor() {
165
-		// this should really be a JSON file
166
-		require \OC::$SERVERROOT . '/version.php';
167
-		/** @var string $vendor */
168
-		return (string) $vendor;
169
-	}
170
-
171
-	/**
172
-	 * Whether an upgrade to a specified version is possible
173
-	 * @param string $oldVersion
174
-	 * @param string $newVersion
175
-	 * @param array $allowedPreviousVersions
176
-	 * @return bool
177
-	 */
178
-	public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
179
-		$version = explode('.', $oldVersion);
180
-		$majorMinor = $version[0] . '.' . $version[1];
181
-
182
-		$currentVendor = $this->config->getAppValue('core', 'vendor', '');
183
-
184
-		// Vendor was not set correctly on install, so we have to white-list known versions
185
-		if ($currentVendor === '') {
186
-			if (in_array($oldVersion, [
187
-				'11.0.2.7',
188
-				'11.0.1.2',
189
-				'11.0.0.10',
190
-			], true)) {
191
-				$currentVendor = 'nextcloud';
192
-			} else if (isset($allowedPreviousVersions['owncloud'][$oldVersion])) {
193
-				$currentVendor = 'owncloud';
194
-			}
195
-		}
196
-
197
-		if ($currentVendor === 'nextcloud') {
198
-			return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
199
-				&& (version_compare($oldVersion, $newVersion, '<=') ||
200
-					$this->config->getSystemValue('debug', false));
201
-		}
202
-
203
-		// Check if the instance can be migrated
204
-		return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) ||
205
-			isset($allowedPreviousVersions[$currentVendor][$oldVersion]);
206
-	}
207
-
208
-	/**
209
-	 * runs the update actions in maintenance mode, does not upgrade the source files
210
-	 * except the main .htaccess file
211
-	 *
212
-	 * @param string $currentVersion current version to upgrade to
213
-	 * @param string $installedVersion previous version from which to upgrade from
214
-	 *
215
-	 * @throws \Exception
216
-	 */
217
-	private function doUpgrade($currentVersion, $installedVersion) {
218
-		// Stop update if the update is over several major versions
219
-		$allowedPreviousVersions = $this->getAllowedPreviousVersions();
220
-		if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
221
-			throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
222
-		}
223
-
224
-		// Update .htaccess files
225
-		try {
226
-			Setup::updateHtaccess();
227
-			Setup::protectDataDirectory();
228
-		} catch (\Exception $e) {
229
-			throw new \Exception($e->getMessage());
230
-		}
231
-
232
-		// create empty file in data dir, so we can later find
233
-		// out that this is indeed an ownCloud data directory
234
-		// (in case it didn't exist before)
235
-		file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
236
-
237
-		// pre-upgrade repairs
238
-		$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
239
-		$repair->run();
240
-
241
-		$this->doCoreUpgrade();
242
-
243
-		try {
244
-			// TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
245
-			Setup::installBackgroundJobs();
246
-		} catch (\Exception $e) {
247
-			throw new \Exception($e->getMessage());
248
-		}
249
-
250
-		// update all shipped apps
251
-		$this->checkAppsRequirements();
252
-		$this->doAppUpgrade();
253
-
254
-		// Update the appfetchers version so it downloads the correct list from the appstore
255
-		\OC::$server->getAppFetcher()->setVersion($currentVersion);
256
-
257
-		// upgrade appstore apps
258
-		$this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps());
259
-
260
-		// install new shipped apps on upgrade
261
-		OC_App::loadApps('authentication');
262
-		$errors = Installer::installShippedApps(true);
263
-		foreach ($errors as $appId => $exception) {
264
-			/** @var \Exception $exception */
265
-			$this->log->logException($exception, ['app' => $appId]);
266
-			$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
267
-		}
268
-
269
-		// post-upgrade repairs
270
-		$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
271
-		$repair->run();
272
-
273
-		//Invalidate update feed
274
-		$this->config->setAppValue('core', 'lastupdatedat', 0);
275
-
276
-		// Check for code integrity if not disabled
277
-		if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
278
-			$this->emit('\OC\Updater', 'startCheckCodeIntegrity');
279
-			$this->checker->runInstanceVerification();
280
-			$this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
281
-		}
282
-
283
-		// only set the final version if everything went well
284
-		$this->config->setSystemValue('version', implode('.', Util::getVersion()));
285
-		$this->config->setAppValue('core', 'vendor', $this->getVendor());
286
-	}
287
-
288
-	protected function doCoreUpgrade() {
289
-		$this->emit('\OC\Updater', 'dbUpgradeBefore');
290
-
291
-		// execute core migrations
292
-		$ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
293
-		$ms->migrate();
294
-
295
-		$this->emit('\OC\Updater', 'dbUpgrade');
296
-	}
297
-
298
-	/**
299
-	 * @param string $version the oc version to check app compatibility with
300
-	 */
301
-	protected function checkAppUpgrade($version) {
302
-		$apps = \OC_App::getEnabledApps();
303
-		$this->emit('\OC\Updater', 'appUpgradeCheckBefore');
304
-
305
-		$appManager = \OC::$server->getAppManager();
306
-		foreach ($apps as $appId) {
307
-			$info = \OC_App::getAppInfo($appId);
308
-			$compatible = \OC_App::isAppCompatible($version, $info);
309
-			$isShipped = $appManager->isShipped($appId);
310
-
311
-			if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) {
312
-				/**
313
-				 * FIXME: The preupdate check is performed before the database migration, otherwise database changes
314
-				 * are not possible anymore within it. - Consider this when touching the code.
315
-				 * @link https://github.com/owncloud/core/issues/10980
316
-				 * @see \OC_App::updateApp
317
-				 */
318
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
319
-					$this->includePreUpdate($appId);
320
-				}
321
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
322
-					$this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
323
-					\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
324
-				}
325
-			}
326
-		}
327
-
328
-		$this->emit('\OC\Updater', 'appUpgradeCheck');
329
-	}
330
-
331
-	/**
332
-	 * Includes the pre-update file. Done here to prevent namespace mixups.
333
-	 * @param string $appId
334
-	 */
335
-	private function includePreUpdate($appId) {
336
-		include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
337
-	}
338
-
339
-	/**
340
-	 * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
341
-	 * (types authentication, filesystem, logging, in that order) afterwards.
342
-	 *
343
-	 * @throws NeedsUpdateException
344
-	 */
345
-	protected function doAppUpgrade() {
346
-		$apps = \OC_App::getEnabledApps();
347
-		$priorityTypes = array('authentication', 'filesystem', 'logging');
348
-		$pseudoOtherType = 'other';
349
-		$stacks = array($pseudoOtherType => array());
350
-
351
-		foreach ($apps as $appId) {
352
-			$priorityType = false;
353
-			foreach ($priorityTypes as $type) {
354
-				if(!isset($stacks[$type])) {
355
-					$stacks[$type] = array();
356
-				}
357
-				if (\OC_App::isType($appId, $type)) {
358
-					$stacks[$type][] = $appId;
359
-					$priorityType = true;
360
-					break;
361
-				}
362
-			}
363
-			if (!$priorityType) {
364
-				$stacks[$pseudoOtherType][] = $appId;
365
-			}
366
-		}
367
-		foreach ($stacks as $type => $stack) {
368
-			foreach ($stack as $appId) {
369
-				if (\OC_App::shouldUpgrade($appId)) {
370
-					$this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
371
-					\OC_App::updateApp($appId);
372
-					$this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
373
-				}
374
-				if($type !== $pseudoOtherType) {
375
-					// load authentication, filesystem and logging apps after
376
-					// upgrading them. Other apps my need to rely on modifying
377
-					// user and/or filesystem aspects.
378
-					\OC_App::loadApp($appId);
379
-				}
380
-			}
381
-		}
382
-	}
383
-
384
-	/**
385
-	 * check if the current enabled apps are compatible with the current
386
-	 * ownCloud version. disable them if not.
387
-	 * This is important if you upgrade ownCloud and have non ported 3rd
388
-	 * party apps installed.
389
-	 *
390
-	 * @return array
391
-	 * @throws \Exception
392
-	 */
393
-	private function checkAppsRequirements() {
394
-		$isCoreUpgrade = $this->isCodeUpgrade();
395
-		$apps = OC_App::getEnabledApps();
396
-		$version = Util::getVersion();
397
-		$disabledApps = [];
398
-		$appManager = \OC::$server->getAppManager();
399
-		foreach ($apps as $app) {
400
-			// check if the app is compatible with this version of ownCloud
401
-			$info = OC_App::getAppInfo($app);
402
-			if(!OC_App::isAppCompatible($version, $info)) {
403
-				if ($appManager->isShipped($app)) {
404
-					throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
405
-				}
406
-				OC_App::disable($app);
407
-				$this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
408
-			}
409
-			// no need to disable any app in case this is a non-core upgrade
410
-			if (!$isCoreUpgrade) {
411
-				continue;
412
-			}
413
-			// shipped apps will remain enabled
414
-			if ($appManager->isShipped($app)) {
415
-				continue;
416
-			}
417
-			// authentication and session apps will remain enabled as well
418
-			if (OC_App::isType($app, ['session', 'authentication'])) {
419
-				continue;
420
-			}
421
-		}
422
-		return $disabledApps;
423
-	}
424
-
425
-	/**
426
-	 * @return bool
427
-	 */
428
-	private function isCodeUpgrade() {
429
-		$installedVersion = $this->config->getSystemValue('version', '0.0.0');
430
-		$currentVersion = implode('.', Util::getVersion());
431
-		if (version_compare($currentVersion, $installedVersion, '>')) {
432
-			return true;
433
-		}
434
-		return false;
435
-	}
436
-
437
-	/**
438
-	 * @param array $disabledApps
439
-	 * @throws \Exception
440
-	 */
441
-	private function upgradeAppStoreApps(array $disabledApps) {
442
-		foreach($disabledApps as $app) {
443
-			try {
444
-				$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
445
-				if ($this->installer->isUpdateAvailable($app)) {
446
-					$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
447
-					$this->installer->updateAppstoreApp($app);
448
-				}
449
-				$this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
450
-			} catch (\Exception $ex) {
451
-				$this->log->logException($ex, ['app' => 'core']);
452
-			}
453
-		}
454
-	}
455
-
456
-	/**
457
-	 * Forward messages emitted by the repair routine
458
-	 */
459
-	private function emitRepairEvents() {
460
-		$dispatcher = \OC::$server->getEventDispatcher();
461
-		$dispatcher->addListener('\OC\Repair::warning', function ($event) {
462
-			if ($event instanceof GenericEvent) {
463
-				$this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
464
-			}
465
-		});
466
-		$dispatcher->addListener('\OC\Repair::error', function ($event) {
467
-			if ($event instanceof GenericEvent) {
468
-				$this->emit('\OC\Updater', 'repairError', $event->getArguments());
469
-			}
470
-		});
471
-		$dispatcher->addListener('\OC\Repair::info', function ($event) {
472
-			if ($event instanceof GenericEvent) {
473
-				$this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
474
-			}
475
-		});
476
-		$dispatcher->addListener('\OC\Repair::step', function ($event) {
477
-			if ($event instanceof GenericEvent) {
478
-				$this->emit('\OC\Updater', 'repairStep', $event->getArguments());
479
-			}
480
-		});
481
-	}
482
-
483
-	private function logAllEvents() {
484
-		$log = $this->log;
485
-
486
-		$dispatcher = \OC::$server->getEventDispatcher();
487
-		$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
488
-			if (!$event instanceof GenericEvent) {
489
-				return;
490
-			}
491
-			$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
492
-		});
493
-		$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
494
-			if (!$event instanceof GenericEvent) {
495
-				return;
496
-			}
497
-			$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
498
-		});
499
-
500
-		$repairListener = function($event) use ($log) {
501
-			if (!$event instanceof GenericEvent) {
502
-				return;
503
-			}
504
-			switch ($event->getSubject()) {
505
-				case '\OC\Repair::startProgress':
506
-					$log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) .  ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
507
-					break;
508
-				case '\OC\Repair::advance':
509
-					$desc = $event->getArgument(1);
510
-					if (empty($desc)) {
511
-						$desc = '';
512
-					}
513
-					$log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
514
-
515
-					break;
516
-				case '\OC\Repair::finishProgress':
517
-					$log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
518
-					break;
519
-				case '\OC\Repair::step':
520
-					$log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
521
-					break;
522
-				case '\OC\Repair::info':
523
-					$log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
524
-					break;
525
-				case '\OC\Repair::warning':
526
-					$log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
527
-					break;
528
-				case '\OC\Repair::error':
529
-					$log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
530
-					break;
531
-			}
532
-		};
533
-
534
-		$dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
535
-		$dispatcher->addListener('\OC\Repair::advance', $repairListener);
536
-		$dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
537
-		$dispatcher->addListener('\OC\Repair::step', $repairListener);
538
-		$dispatcher->addListener('\OC\Repair::info', $repairListener);
539
-		$dispatcher->addListener('\OC\Repair::warning', $repairListener);
540
-		$dispatcher->addListener('\OC\Repair::error', $repairListener);
541
-
542
-
543
-		$this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
544
-			$log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
545
-		});
546
-		$this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
547
-			$log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
548
-		});
549
-		$this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
550
-			$log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
551
-		});
552
-		$this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
553
-			if ($success) {
554
-				$log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
555
-			} else {
556
-				$log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
557
-			}
558
-		});
559
-		$this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
560
-			$log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
561
-		});
562
-		$this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
563
-			$log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
564
-		});
565
-		$this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
566
-			$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']);
567
-		});
568
-		$this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
569
-			$log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
570
-		});
571
-		$this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
572
-			$log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
573
-		});
574
-		$this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) {
575
-			$log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']);
576
-		});
577
-		$this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
578
-			$log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']);
579
-		});
580
-		$this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) {
581
-			$log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']);
582
-		});
583
-		$this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
584
-			$log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
585
-		});
586
-		$this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
587
-			$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']);
588
-		});
589
-		$this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
590
-			$log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
591
-		});
592
-		$this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
593
-			$log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
594
-		});
595
-		$this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
596
-			$log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
597
-		});
598
-		$this->listen('\OC\Updater', 'failure', function ($message) use($log) {
599
-			$log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
600
-		});
601
-		$this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
602
-			$log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
603
-		});
604
-		$this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
605
-			$log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
606
-		});
607
-		$this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
608
-			$log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
609
-		});
610
-		$this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
611
-			$log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
612
-		});
613
-
614
-	}
57
+    /** @var ILogger $log */
58
+    private $log;
59
+
60
+    /** @var IConfig */
61
+    private $config;
62
+
63
+    /** @var Checker */
64
+    private $checker;
65
+
66
+    /** @var Installer */
67
+    private $installer;
68
+
69
+    private $logLevelNames = [
70
+        0 => 'Debug',
71
+        1 => 'Info',
72
+        2 => 'Warning',
73
+        3 => 'Error',
74
+        4 => 'Fatal',
75
+    ];
76
+
77
+    /**
78
+     * @param IConfig $config
79
+     * @param Checker $checker
80
+     * @param ILogger $log
81
+     * @param Installer $installer
82
+     */
83
+    public function __construct(IConfig $config,
84
+                                Checker $checker,
85
+                                ILogger $log = null,
86
+                                Installer $installer) {
87
+        $this->log = $log;
88
+        $this->config = $config;
89
+        $this->checker = $checker;
90
+        $this->installer = $installer;
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', Util::WARN);
104
+        $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
105
+        $this->config->setSystemValue('loglevel', Util::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
+        $installedVersion = $this->config->getSystemValue('version', '0.0.0');
115
+        $currentVersion = implode('.', \OCP\Util::getVersion());
116
+        $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
117
+
118
+        $success = true;
119
+        try {
120
+            $this->doUpgrade($currentVersion, $installedVersion);
121
+        } catch (HintException $exception) {
122
+            $this->log->logException($exception, ['app' => 'core']);
123
+            $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint()));
124
+            $success = false;
125
+        } catch (\Exception $exception) {
126
+            $this->log->logException($exception, ['app' => 'core']);
127
+            $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
128
+            $success = false;
129
+        }
130
+
131
+        $this->emit('\OC\Updater', 'updateEnd', array($success));
132
+
133
+        if(!$wasMaintenanceModeEnabled && $success) {
134
+            $this->config->setSystemValue('maintenance', false);
135
+            $this->emit('\OC\Updater', 'maintenanceDisabled');
136
+        } else {
137
+            $this->emit('\OC\Updater', 'maintenanceActive');
138
+        }
139
+
140
+        $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
141
+        $this->config->setSystemValue('loglevel', $logLevel);
142
+        $this->config->setSystemValue('installed', true);
143
+
144
+        return $success;
145
+    }
146
+
147
+    /**
148
+     * Return version from which this version is allowed to upgrade from
149
+     *
150
+     * @return array allowed previous versions per vendor
151
+     */
152
+    private function getAllowedPreviousVersions() {
153
+        // this should really be a JSON file
154
+        require \OC::$SERVERROOT . '/version.php';
155
+        /** @var array $OC_VersionCanBeUpgradedFrom */
156
+        return $OC_VersionCanBeUpgradedFrom;
157
+    }
158
+
159
+    /**
160
+     * Return vendor from which this version was published
161
+     *
162
+     * @return string Get the vendor
163
+     */
164
+    private function getVendor() {
165
+        // this should really be a JSON file
166
+        require \OC::$SERVERROOT . '/version.php';
167
+        /** @var string $vendor */
168
+        return (string) $vendor;
169
+    }
170
+
171
+    /**
172
+     * Whether an upgrade to a specified version is possible
173
+     * @param string $oldVersion
174
+     * @param string $newVersion
175
+     * @param array $allowedPreviousVersions
176
+     * @return bool
177
+     */
178
+    public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
179
+        $version = explode('.', $oldVersion);
180
+        $majorMinor = $version[0] . '.' . $version[1];
181
+
182
+        $currentVendor = $this->config->getAppValue('core', 'vendor', '');
183
+
184
+        // Vendor was not set correctly on install, so we have to white-list known versions
185
+        if ($currentVendor === '') {
186
+            if (in_array($oldVersion, [
187
+                '11.0.2.7',
188
+                '11.0.1.2',
189
+                '11.0.0.10',
190
+            ], true)) {
191
+                $currentVendor = 'nextcloud';
192
+            } else if (isset($allowedPreviousVersions['owncloud'][$oldVersion])) {
193
+                $currentVendor = 'owncloud';
194
+            }
195
+        }
196
+
197
+        if ($currentVendor === 'nextcloud') {
198
+            return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
199
+                && (version_compare($oldVersion, $newVersion, '<=') ||
200
+                    $this->config->getSystemValue('debug', false));
201
+        }
202
+
203
+        // Check if the instance can be migrated
204
+        return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) ||
205
+            isset($allowedPreviousVersions[$currentVendor][$oldVersion]);
206
+    }
207
+
208
+    /**
209
+     * runs the update actions in maintenance mode, does not upgrade the source files
210
+     * except the main .htaccess file
211
+     *
212
+     * @param string $currentVersion current version to upgrade to
213
+     * @param string $installedVersion previous version from which to upgrade from
214
+     *
215
+     * @throws \Exception
216
+     */
217
+    private function doUpgrade($currentVersion, $installedVersion) {
218
+        // Stop update if the update is over several major versions
219
+        $allowedPreviousVersions = $this->getAllowedPreviousVersions();
220
+        if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
221
+            throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
222
+        }
223
+
224
+        // Update .htaccess files
225
+        try {
226
+            Setup::updateHtaccess();
227
+            Setup::protectDataDirectory();
228
+        } catch (\Exception $e) {
229
+            throw new \Exception($e->getMessage());
230
+        }
231
+
232
+        // create empty file in data dir, so we can later find
233
+        // out that this is indeed an ownCloud data directory
234
+        // (in case it didn't exist before)
235
+        file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
236
+
237
+        // pre-upgrade repairs
238
+        $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
239
+        $repair->run();
240
+
241
+        $this->doCoreUpgrade();
242
+
243
+        try {
244
+            // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
245
+            Setup::installBackgroundJobs();
246
+        } catch (\Exception $e) {
247
+            throw new \Exception($e->getMessage());
248
+        }
249
+
250
+        // update all shipped apps
251
+        $this->checkAppsRequirements();
252
+        $this->doAppUpgrade();
253
+
254
+        // Update the appfetchers version so it downloads the correct list from the appstore
255
+        \OC::$server->getAppFetcher()->setVersion($currentVersion);
256
+
257
+        // upgrade appstore apps
258
+        $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps());
259
+
260
+        // install new shipped apps on upgrade
261
+        OC_App::loadApps('authentication');
262
+        $errors = Installer::installShippedApps(true);
263
+        foreach ($errors as $appId => $exception) {
264
+            /** @var \Exception $exception */
265
+            $this->log->logException($exception, ['app' => $appId]);
266
+            $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
267
+        }
268
+
269
+        // post-upgrade repairs
270
+        $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
271
+        $repair->run();
272
+
273
+        //Invalidate update feed
274
+        $this->config->setAppValue('core', 'lastupdatedat', 0);
275
+
276
+        // Check for code integrity if not disabled
277
+        if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
278
+            $this->emit('\OC\Updater', 'startCheckCodeIntegrity');
279
+            $this->checker->runInstanceVerification();
280
+            $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
281
+        }
282
+
283
+        // only set the final version if everything went well
284
+        $this->config->setSystemValue('version', implode('.', Util::getVersion()));
285
+        $this->config->setAppValue('core', 'vendor', $this->getVendor());
286
+    }
287
+
288
+    protected function doCoreUpgrade() {
289
+        $this->emit('\OC\Updater', 'dbUpgradeBefore');
290
+
291
+        // execute core migrations
292
+        $ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
293
+        $ms->migrate();
294
+
295
+        $this->emit('\OC\Updater', 'dbUpgrade');
296
+    }
297
+
298
+    /**
299
+     * @param string $version the oc version to check app compatibility with
300
+     */
301
+    protected function checkAppUpgrade($version) {
302
+        $apps = \OC_App::getEnabledApps();
303
+        $this->emit('\OC\Updater', 'appUpgradeCheckBefore');
304
+
305
+        $appManager = \OC::$server->getAppManager();
306
+        foreach ($apps as $appId) {
307
+            $info = \OC_App::getAppInfo($appId);
308
+            $compatible = \OC_App::isAppCompatible($version, $info);
309
+            $isShipped = $appManager->isShipped($appId);
310
+
311
+            if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) {
312
+                /**
313
+                 * FIXME: The preupdate check is performed before the database migration, otherwise database changes
314
+                 * are not possible anymore within it. - Consider this when touching the code.
315
+                 * @link https://github.com/owncloud/core/issues/10980
316
+                 * @see \OC_App::updateApp
317
+                 */
318
+                if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
319
+                    $this->includePreUpdate($appId);
320
+                }
321
+                if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
322
+                    $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
323
+                    \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
324
+                }
325
+            }
326
+        }
327
+
328
+        $this->emit('\OC\Updater', 'appUpgradeCheck');
329
+    }
330
+
331
+    /**
332
+     * Includes the pre-update file. Done here to prevent namespace mixups.
333
+     * @param string $appId
334
+     */
335
+    private function includePreUpdate($appId) {
336
+        include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
337
+    }
338
+
339
+    /**
340
+     * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
341
+     * (types authentication, filesystem, logging, in that order) afterwards.
342
+     *
343
+     * @throws NeedsUpdateException
344
+     */
345
+    protected function doAppUpgrade() {
346
+        $apps = \OC_App::getEnabledApps();
347
+        $priorityTypes = array('authentication', 'filesystem', 'logging');
348
+        $pseudoOtherType = 'other';
349
+        $stacks = array($pseudoOtherType => array());
350
+
351
+        foreach ($apps as $appId) {
352
+            $priorityType = false;
353
+            foreach ($priorityTypes as $type) {
354
+                if(!isset($stacks[$type])) {
355
+                    $stacks[$type] = array();
356
+                }
357
+                if (\OC_App::isType($appId, $type)) {
358
+                    $stacks[$type][] = $appId;
359
+                    $priorityType = true;
360
+                    break;
361
+                }
362
+            }
363
+            if (!$priorityType) {
364
+                $stacks[$pseudoOtherType][] = $appId;
365
+            }
366
+        }
367
+        foreach ($stacks as $type => $stack) {
368
+            foreach ($stack as $appId) {
369
+                if (\OC_App::shouldUpgrade($appId)) {
370
+                    $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
371
+                    \OC_App::updateApp($appId);
372
+                    $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
373
+                }
374
+                if($type !== $pseudoOtherType) {
375
+                    // load authentication, filesystem and logging apps after
376
+                    // upgrading them. Other apps my need to rely on modifying
377
+                    // user and/or filesystem aspects.
378
+                    \OC_App::loadApp($appId);
379
+                }
380
+            }
381
+        }
382
+    }
383
+
384
+    /**
385
+     * check if the current enabled apps are compatible with the current
386
+     * ownCloud version. disable them if not.
387
+     * This is important if you upgrade ownCloud and have non ported 3rd
388
+     * party apps installed.
389
+     *
390
+     * @return array
391
+     * @throws \Exception
392
+     */
393
+    private function checkAppsRequirements() {
394
+        $isCoreUpgrade = $this->isCodeUpgrade();
395
+        $apps = OC_App::getEnabledApps();
396
+        $version = Util::getVersion();
397
+        $disabledApps = [];
398
+        $appManager = \OC::$server->getAppManager();
399
+        foreach ($apps as $app) {
400
+            // check if the app is compatible with this version of ownCloud
401
+            $info = OC_App::getAppInfo($app);
402
+            if(!OC_App::isAppCompatible($version, $info)) {
403
+                if ($appManager->isShipped($app)) {
404
+                    throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
405
+                }
406
+                OC_App::disable($app);
407
+                $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
408
+            }
409
+            // no need to disable any app in case this is a non-core upgrade
410
+            if (!$isCoreUpgrade) {
411
+                continue;
412
+            }
413
+            // shipped apps will remain enabled
414
+            if ($appManager->isShipped($app)) {
415
+                continue;
416
+            }
417
+            // authentication and session apps will remain enabled as well
418
+            if (OC_App::isType($app, ['session', 'authentication'])) {
419
+                continue;
420
+            }
421
+        }
422
+        return $disabledApps;
423
+    }
424
+
425
+    /**
426
+     * @return bool
427
+     */
428
+    private function isCodeUpgrade() {
429
+        $installedVersion = $this->config->getSystemValue('version', '0.0.0');
430
+        $currentVersion = implode('.', Util::getVersion());
431
+        if (version_compare($currentVersion, $installedVersion, '>')) {
432
+            return true;
433
+        }
434
+        return false;
435
+    }
436
+
437
+    /**
438
+     * @param array $disabledApps
439
+     * @throws \Exception
440
+     */
441
+    private function upgradeAppStoreApps(array $disabledApps) {
442
+        foreach($disabledApps as $app) {
443
+            try {
444
+                $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
445
+                if ($this->installer->isUpdateAvailable($app)) {
446
+                    $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
447
+                    $this->installer->updateAppstoreApp($app);
448
+                }
449
+                $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
450
+            } catch (\Exception $ex) {
451
+                $this->log->logException($ex, ['app' => 'core']);
452
+            }
453
+        }
454
+    }
455
+
456
+    /**
457
+     * Forward messages emitted by the repair routine
458
+     */
459
+    private function emitRepairEvents() {
460
+        $dispatcher = \OC::$server->getEventDispatcher();
461
+        $dispatcher->addListener('\OC\Repair::warning', function ($event) {
462
+            if ($event instanceof GenericEvent) {
463
+                $this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
464
+            }
465
+        });
466
+        $dispatcher->addListener('\OC\Repair::error', function ($event) {
467
+            if ($event instanceof GenericEvent) {
468
+                $this->emit('\OC\Updater', 'repairError', $event->getArguments());
469
+            }
470
+        });
471
+        $dispatcher->addListener('\OC\Repair::info', function ($event) {
472
+            if ($event instanceof GenericEvent) {
473
+                $this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
474
+            }
475
+        });
476
+        $dispatcher->addListener('\OC\Repair::step', function ($event) {
477
+            if ($event instanceof GenericEvent) {
478
+                $this->emit('\OC\Updater', 'repairStep', $event->getArguments());
479
+            }
480
+        });
481
+    }
482
+
483
+    private function logAllEvents() {
484
+        $log = $this->log;
485
+
486
+        $dispatcher = \OC::$server->getEventDispatcher();
487
+        $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
488
+            if (!$event instanceof GenericEvent) {
489
+                return;
490
+            }
491
+            $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
492
+        });
493
+        $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
494
+            if (!$event instanceof GenericEvent) {
495
+                return;
496
+            }
497
+            $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
498
+        });
499
+
500
+        $repairListener = function($event) use ($log) {
501
+            if (!$event instanceof GenericEvent) {
502
+                return;
503
+            }
504
+            switch ($event->getSubject()) {
505
+                case '\OC\Repair::startProgress':
506
+                    $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) .  ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
507
+                    break;
508
+                case '\OC\Repair::advance':
509
+                    $desc = $event->getArgument(1);
510
+                    if (empty($desc)) {
511
+                        $desc = '';
512
+                    }
513
+                    $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
514
+
515
+                    break;
516
+                case '\OC\Repair::finishProgress':
517
+                    $log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
518
+                    break;
519
+                case '\OC\Repair::step':
520
+                    $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
521
+                    break;
522
+                case '\OC\Repair::info':
523
+                    $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
524
+                    break;
525
+                case '\OC\Repair::warning':
526
+                    $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
527
+                    break;
528
+                case '\OC\Repair::error':
529
+                    $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
530
+                    break;
531
+            }
532
+        };
533
+
534
+        $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
535
+        $dispatcher->addListener('\OC\Repair::advance', $repairListener);
536
+        $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
537
+        $dispatcher->addListener('\OC\Repair::step', $repairListener);
538
+        $dispatcher->addListener('\OC\Repair::info', $repairListener);
539
+        $dispatcher->addListener('\OC\Repair::warning', $repairListener);
540
+        $dispatcher->addListener('\OC\Repair::error', $repairListener);
541
+
542
+
543
+        $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
544
+            $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
545
+        });
546
+        $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
547
+            $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
548
+        });
549
+        $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
550
+            $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
551
+        });
552
+        $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
553
+            if ($success) {
554
+                $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
555
+            } else {
556
+                $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
557
+            }
558
+        });
559
+        $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
560
+            $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
561
+        });
562
+        $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
563
+            $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
564
+        });
565
+        $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
566
+            $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']);
567
+        });
568
+        $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
569
+            $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
570
+        });
571
+        $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
572
+            $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
573
+        });
574
+        $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) {
575
+            $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']);
576
+        });
577
+        $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
578
+            $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']);
579
+        });
580
+        $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) {
581
+            $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']);
582
+        });
583
+        $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
584
+            $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
585
+        });
586
+        $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
587
+            $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']);
588
+        });
589
+        $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
590
+            $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
591
+        });
592
+        $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
593
+            $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
594
+        });
595
+        $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
596
+            $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
597
+        });
598
+        $this->listen('\OC\Updater', 'failure', function ($message) use($log) {
599
+            $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
600
+        });
601
+        $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
602
+            $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
603
+        });
604
+        $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
605
+            $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
606
+        });
607
+        $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
608
+            $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
609
+        });
610
+        $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
611
+            $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
612
+        });
613
+
614
+    }
615 615
 
616 616
 }
617 617
 
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', Util::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', Util::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
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		// create empty file in data dir, so we can later find
233 233
 		// out that this is indeed an ownCloud data directory
234 234
 		// (in case it didn't exist before)
235
-		file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
235
+		file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
236 236
 
237 237
 		// pre-upgrade repairs
238 238
 		$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		foreach ($errors as $appId => $exception) {
264 264
 			/** @var \Exception $exception */
265 265
 			$this->log->logException($exception, ['app' => $appId]);
266
-			$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
266
+			$this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]);
267 267
 		}
268 268
 
269 269
 		// post-upgrade repairs
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 		$this->config->setAppValue('core', 'lastupdatedat', 0);
275 275
 
276 276
 		// Check for code integrity if not disabled
277
-		if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
277
+		if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
278 278
 			$this->emit('\OC\Updater', 'startCheckCodeIntegrity');
279 279
 			$this->checker->runInstanceVerification();
280 280
 			$this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 				 * @link https://github.com/owncloud/core/issues/10980
316 316
 				 * @see \OC_App::updateApp
317 317
 				 */
318
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
318
+				if (file_exists(\OC_App::getAppPath($appId).'/appinfo/preupdate.php')) {
319 319
 					$this->includePreUpdate($appId);
320 320
 				}
321
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
321
+				if (file_exists(\OC_App::getAppPath($appId).'/appinfo/database.xml')) {
322 322
 					$this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
323
-					\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
323
+					\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId).'/appinfo/database.xml');
324 324
 				}
325 325
 			}
326 326
 		}
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @param string $appId
334 334
 	 */
335 335
 	private function includePreUpdate($appId) {
336
-		include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
336
+		include \OC_App::getAppPath($appId).'/appinfo/preupdate.php';
337 337
 	}
338 338
 
339 339
 	/**
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 		foreach ($apps as $appId) {
352 352
 			$priorityType = false;
353 353
 			foreach ($priorityTypes as $type) {
354
-				if(!isset($stacks[$type])) {
354
+				if (!isset($stacks[$type])) {
355 355
 					$stacks[$type] = array();
356 356
 				}
357 357
 				if (\OC_App::isType($appId, $type)) {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 					\OC_App::updateApp($appId);
372 372
 					$this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
373 373
 				}
374
-				if($type !== $pseudoOtherType) {
374
+				if ($type !== $pseudoOtherType) {
375 375
 					// load authentication, filesystem and logging apps after
376 376
 					// upgrading them. Other apps my need to rely on modifying
377 377
 					// user and/or filesystem aspects.
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
 		foreach ($apps as $app) {
400 400
 			// check if the app is compatible with this version of ownCloud
401 401
 			$info = OC_App::getAppInfo($app);
402
-			if(!OC_App::isAppCompatible($version, $info)) {
402
+			if (!OC_App::isAppCompatible($version, $info)) {
403 403
 				if ($appManager->isShipped($app)) {
404
-					throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
404
+					throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update');
405 405
 				}
406 406
 				OC_App::disable($app);
407 407
 				$this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	 * @throws \Exception
440 440
 	 */
441 441
 	private function upgradeAppStoreApps(array $disabledApps) {
442
-		foreach($disabledApps as $app) {
442
+		foreach ($disabledApps as $app) {
443 443
 			try {
444 444
 				$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
445 445
 				if ($this->installer->isUpdateAvailable($app)) {
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
 	 */
459 459
 	private function emitRepairEvents() {
460 460
 		$dispatcher = \OC::$server->getEventDispatcher();
461
-		$dispatcher->addListener('\OC\Repair::warning', function ($event) {
461
+		$dispatcher->addListener('\OC\Repair::warning', function($event) {
462 462
 			if ($event instanceof GenericEvent) {
463 463
 				$this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
464 464
 			}
465 465
 		});
466
-		$dispatcher->addListener('\OC\Repair::error', function ($event) {
466
+		$dispatcher->addListener('\OC\Repair::error', function($event) {
467 467
 			if ($event instanceof GenericEvent) {
468 468
 				$this->emit('\OC\Updater', 'repairError', $event->getArguments());
469 469
 			}
470 470
 		});
471
-		$dispatcher->addListener('\OC\Repair::info', function ($event) {
471
+		$dispatcher->addListener('\OC\Repair::info', function($event) {
472 472
 			if ($event instanceof GenericEvent) {
473 473
 				$this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
474 474
 			}
475 475
 		});
476
-		$dispatcher->addListener('\OC\Repair::step', function ($event) {
476
+		$dispatcher->addListener('\OC\Repair::step', function($event) {
477 477
 			if ($event instanceof GenericEvent) {
478 478
 				$this->emit('\OC\Updater', 'repairStep', $event->getArguments());
479 479
 			}
@@ -488,13 +488,13 @@  discard block
 block discarded – undo
488 488
 			if (!$event instanceof GenericEvent) {
489 489
 				return;
490 490
 			}
491
-			$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
491
+			$log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']);
492 492
 		});
493 493
 		$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
494 494
 			if (!$event instanceof GenericEvent) {
495 495
 				return;
496 496
 			}
497
-			$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
497
+			$log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']);
498 498
 		});
499 499
 
500 500
 		$repairListener = function($event) use ($log) {
@@ -503,30 +503,30 @@  discard block
 block discarded – undo
503 503
 			}
504 504
 			switch ($event->getSubject()) {
505 505
 				case '\OC\Repair::startProgress':
506
-					$log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) .  ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
506
+					$log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']);
507 507
 					break;
508 508
 				case '\OC\Repair::advance':
509 509
 					$desc = $event->getArgument(1);
510 510
 					if (empty($desc)) {
511 511
 						$desc = '';
512 512
 					}
513
-					$log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
513
+					$log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']);
514 514
 
515 515
 					break;
516 516
 				case '\OC\Repair::finishProgress':
517 517
 					$log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
518 518
 					break;
519 519
 				case '\OC\Repair::step':
520
-					$log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
520
+					$log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']);
521 521
 					break;
522 522
 				case '\OC\Repair::info':
523
-					$log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
523
+					$log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']);
524 524
 					break;
525 525
 				case '\OC\Repair::warning':
526
-					$log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
526
+					$log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']);
527 527
 					break;
528 528
 				case '\OC\Repair::error':
529
-					$log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
529
+					$log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']);
530 530
 					break;
531 531
 			}
532 532
 		};
@@ -540,74 +540,74 @@  discard block
 block discarded – undo
540 540
 		$dispatcher->addListener('\OC\Repair::error', $repairListener);
541 541
 
542 542
 
543
-		$this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
543
+		$this->listen('\OC\Updater', 'maintenanceEnabled', function() use($log) {
544 544
 			$log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
545 545
 		});
546
-		$this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
546
+		$this->listen('\OC\Updater', 'maintenanceDisabled', function() use($log) {
547 547
 			$log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
548 548
 		});
549
-		$this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
549
+		$this->listen('\OC\Updater', 'maintenanceActive', function() use($log) {
550 550
 			$log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
551 551
 		});
552
-		$this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
552
+		$this->listen('\OC\Updater', 'updateEnd', function($success) use($log) {
553 553
 			if ($success) {
554 554
 				$log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
555 555
 			} else {
556 556
 				$log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
557 557
 			}
558 558
 		});
559
-		$this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
559
+		$this->listen('\OC\Updater', 'dbUpgradeBefore', function() use($log) {
560 560
 			$log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
561 561
 		});
562
-		$this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
562
+		$this->listen('\OC\Updater', 'dbUpgrade', function() use($log) {
563 563
 			$log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
564 564
 		});
565
-		$this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
565
+		$this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($log) {
566 566
 			$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']);
567 567
 		});
568
-		$this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
568
+		$this->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($log) {
569 569
 			$log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
570 570
 		});
571
-		$this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
572
-			$log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
571
+		$this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($log) {
572
+			$log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']);
573 573
 		});
574
-		$this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) {
575
-			$log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']);
574
+		$this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($log) {
575
+			$log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']);
576 576
 		});
577
-		$this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
578
-			$log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']);
577
+		$this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($log) {
578
+			$log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']);
579 579
 		});
580
-		$this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) {
581
-			$log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']);
580
+		$this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($log) {
581
+			$log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']);
582 582
 		});
583
-		$this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
583
+		$this->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($log) {
584 584
 			$log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
585 585
 		});
586
-		$this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
587
-			$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']);
586
+		$this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) {
587
+			$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']);
588 588
 		});
589
-		$this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
589
+		$this->listen('\OC\Updater', 'appUpgradeCheck', function() use ($log) {
590 590
 			$log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
591 591
 		});
592
-		$this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
593
-			$log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
592
+		$this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) {
593
+			$log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']);
594 594
 		});
595
-		$this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
596
-			$log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
595
+		$this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) {
596
+			$log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']);
597 597
 		});
598
-		$this->listen('\OC\Updater', 'failure', function ($message) use($log) {
599
-			$log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
598
+		$this->listen('\OC\Updater', 'failure', function($message) use($log) {
599
+			$log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']);
600 600
 		});
601
-		$this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
601
+		$this->listen('\OC\Updater', 'setDebugLogLevel', function() use($log) {
602 602
 			$log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
603 603
 		});
604
-		$this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
605
-			$log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
604
+		$this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($log) {
605
+			$log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']);
606 606
 		});
607
-		$this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
607
+		$this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($log) {
608 608
 			$log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
609 609
 		});
610
-		$this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
610
+		$this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($log) {
611 611
 			$log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
612 612
 		});
613 613
 
Please login to merge, or discard this patch.