Completed
Push — master ( 690881...a809aa )
by Lukas
14:29
created
core/Command/Upgrade.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -44,254 +44,254 @@
 block discarded – undo
44 44
 
45 45
 class Upgrade extends Command {
46 46
 
47
-	const ERROR_SUCCESS = 0;
48
-	const ERROR_NOT_INSTALLED = 1;
49
-	const ERROR_MAINTENANCE_MODE = 2;
50
-	const ERROR_UP_TO_DATE = 0;
51
-	const ERROR_INVALID_ARGUMENTS = 4;
52
-	const ERROR_FAILURE = 5;
47
+    const ERROR_SUCCESS = 0;
48
+    const ERROR_NOT_INSTALLED = 1;
49
+    const ERROR_MAINTENANCE_MODE = 2;
50
+    const ERROR_UP_TO_DATE = 0;
51
+    const ERROR_INVALID_ARGUMENTS = 4;
52
+    const ERROR_FAILURE = 5;
53 53
 
54
-	/** @var IConfig */
55
-	private $config;
54
+    /** @var IConfig */
55
+    private $config;
56 56
 
57
-	/** @var ILogger */
58
-	private $logger;
57
+    /** @var ILogger */
58
+    private $logger;
59 59
 
60
-	/**
61
-	 * @param IConfig $config
62
-	 * @param ILogger $logger
63
-	 */
64
-	public function __construct(IConfig $config, ILogger $logger) {
65
-		parent::__construct();
66
-		$this->config = $config;
67
-		$this->logger = $logger;
68
-	}
60
+    /**
61
+     * @param IConfig $config
62
+     * @param ILogger $logger
63
+     */
64
+    public function __construct(IConfig $config, ILogger $logger) {
65
+        parent::__construct();
66
+        $this->config = $config;
67
+        $this->logger = $logger;
68
+    }
69 69
 
70
-	protected function configure() {
71
-		$this
72
-			->setName('upgrade')
73
-			->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.')
74
-			->addOption(
75
-				'--no-app-disable',
76
-				null,
77
-				InputOption::VALUE_NONE,
78
-				'skips the disable of third party apps'
79
-			);
80
-	}
70
+    protected function configure() {
71
+        $this
72
+            ->setName('upgrade')
73
+            ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.')
74
+            ->addOption(
75
+                '--no-app-disable',
76
+                null,
77
+                InputOption::VALUE_NONE,
78
+                'skips the disable of third party apps'
79
+            );
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
-			);
97
+            $self = $this;
98
+            $updater = new Updater(
99
+                    $this->config,
100
+                    \OC::$server->getIntegrityCodeChecker(),
101
+                    $this->logger
102
+            );
103 103
 
104
-			if ($input->getOption('no-app-disable')) {
105
-				$updater->setSkip3rdPartyAppsDisable(true);
106
-			}
107
-			$dispatcher = \OC::$server->getEventDispatcher();
108
-			$progress = new ProgressBar($output);
109
-			$progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%");
110
-			$listener = function($event) use ($progress, $output) {
111
-				if ($event instanceof GenericEvent) {
112
-					$message = $event->getSubject();
113
-					if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
114
-						$output->writeln(' Checking table ' . $message);
115
-					} else {
116
-						if (strlen($message) > 60) {
117
-							$message = substr($message, 0, 57) . '...';
118
-						}
119
-						$progress->setMessage($message);
120
-						if ($event[0] === 1) {
121
-							$output->writeln('');
122
-							$progress->start($event[1]);
123
-						}
124
-						$progress->setProgress($event[0]);
125
-						if ($event[0] === $event[1]) {
126
-							$progress->setMessage('Done');
127
-							$progress->finish();
128
-							$output->writeln('');
129
-						}
130
-					}
131
-				}
132
-			};
133
-			$repairListener = function($event) use ($progress, $output) {
134
-				if (!$event instanceof GenericEvent) {
135
-					return;
136
-				}
137
-				switch ($event->getSubject()) {
138
-					case '\OC\Repair::startProgress':
139
-						$progress->setMessage('Starting ...');
140
-						$output->writeln($event->getArgument(1));
141
-						$output->writeln('');
142
-						$progress->start($event->getArgument(0));
143
-						break;
144
-					case '\OC\Repair::advance':
145
-						$desc = $event->getArgument(1);
146
-						if (!empty($desc)) {
147
-							$progress->setMessage($desc);
148
-						}
149
-						$progress->advance($event->getArgument(0));
104
+            if ($input->getOption('no-app-disable')) {
105
+                $updater->setSkip3rdPartyAppsDisable(true);
106
+            }
107
+            $dispatcher = \OC::$server->getEventDispatcher();
108
+            $progress = new ProgressBar($output);
109
+            $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%");
110
+            $listener = function($event) use ($progress, $output) {
111
+                if ($event instanceof GenericEvent) {
112
+                    $message = $event->getSubject();
113
+                    if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
114
+                        $output->writeln(' Checking table ' . $message);
115
+                    } else {
116
+                        if (strlen($message) > 60) {
117
+                            $message = substr($message, 0, 57) . '...';
118
+                        }
119
+                        $progress->setMessage($message);
120
+                        if ($event[0] === 1) {
121
+                            $output->writeln('');
122
+                            $progress->start($event[1]);
123
+                        }
124
+                        $progress->setProgress($event[0]);
125
+                        if ($event[0] === $event[1]) {
126
+                            $progress->setMessage('Done');
127
+                            $progress->finish();
128
+                            $output->writeln('');
129
+                        }
130
+                    }
131
+                }
132
+            };
133
+            $repairListener = function($event) use ($progress, $output) {
134
+                if (!$event instanceof GenericEvent) {
135
+                    return;
136
+                }
137
+                switch ($event->getSubject()) {
138
+                    case '\OC\Repair::startProgress':
139
+                        $progress->setMessage('Starting ...');
140
+                        $output->writeln($event->getArgument(1));
141
+                        $output->writeln('');
142
+                        $progress->start($event->getArgument(0));
143
+                        break;
144
+                    case '\OC\Repair::advance':
145
+                        $desc = $event->getArgument(1);
146
+                        if (!empty($desc)) {
147
+                            $progress->setMessage($desc);
148
+                        }
149
+                        $progress->advance($event->getArgument(0));
150 150
 
151
-						break;
152
-					case '\OC\Repair::finishProgress':
153
-						$progress->setMessage('Done');
154
-						$progress->finish();
155
-						$output->writeln('');
156
-						break;
157
-					case '\OC\Repair::step':
158
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
159
-							$output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>');
160
-						}
161
-						break;
162
-					case '\OC\Repair::info':
163
-						if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
164
-							$output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>');
165
-						}
166
-						break;
167
-					case '\OC\Repair::warning':
168
-						$output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>');
169
-						break;
170
-					case '\OC\Repair::error':
171
-						$output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>');
172
-						break;
173
-				}
174
-			};
151
+                        break;
152
+                    case '\OC\Repair::finishProgress':
153
+                        $progress->setMessage('Done');
154
+                        $progress->finish();
155
+                        $output->writeln('');
156
+                        break;
157
+                    case '\OC\Repair::step':
158
+                        if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
159
+                            $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>');
160
+                        }
161
+                        break;
162
+                    case '\OC\Repair::info':
163
+                        if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
164
+                            $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>');
165
+                        }
166
+                        break;
167
+                    case '\OC\Repair::warning':
168
+                        $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>');
169
+                        break;
170
+                    case '\OC\Repair::error':
171
+                        $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>');
172
+                        break;
173
+                }
174
+            };
175 175
 
