@@ -40,149 +40,149 @@ |
||
40 | 40 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
41 | 41 | |
42 | 42 | class Application { |
43 | - /** @var IConfig */ |
|
44 | - private $config; |
|
45 | - /** @var EventDispatcherInterface */ |
|
46 | - private $dispatcher; |
|
47 | - /** @var IRequest */ |
|
48 | - private $request; |
|
49 | - /** @var ILogger */ |
|
50 | - private $logger; |
|
43 | + /** @var IConfig */ |
|
44 | + private $config; |
|
45 | + /** @var EventDispatcherInterface */ |
|
46 | + private $dispatcher; |
|
47 | + /** @var IRequest */ |
|
48 | + private $request; |
|
49 | + /** @var ILogger */ |
|
50 | + private $logger; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param IConfig $config |
|
54 | - * @param EventDispatcherInterface $dispatcher |
|
55 | - * @param IRequest $request |
|
56 | - * @param ILogger $logger |
|
57 | - */ |
|
58 | - public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) { |
|
59 | - $defaults = \OC::$server->getThemingDefaults(); |
|
60 | - $this->config = $config; |
|
61 | - $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); |
|
62 | - $this->dispatcher = $dispatcher; |
|
63 | - $this->request = $request; |
|
64 | - $this->logger = $logger; |
|
65 | - } |
|
52 | + /** |
|
53 | + * @param IConfig $config |
|
54 | + * @param EventDispatcherInterface $dispatcher |
|
55 | + * @param IRequest $request |
|
56 | + * @param ILogger $logger |
|
57 | + */ |
|
58 | + public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) { |
|
59 | + $defaults = \OC::$server->getThemingDefaults(); |
|
60 | + $this->config = $config; |
|
61 | + $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); |
|
62 | + $this->dispatcher = $dispatcher; |
|
63 | + $this->request = $request; |
|
64 | + $this->logger = $logger; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param InputInterface $input |
|
69 | - * @param OutputInterface $output |
|
70 | - * @throws \Exception |
|
71 | - */ |
|
72 | - public function loadCommands(InputInterface $input, OutputInterface $output) { |
|
73 | - // $application is required to be defined in the register_command scripts |
|
74 | - $application = $this->application; |
|
75 | - $inputDefinition = $application->getDefinition(); |
|
76 | - $inputDefinition->addOption( |
|
77 | - new InputOption( |
|
78 | - 'no-warnings', |
|
79 | - null, |
|
80 | - InputOption::VALUE_NONE, |
|
81 | - 'Skip global warnings, show command output only', |
|
82 | - null |
|
83 | - ) |
|
84 | - ); |
|
85 | - try { |
|
86 | - $input->bind($inputDefinition); |
|
87 | - } catch (\RuntimeException $e) { |
|
88 | - //expected if there are extra options |
|
89 | - } |
|
90 | - if ($input->getOption('no-warnings')) { |
|
91 | - $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
|
92 | - } |
|
93 | - try { |
|
94 | - require_once __DIR__ . '/../../../core/register_command.php'; |
|
95 | - if ($this->config->getSystemValue('installed', false)) { |
|
96 | - if (\OCP\Util::needUpgrade()) { |
|
97 | - throw new NeedsUpdateException(); |
|
98 | - } elseif ($this->config->getSystemValue('maintenance', false)) { |
|
99 | - if ($input->getArgument('command') !== '_completion') { |
|
100 | - $errOutput = $output->getErrorOutput(); |
|
101 | - $errOutput->writeln('<comment>Nextcloud is in maintenance mode - no apps have been loaded</comment>' . PHP_EOL); |
|
102 | - } |
|
103 | - } else { |
|
104 | - OC_App::loadApps(); |
|
105 | - foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { |
|
106 | - $appPath = \OC_App::getAppPath($app); |
|
107 | - if ($appPath === false) { |
|
108 | - continue; |
|
109 | - } |
|
110 | - // load commands using info.xml |
|
111 | - $info = \OC_App::getAppInfo($app); |
|
112 | - if (isset($info['commands'])) { |
|
113 | - $this->loadCommandsFromInfoXml($info['commands']); |
|
114 | - } |
|
115 | - // load from register_command.php |
|
116 | - \OC_App::registerAutoloading($app, $appPath); |
|
117 | - $file = $appPath . '/appinfo/register_command.php'; |
|
118 | - if (file_exists($file)) { |
|
119 | - try { |
|
120 | - require $file; |
|
121 | - } catch (\Exception $e) { |
|
122 | - $this->logger->logException($e); |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
127 | - } else if ($input->getArgument('command') !== '_completion') { |
|
128 | - $output->writeln("Nextcloud is not installed - only a limited number of commands are available"); |
|
129 | - } |
|
130 | - } catch(NeedsUpdateException $e) { |
|
131 | - if ($input->getArgument('command') !== '_completion') { |
|
132 | - $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); |
|
133 | - $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); |
|
134 | - } |
|
135 | - } |
|
67 | + /** |
|
68 | + * @param InputInterface $input |
|
69 | + * @param OutputInterface $output |
|
70 | + * @throws \Exception |
|
71 | + */ |
|
72 | + public function loadCommands(InputInterface $input, OutputInterface $output) { |
|
73 | + // $application is required to be defined in the register_command scripts |
|
74 | + $application = $this->application; |
|
75 | + $inputDefinition = $application->getDefinition(); |
|
76 | + $inputDefinition->addOption( |
|
77 | + new InputOption( |
|
78 | + 'no-warnings', |
|
79 | + null, |
|
80 | + InputOption::VALUE_NONE, |
|
81 | + 'Skip global warnings, show command output only', |
|
82 | + null |
|
83 | + ) |
|
84 | + ); |
|
85 | + try { |
|
86 | + $input->bind($inputDefinition); |
|
87 | + } catch (\RuntimeException $e) { |
|
88 | + //expected if there are extra options |
|
89 | + } |
|
90 | + if ($input->getOption('no-warnings')) { |
|
91 | + $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
|
92 | + } |
|
93 | + try { |
|
94 | + require_once __DIR__ . '/../../../core/register_command.php'; |
|
95 | + if ($this->config->getSystemValue('installed', false)) { |
|
96 | + if (\OCP\Util::needUpgrade()) { |
|
97 | + throw new NeedsUpdateException(); |
|
98 | + } elseif ($this->config->getSystemValue('maintenance', false)) { |
|
99 | + if ($input->getArgument('command') !== '_completion') { |
|
100 | + $errOutput = $output->getErrorOutput(); |
|
101 | + $errOutput->writeln('<comment>Nextcloud is in maintenance mode - no apps have been loaded</comment>' . PHP_EOL); |
|
102 | + } |
|
103 | + } else { |
|
104 | + OC_App::loadApps(); |
|
105 | + foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { |
|
106 | + $appPath = \OC_App::getAppPath($app); |
|
107 | + if ($appPath === false) { |
|
108 | + continue; |
|
109 | + } |
|
110 | + // load commands using info.xml |
|
111 | + $info = \OC_App::getAppInfo($app); |
|
112 | + if (isset($info['commands'])) { |
|
113 | + $this->loadCommandsFromInfoXml($info['commands']); |
|
114 | + } |
|
115 | + // load from register_command.php |
|
116 | + \OC_App::registerAutoloading($app, $appPath); |
|
117 | + $file = $appPath . '/appinfo/register_command.php'; |
|
118 | + if (file_exists($file)) { |
|
119 | + try { |
|
120 | + require $file; |
|
121 | + } catch (\Exception $e) { |
|
122 | + $this->logger->logException($e); |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | + } else if ($input->getArgument('command') !== '_completion') { |
|
128 | + $output->writeln("Nextcloud is not installed - only a limited number of commands are available"); |
|
129 | + } |
|
130 | + } catch(NeedsUpdateException $e) { |
|
131 | + if ($input->getArgument('command') !== '_completion') { |
|
132 | + $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); |
|
133 | + $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - if ($input->getFirstArgument() !== 'check') { |
|
138 | - $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
139 | - if (!empty($errors)) { |
|
140 | - foreach ($errors as $error) { |
|
141 | - $output->writeln((string)$error['error']); |
|
142 | - $output->writeln((string)$error['hint']); |
|
143 | - $output->writeln(''); |
|
144 | - } |
|
145 | - throw new \Exception("Environment not properly prepared."); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
137 | + if ($input->getFirstArgument() !== 'check') { |
|
138 | + $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
139 | + if (!empty($errors)) { |
|
140 | + foreach ($errors as $error) { |
|
141 | + $output->writeln((string)$error['error']); |
|
142 | + $output->writeln((string)$error['hint']); |
|
143 | + $output->writeln(''); |
|
144 | + } |
|
145 | + throw new \Exception("Environment not properly prepared."); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Sets whether to automatically exit after a command execution or not. |
|
152 | - * |
|
153 | - * @param bool $boolean Whether to automatically exit after a command execution or not |
|
154 | - */ |
|
155 | - public function setAutoExit($boolean) { |
|
156 | - $this->application->setAutoExit($boolean); |
|
157 | - } |
|
150 | + /** |
|
151 | + * Sets whether to automatically exit after a command execution or not. |
|
152 | + * |
|
153 | + * @param bool $boolean Whether to automatically exit after a command execution or not |
|
154 | + */ |
|
155 | + public function setAutoExit($boolean) { |
|
156 | + $this->application->setAutoExit($boolean); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @param InputInterface $input |
|
161 | - * @param OutputInterface $output |
|
162 | - * @return int |
|
163 | - * @throws \Exception |
|
164 | - */ |
|
165 | - public function run(InputInterface $input = null, OutputInterface $output = null) { |
|
166 | - $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent( |
|
167 | - ConsoleEvent::EVENT_RUN, |
|
168 | - $this->request->server['argv'] |
|
169 | - )); |
|
170 | - return $this->application->run($input, $output); |
|
171 | - } |
|
159 | + /** |
|
160 | + * @param InputInterface $input |
|
161 | + * @param OutputInterface $output |
|
162 | + * @return int |
|
163 | + * @throws \Exception |
|
164 | + */ |
|
165 | + public function run(InputInterface $input = null, OutputInterface $output = null) { |
|
166 | + $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent( |
|
167 | + ConsoleEvent::EVENT_RUN, |
|
168 | + $this->request->server['argv'] |
|
169 | + )); |
|
170 | + return $this->application->run($input, $output); |
|
171 | + } |
|
172 | 172 | |
173 | - private function loadCommandsFromInfoXml($commands) { |
|
174 | - foreach ($commands as $command) { |
|
175 | - try { |
|
176 | - $c = \OC::$server->query($command); |
|
177 | - } catch (QueryException $e) { |
|
178 | - if (class_exists($command)) { |
|
179 | - $c = new $command(); |
|
180 | - } else { |
|
181 | - throw new \Exception("Console command '$command' is unknown and could not be loaded"); |
|
182 | - } |
|
183 | - } |
|
173 | + private function loadCommandsFromInfoXml($commands) { |
|
174 | + foreach ($commands as $command) { |
|
175 | + try { |
|
176 | + $c = \OC::$server->query($command); |
|
177 | + } catch (QueryException $e) { |
|
178 | + if (class_exists($command)) { |
|
179 | + $c = new $command(); |
|
180 | + } else { |
|
181 | + throw new \Exception("Console command '$command' is unknown and could not be loaded"); |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - $this->application->add($c); |
|
186 | - } |
|
187 | - } |
|
185 | + $this->application->add($c); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | } |