Completed
Pull Request — master (#10069)
by
unknown
18:05
created
core/Command/Maintenance/Mode.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -32,54 +32,54 @@
 block discarded – undo
32 32
 
33 33
 class Mode extends Command {
34 34
 
35
-	/** @var IConfig */
36
-	protected $config;
35
+    /** @var IConfig */
36
+    protected $config;
37 37
 
38
-	public function __construct(IConfig $config) {
39
-		$this->config = $config;
40
-		parent::__construct();
41
-	}
38
+    public function __construct(IConfig $config) {
39
+        $this->config = $config;
40
+        parent::__construct();
41
+    }
42 42
 
43
-	protected function configure() {
44
-		$this
45
-			->setName('maintenance:mode')
46
-			->setDescription('set maintenance mode')
47
-			->addOption(
48
-				'on',
49
-				null,
50
-				InputOption::VALUE_NONE,
51
-				'enable maintenance mode'
52
-			)
53
-			->addOption(
54
-				'off',
55
-				null,
56
-				InputOption::VALUE_NONE,
57
-				'disable maintenance mode'
58
-			);
59
-	}
43
+    protected function configure() {
44
+        $this
45
+            ->setName('maintenance:mode')
46
+            ->setDescription('set maintenance mode')
47
+            ->addOption(
48
+                'on',
49
+                null,
50
+                InputOption::VALUE_NONE,
51
+                'enable maintenance mode'
52
+            )
53
+            ->addOption(
54
+                'off',
55
+                null,
56
+                InputOption::VALUE_NONE,
57
+                'disable maintenance mode'
58
+            );
59
+    }
60 60
 
61
-	protected function execute(InputInterface $input, OutputInterface $output) {
62
-		$maintenanceMode = $this->config->getSystemValue('maintenance', false);
63
-		if ($input->getOption('on')) {
64
-			if ($maintenanceMode === false) {
65
-				$this->config->setSystemValue('maintenance', true);
66
-				$output->writeln('Maintenance mode enabled');
67
-			} else {
68
-				$output->writeln('Maintenance mode already enabled');
69
-			}
70
-		} elseif ($input->getOption('off')) {
71
-			if ($maintenanceMode === true) {
72
-				$this->config->setSystemValue('maintenance', false);
73
-				$output->writeln('Maintenance mode disabled');
74
-			} else {
75
-				$output->writeln('Maintenance mode already disabled');
76
-			}
77
-		} else {
78
-			if ($maintenanceMode) {
79
-				$output->writeln('Maintenance mode is currently enabled');
80
-			} else {
81
-				$output->writeln('Maintenance mode is currently disabled');
82
-			}
83
-		}
84
-	}
61
+    protected function execute(InputInterface $input, OutputInterface $output) {
62
+        $maintenanceMode = $this->config->getSystemValue('maintenance', false);
63
+        if ($input->getOption('on')) {
64
+            if ($maintenanceMode === false) {
65
+                $this->config->setSystemValue('maintenance', true);
66
+                $output->writeln('Maintenance mode enabled');
67
+            } else {
68
+                $output->writeln('Maintenance mode already enabled');
69
+            }
70
+        } elseif ($input->getOption('off')) {
71
+            if ($maintenanceMode === true) {
72
+                $this->config->setSystemValue('maintenance', false);
73
+                $output->writeln('Maintenance mode disabled');
74
+            } else {
75
+                $output->writeln('Maintenance mode already disabled');
76
+            }
77
+        } else {
78
+            if ($maintenanceMode) {
79
+                $output->writeln('Maintenance mode is currently enabled');
80
+            } else {
81
+                $output->writeln('Maintenance mode is currently disabled');
82
+            }
83
+        }
84
+    }
85 85
 }
Please login to merge, or discard this patch.
lib/private/Console/Application.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -44,171 +44,171 @@
 block discarded – undo
44 44
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
45 45
 
46 46
 class Application {
47
-	/** @var IConfig */
48
-	private $config;
49
-	/** @var EventDispatcherInterface */
50
-	private $dispatcher;
51
-	/** @var IRequest */
52
-	private $request;
53
-	/** @var ILogger  */
54
-	private $logger;
47
+    /** @var IConfig */
48
+    private $config;
49
+    /** @var EventDispatcherInterface */
50
+    private $dispatcher;
51
+    /** @var IRequest */
52
+    private $request;
53
+    /** @var ILogger  */
54
+    private $logger;
55 55
 
56
-	/**
57
-	 * @param IConfig $config
58
-	 * @param EventDispatcherInterface $dispatcher
59
-	 * @param IRequest $request
60
-	 * @param ILogger $logger
61
-	 */
62
-	public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) {
63
-		$defaults = \OC::$server->getThemingDefaults();
64
-		$this->config = $config;
65
-		$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
66
-		$this->dispatcher = $dispatcher;
67
-		$this->request = $request;
68
-		$this->logger = $logger;
69
-	}
56
+    /**
57
+     * @param IConfig $config
58
+     * @param EventDispatcherInterface $dispatcher
59
+     * @param IRequest $request
60
+     * @param ILogger $logger
61
+     */
62
+    public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) {
63
+        $defaults = \OC::$server->getThemingDefaults();
64
+        $this->config = $config;
65
+        $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
66
+        $this->dispatcher = $dispatcher;
67
+        $this->request = $request;
68
+        $this->logger = $logger;
69
+    }
70 70
 