176
-			$dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener);
177
-			$dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener);
178
-			$dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
179
-			$dispatcher->addListener('\OC\Repair::advance', $repairListener);
180
-			$dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
181
-			$dispatcher->addListener('\OC\Repair::step', $repairListener);
182
-			$dispatcher->addListener('\OC\Repair::info', $repairListener);
183
-			$dispatcher->addListener('\OC\Repair::warning', $repairListener);
184
-			$dispatcher->addListener('\OC\Repair::error', $repairListener);
176
+            $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener);
177
+            $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener);
178
+            $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
179
+            $dispatcher->addListener('\OC\Repair::advance', $repairListener);
180
+            $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
181
+            $dispatcher->addListener('\OC\Repair::step', $repairListener);
182
+            $dispatcher->addListener('\OC\Repair::info', $repairListener);
183
+            $dispatcher->addListener('\OC\Repair::warning', $repairListener);
184
+            $dispatcher->addListener('\OC\Repair::error', $repairListener);
185 185
 			
186 186
 
187
-			$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
188
-				$output->writeln('<info>Turned on maintenance mode</info>');
189
-			});
190
-			$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) {
191
-				$output->writeln('<info>Turned off maintenance mode</info>');
192
-			});
193
-			$updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
194
-				$output->writeln('<info>Maintenance mode is kept active</info>');
195
-			});
196
-			$updater->listen('\OC\Updater', 'updateEnd',
197
-				function ($success) use($output, $self) {
198
-					if ($success) {
199
-						$message = "<info>Update successful</info>";
200
-					} else {
201
-						$message = "<error>Update failed</error>";
202
-					}
203
-					$output->writeln($message);
204
-				});
205
-			$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) {
206
-				$output->writeln('<info>Updating database schema</info>');
207
-			});
208
-			$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
209
-				$output->writeln('<info>Updated database</info>');
210
-			});
211
-			$updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) {
212
-				$output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>');
213
-			});
214
-			$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
215
-				$output->writeln('<info>Checked database schema update</info>');
216
-			});
217
-			$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) {
218
-				$output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>');
219
-			});
220
-			$updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($output) {
221
-				$output->writeln('<comment>Disabled 3rd-party app: ' . $app . '</comment>');
222
-			});
223
-			$updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) {
224
-				$output->writeln('<info>Update 3rd-party app: ' . $app . '</info>');
225
-			});
226
-			$updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) {
227
-				$output->writeln('<info>Checking updates of apps</info>');
228
-			});
229
-			$updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) {
230
-				$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>");
231
-			});
232
-			$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) {
233
-				$output->writeln('<info>Checked database schema update for apps</info>');
234
-			});
235
-			$updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) {
236
-				$output->writeln("<info>Updating <$app> ...</info>");
237
-			});
238
-			$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) {
239
-				$output->writeln("<info>Updated <$app> to $version</info>");
240
-			});
241
-			$updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
242
-				$output->writeln("<error>$message</error>");
243
-			});
244
-			$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) {
245
-				$output->writeln("<info>Set log level to debug</info>");
246
-			});
247
-			$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) {
248
-				$output->writeln("<info>Reset log level</info>");
249
-			});
250
-			$updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) {
251
-				$output->writeln("<info>Starting code integrity check...</info>");
252
-			});
253
-			$updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) {
254
-				$output->writeln("<info>Finished code integrity check</info>");
255
-			});
187
+            $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
188
+                $output->writeln('<info>Turned on maintenance mode</info>');
189
+            });
190
+            $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) {
191
+                $output->writeln('<info>Turned off maintenance mode</info>');
192
+            });
193
+            $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
194
+                $output->writeln('<info>Maintenance mode is kept active</info>');
195
+            });
196
+            $updater->listen('\OC\Updater', 'updateEnd',
197
+                function ($success) use($output, $self) {
198
+                    if ($success) {
199
+                        $message = "<info>Update successful</info>";
200
+                    } else {
201
+                        $message = "<error>Update failed</error>";
202
+                    }
203
+                    $output->writeln($message);
204
+                });
205
+            $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) {
206
+                $output->writeln('<info>Updating database schema</info>');
207
+            });
208
+            $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
209
+                $output->writeln('<info>Updated database</info>');
210
+            });
211
+            $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) {
212
+                $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>');
213
+            });
214
+            $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
215
+                $output->writeln('<info>Checked database schema update</info>');
216
+            });
217
+            $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) {
218
+                $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>');
219
+            });
220
+            $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($output) {
221
+                $output->writeln('<comment>Disabled 3rd-party app: ' . $app . '</comment>');
222
+            });
223
+            $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) {
224
+                $output->writeln('<info>Update 3rd-party app: ' . $app . '</info>');
225
+            });
226
+            $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) {
227
+                $output->writeln('<info>Checking updates of apps</info>');
228
+            });
229
+            $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) {
230
+                $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>");
231
+            });
232
+            $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) {
233
+                $output->writeln('<info>Checked database schema update for apps</info>');
234
+            });
235
+            $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) {
236
+                $output->writeln("<info>Updating <$app> ...</info>");
237
+            });
238
+            $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) {
239
+                $output->writeln("<info>Updated <$app> to $version</info>");
240
+            });
241
+            $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
242
+                $output->writeln("<error>$message</error>");
243
+            });
244
+            $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) {
245
+                $output->writeln("<info>Set log level to debug</info>");
246
+            });
247
+            $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) {
248
+                $output->writeln("<info>Reset log level</info>");
249
+            });
250
+            $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) {
251
+                $output->writeln("<info>Starting code integrity check...</info>");
252
+            });
253
+            $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) {
254
+                $output->writeln("<info>Finished code integrity check</info>");
255
+            });
256 256
 
257
-			$success = $updater->upgrade();
257
+            $success = $updater->upgrade();
258 258
 
259
-			$this->postUpgradeCheck($input, $output);
259
+            $this->postUpgradeCheck($input, $output);
260 260
 
261
-			if(!$success) {
262
-				return self::ERROR_FAILURE;
263
-			}
261
+            if(!$success) {
262
+                return self::ERROR_FAILURE;
263
+            }
264 264
 
265
-			return self::ERROR_SUCCESS;
266
-		} else if($this->config->getSystemValue('maintenance', false)) {
267
-			//Possible scenario: Nextcloud core is updated but an app failed
268
-			$output->writeln('<warning>Nextcloud is in maintenance mode</warning>');
269
-			$output->write('<comment>Maybe an upgrade is already in process. Please check the '
270
-				. 'logfile (data/nextcloud.log). If you want to re-run the '
271
-				. 'upgrade procedure, remove the "maintenance mode" from '
272
-				. 'config.php and call this script again.</comment>'
273
-				, true);
274
-			return self::ERROR_MAINTENANCE_MODE;
275
-		} else {
276
-			$output->writeln('<info>Nextcloud is already latest version</info>');
277
-			return self::ERROR_UP_TO_DATE;
278
-		}
279
-	}
265
+            return self::ERROR_SUCCESS;
266
+        } else if($this->config->getSystemValue('maintenance', false)) {
267
+            //Possible scenario: Nextcloud core is updated but an app failed
268
+            $output->writeln('<warning>Nextcloud is in maintenance mode</warning>');
269
+            $output->write('<comment>Maybe an upgrade is already in process. Please check the '
270
+                . 'logfile (data/nextcloud.log). If you want to re-run the '
271
+                . 'upgrade procedure, remove the "maintenance mode" from '
272
+                . 'config.php and call this script again.</comment>'
273
+                , true);
274
+            return self::ERROR_MAINTENANCE_MODE;
275
+        } else {
276
+            $output->writeln('<info>Nextcloud is already latest version</info>');
277
+            return self::ERROR_UP_TO_DATE;
278
+        }
279
+    }
280 280
 
281
-	/**
282
-	 * Perform a post upgrade check (specific to the command line tool)
283
-	 *
284
-	 * @param InputInterface $input input interface
285
-	 * @param OutputInterface $output output interface
286
-	 */
287
-	protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
288
-		$trustedDomains = $this->config->getSystemValue('trusted_domains', array());
289
-		if (empty($trustedDomains)) {
290
-			$output->write(
291
-				'<warning>The setting "trusted_domains" could not be ' .
292
-				'set automatically by the upgrade script, ' .
293
-				'please set it manually</warning>'
294
-			);
295
-		}
296
-	}
281
+    /**
282
+     * Perform a post upgrade check (specific to the command line tool)
283
+     *
284
+     * @param InputInterface $input input interface
285
+     * @param OutputInterface $output output interface
286
+     */
287
+    protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) {
288
+        $trustedDomains = $this->config->getSystemValue('trusted_domains', array());
289
+        if (empty($trustedDomains)) {
290
+            $output->write(
291
+                '<warning>The setting "trusted_domains" could not be ' .
292
+                'set automatically by the upgrade script, ' .
293
+                'please set it manually</warning>'
294
+            );
295
+        }
296
+    }
297 297
 }
Please login to merge, or discard this patch.