aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Console/Application.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Console/Application.php')
-rw-r--r--lib/private/Console/Application.php51
1 files changed, 29 insertions, 22 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 {