diff options
Diffstat (limited to 'lib/private/Console')
-rw-r--r-- | lib/private/Console/Application.php | 51 | ||||
-rw-r--r-- | lib/private/Console/TimestampFormatter.php | 12 |
2 files changed, 35 insertions, 28 deletions
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 14baa528940..4cf1e0da8ca 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -7,14 +7,19 @@ */ namespace OC\Console; +use ArgumentCountError; use OC\MemoryInfo; use OC\NeedsUpdateException; +use OC\SystemConfig; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\Console\ConsoleEvent; +use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IRequest; +use OCP\Server; +use OCP\ServerVersion; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; @@ -27,15 +32,16 @@ class Application { private SymfonyApplication $application; public function __construct( + ServerVersion $serverVersion, private IConfig $config, private IEventDispatcher $dispatcher, private IRequest $request, private LoggerInterface $logger, private MemoryInfo $memoryInfo, private IAppManager $appManager, + private Defaults $defaults, ) { - $defaults = \OC::$server->get('ThemingDefaults'); - $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); + $this->application = new SymfonyApplication($defaults->getName(), $serverVersion->getVersionString()); } /** @@ -43,8 +49,8 @@ class Application { */ public function loadCommands( InputInterface $input, - ConsoleOutputInterface $output - ) { + ConsoleOutputInterface $output, + ): void { // $application is required to be defined in the register_command scripts $application = $this->application; $inputDefinition = $application->getDefinition(); @@ -68,8 +74,8 @@ class Application { if ($this->memoryInfo->isMemoryLimitSufficient() === false) { $output->getErrorOutput()->writeln( - '<comment>The current PHP memory limit ' . - 'is below the recommended value of 512MB.</comment>' + '<comment>The current PHP memory limit ' + . 'is below the recommended value of 512MB.</comment>' ); } @@ -82,7 +88,7 @@ class Application { $this->writeMaintenanceModeInfo($input, $output); } else { $this->appManager->loadApps(); - foreach ($this->appManager->getInstalledApps() as $app) { + foreach ($this->appManager->getEnabledApps() as $app) { try { $appPath = $this->appManager->getAppPath($app); } catch (AppPathNotFoundException) { @@ -94,7 +100,7 @@ class Application { try { $this->loadCommandsFromInfoXml($info['commands']); } catch (\Throwable $e) { - $output->writeln("<error>" . $e->getMessage() . "</error>"); + $output->writeln('<error>' . $e->getMessage() . '</error>'); $this->logger->error($e->getMessage(), [ 'exception' => $e, ]); @@ -116,25 +122,25 @@ class Application { } } elseif ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') { $errorOutput = $output->getErrorOutput(); - $errorOutput->writeln("Nextcloud is not installed - only a limited number of commands are available"); + $errorOutput->writeln('Nextcloud is not installed - only a limited number of commands are available'); } - } catch (NeedsUpdateException $e) { - if ($input->getArgument('command') !== '_completion') { + } catch (NeedsUpdateException) { + if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'upgrade') { $errorOutput = $output->getErrorOutput(); - $errorOutput->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); - $errorOutput->writeln("You may use your browser or the occ upgrade command to do the upgrade"); + $errorOutput->writeln('Nextcloud or one of the apps require upgrade - only a limited number of commands are available'); + $errorOutput->writeln('You may use your browser or the occ upgrade command to do the upgrade'); } } if ($input->getFirstArgument() !== 'check') { - $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); + $errors = \OC_Util::checkServer(Server::get(SystemConfig::class)); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string)$error['error']); $output->writeln((string)$error['hint']); $output->writeln(''); } - throw new \Exception("Environment not properly prepared."); + throw new \Exception('Environment not properly prepared.'); } } } @@ -145,7 +151,7 @@ class Application { * * @param InputInterface $input The input implementation for reading inputs. * @param ConsoleOutputInterface $output The output implementation - * for writing outputs. + * for writing outputs. * @return void */ private function writeMaintenanceModeInfo(InputInterface $input, ConsoleOutputInterface $output): void { @@ -163,13 +169,11 @@ class Application { * * @param bool $boolean Whether to automatically exit after a command execution or not */ - public function setAutoExit($boolean) { + public function setAutoExit(bool $boolean): void { $this->application->setAutoExit($boolean); } /** - * @param InputInterface $input - * @param OutputInterface $output * @return int * @throws \Exception */ @@ -183,15 +187,18 @@ class Application { return $this->application->run($input, $output); } - private function loadCommandsFromInfoXml($commands) { + /** + * @throws \Exception + */ + private function loadCommandsFromInfoXml(iterable $commands): void { foreach ($commands as $command) { try { - $c = \OCP\Server::get($command); + $c = Server::get($command); } catch (ContainerExceptionInterface $e) { if (class_exists($command)) { try { $c = new $command(); - } catch (\ArgumentCountError $e2) { + } catch (ArgumentCountError) { throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e); } } else { diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index de0675cc5df..e8d9eef6b16 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -32,7 +32,7 @@ class TimestampFormatter implements OutputFormatterInterface { * * @param bool $decorated Whether to decorate the messages or not */ - public function setDecorated($decorated) { + public function setDecorated(bool $decorated) { $this->formatter->setDecorated($decorated); } @@ -41,7 +41,7 @@ class TimestampFormatter implements OutputFormatterInterface { * * @return bool true if the output will decorate messages, false otherwise */ - public function isDecorated() { + public function isDecorated(): bool { return $this->formatter->isDecorated(); } @@ -51,7 +51,7 @@ class TimestampFormatter implements OutputFormatterInterface { * @param string $name The style name * @param OutputFormatterStyleInterface $style The style instance */ - public function setStyle($name, OutputFormatterStyleInterface $style) { + public function setStyle(string $name, OutputFormatterStyleInterface $style) { $this->formatter->setStyle($name, $style); } @@ -61,7 +61,7 @@ class TimestampFormatter implements OutputFormatterInterface { * @param string $name * @return bool */ - public function hasStyle($name) { + public function hasStyle(string $name): bool { return $this->formatter->hasStyle($name); } @@ -72,7 +72,7 @@ class TimestampFormatter implements OutputFormatterInterface { * @return OutputFormatterStyleInterface * @throws \InvalidArgumentException When style isn't defined */ - public function getStyle($name) { + public function getStyle(string $name): OutputFormatterStyleInterface { return $this->formatter->getStyle($name); } @@ -81,7 +81,7 @@ class TimestampFormatter implements OutputFormatterInterface { * * @param string|null $message The message to style * @return string|null The styled message, prepended with a timestamp using the - * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" + * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" */ public function format(?string $message): ?string { if (!$this->formatter->isDecorated()) { |