71
-	/**
72
-	 * @param InputInterface $input
73
-	 * @param ConsoleOutputInterface $output
74
-	 * @throws \Exception
75
-	 */
76
-	public function loadCommands(
77
-		InputInterface $input,
78
-		ConsoleOutputInterface $output
79
-	) {
80
-		// $application is required to be defined in the register_command scripts
81
-		$application = $this->application;
82
-		$inputDefinition = $application->getDefinition();
83
-		$inputDefinition->addOption(
84
-			new InputOption(
85
-				'no-warnings', 
86
-				null, 
87
-				InputOption::VALUE_NONE, 
88
-				'Skip global warnings, show command output only', 
89
-				null
90
-			)
91
-		);
92
-		try {
93
-			$input->bind($inputDefinition);
94
-		} catch (\RuntimeException $e) {
95
-			//expected if there are extra options
96
-		}
97
-		if ($input->getOption('no-warnings')) {
98
-			$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
99
-		}
100
-		try {
101
-			require_once __DIR__ . '/../../../core/register_command.php';
102
-			if ($this->config->getSystemValue('installed', false)) {
103
-				if (\OCP\Util::needUpgrade()) {
104
-					throw new NeedsUpdateException();
105
-				} elseif ($this->config->getSystemValue('maintenance', false)) {
106
-					$this->writeMaintenanceModeInfo($input, $output);
107
-				} else {
108
-					OC_App::loadApps();
109
-					foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
110
-						$appPath = \OC_App::getAppPath($app);
111
-						if ($appPath === false) {
112
-							continue;
113
-						}
114
-						// load commands using info.xml
115
-						$info = \OC_App::getAppInfo($app);
116
-						if (isset($info['commands'])) {
117
-							$this->loadCommandsFromInfoXml($info['commands']);
118
-						}
119
-						// load from register_command.php
120
-						\OC_App::registerAutoloading($app, $appPath);
121
-						$file = $appPath . '/appinfo/register_command.php';
122
-						if (file_exists($file)) {
123
-							try {
124
-								require $file;
125
-							} catch (\Exception $e) {
126
-								$this->logger->logException($e);
127
-							}
128
-						}
129
-					}
130
-				}
131
-			} else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
132
-				$output->writeln("Nextcloud is not installed - only a limited number of commands are available");
133
-			}
134
-		} catch(NeedsUpdateException $e) {
135
-			if ($input->getArgument('command') !== '_completion') {
136
-				$output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
137
-				$output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
138
-			}
139
-		}
71
+    /**
72
+     * @param InputInterface $input
73
+     * @param ConsoleOutputInterface $output
74
+     * @throws \Exception
75
+     */
76
+    public function loadCommands(
77
+        InputInterface $input,
78
+        ConsoleOutputInterface $output
79
+    ) {
80
+        // $application is required to be defined in the register_command scripts
81
+        $application = $this->application;
82
+        $inputDefinition = $application->getDefinition();
83
+        $inputDefinition->addOption(
84
+            new InputOption(
85
+                'no-warnings', 
86
+                null, 
87
+                InputOption::VALUE_NONE, 
88
+                'Skip global warnings, show command output only', 
89
+                null
90
+            )
91
+        );
92
+        try {
93
+            $input->bind($inputDefinition);
94
+        } catch (\RuntimeException $e) {
95
+            //expected if there are extra options
96
+        }
97
+        if ($input->getOption('no-warnings')) {
98
+            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
99
+        }
100
+        try {
101
+            require_once __DIR__ . '/../../../core/register_command.php';
102
+            if ($this->config->getSystemValue('installed', false)) {
103
+                if (\OCP\Util::needUpgrade()) {
104
+                    throw new NeedsUpdateException();
105
+                } elseif ($this->config->getSystemValue('maintenance', false)) {
106
+                    $this->writeMaintenanceModeInfo($input, $output);
107
+                } else {
108
+                    OC_App::loadApps();
109
+                    foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
110
+                        $appPath = \OC_App::getAppPath($app);
111
+                        if ($appPath === false) {
112
+                            continue;
113
+                        }
114
+                        // load commands using info.xml
115
+                        $info = \OC_App::getAppInfo($app);
116
+                        if (isset($info['commands'])) {
117
+                            $this->loadCommandsFromInfoXml($info['commands']);
118
+                        }
119
+                        // load from register_command.php
120
+                        \OC_App::registerAutoloading($app, $appPath);
121
+                        $file = $appPath . '/appinfo/register_command.php';
122
+                        if (file_exists($file)) {
123
+                            try {
124
+                                require $file;
125
+                            } catch (\Exception $e) {
126
+                                $this->logger->logException($e);
127
+                            }
128
+                        }
129
+                    }
130
+                }
131
+            } else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
132
+                $output->writeln("Nextcloud is not installed - only a limited number of commands are available");
133
+            }
134
+        } catch(NeedsUpdateException $e) {
135
+            if ($input->getArgument('command') !== '_completion') {
136
+                $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
137
+                $output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
138
+            }
139
+        }
140 140
 
141
-		if ($input->getFirstArgument() !== 'check') {
142
-			$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
143
-			if (!empty($errors)) {
144
-				foreach ($errors as $error) {
145
-					$output->writeln((string)$error['error']);
146
-					$output->writeln((string)$error['hint']);
147
-					$output->writeln('');
148
-				}
149
-				throw new \Exception("Environment not properly prepared.");
150
-			}
151
-		}
152
-	}
141
+        if ($input->getFirstArgument() !== 'check') {
142
+            $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
143
+            if (!empty($errors)) {
144
+                foreach ($errors as $error) {
145
+                    $output->writeln((string)$error['error']);
146
+                    $output->writeln((string)$error['hint']);
147
+                    $output->writeln('');
148
+                }
149
+                throw new \Exception("Environment not properly prepared.");
150
+            }
151
+        }
152
+    }
153 153
 
154
-	/**
155
-	 * Write a maintenance mode info.
156
-	 * The commands "_completion" and "maintenance:mode" are excluded.
157
-	 *
158
-	 * @param InputInterface $input The input implementation for reading inputs.
159
-	 * @param ConsoleOutputInterface $output The output implementation
160
-	 * for writing outputs.
161
-	 * @return void
162
-	 */
163
-	private function writeMaintenanceModeInfo(
164
-		InputInterface $input, ConsoleOutputInterface $output
165
-	) {
166
-		if ($input->getArgument('command') !== '_completion'
167
-			&& $input->getArgument('command') !== 'maintenance:mode') {
168
-			$errOutput = $output->getErrorOutput();
169
-			$errOutput->writeln(
170
-				'<comment>Nextcloud is in maintenance mode - ' .
171
-				'no apps have been loaded</comment>' . PHP_EOL
172
-			);
173
-		}
174
-	}
154
+    /**
155
+     * Write a maintenance mode info.
156
+     * The commands "_completion" and "maintenance:mode" are excluded.
157
+     *
158
+     * @param InputInterface $input The input implementation for reading inputs.
159
+     * @param ConsoleOutputInterface $output The output implementation
160
+     * for writing outputs.
161
+     * @return void
162
+     */
163
+    private function writeMaintenanceModeInfo(
164
+        InputInterface $input, ConsoleOutputInterface $output
165
+    ) {
166
+        if ($input->getArgument('command') !== '_completion'
167
+            && $input->getArgument('command') !== 'maintenance:mode') {
168
+            $errOutput = $output->getErrorOutput();
169
+            $errOutput->writeln(
170
+                '<comment>Nextcloud is in maintenance mode - ' .
171
+                'no apps have been loaded</comment>' . PHP_EOL
172
+            );
173
+        }
174
+    }
175 175
 
176
-	/**
177
-	 * Sets whether to automatically exit after a command execution or not.
178
-	 *
179
-	 * @param bool $boolean Whether to automatically exit after a command execution or not
180
-	 */
181
-	public function setAutoExit($boolean) {
182
-		$this->application->setAutoExit($boolean);
183
-	}
176
+    /**
177
+     * Sets whether to automatically exit after a command execution or not.
178
+     *
179
+     * @param bool $boolean Whether to automatically exit after a command execution or not
180
+     */
181
+    public function setAutoExit($boolean) {
182
+        $this->application->setAutoExit($boolean);
183
+    }
184 184
 
185
-	/**
186
-	 * @param InputInterface $input
187
-	 * @param OutputInterface $output
188
-	 * @return int
189
-	 * @throws \Exception
190
-	 */
191
-	public function run(InputInterface $input = null, OutputInterface $output = null) {
192
-		$this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
193
-			ConsoleEvent::EVENT_RUN,
194
-			$this->request->server['argv']
195
-		));
196
-		return $this->application->run($input, $output);
197
-	}
185
+    /**
186
+     * @param InputInterface $input
187
+     * @param OutputInterface $output
188
+     * @return int
189
+     * @throws \Exception
190
+     */
191
+    public function run(InputInterface $input = null, OutputInterface $output = null) {
192
+        $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
193
+            ConsoleEvent::EVENT_RUN,
194
+            $this->request->server['argv']
195
+        ));
196
+        return $this->application->run($input, $output);
197
+    }
198 198
 
199
-	private function loadCommandsFromInfoXml($commands) {
200
-		foreach ($commands as $command) {
201
-			try {
202
-				$c = \OC::$server->query($command);
203
-			} catch (QueryException $e) {
204
-				if (class_exists($command)) {
205
-					$c = new $command();
206
-				} else {
207
-					throw new \Exception("Console command '$command' is unknown and could not be loaded");
208
-				}
209
-			}
199
+    private function loadCommandsFromInfoXml($commands) {
200
+        foreach ($commands as $command) {
201
+            try {
202
+                $c = \OC::$server->query($command);
203
+            } catch (QueryException $e) {
204
+                if (class_exists($command)) {
205
+                    $c = new $command();
206
+                } else {
207
+                    throw new \Exception("Console command '$command' is unknown and could not be loaded");
208
+                }
209
+            }
210 210
 
211
-			$this->application->add($c);
212
-		}
213
-	}
211
+            $this->application->add($c);
212
+        }
213
+    }
214 214
 }
Please login to merge, or discard this patch.