@@ -35,74 +35,74 @@ |
||
35 | 35 | |
36 | 36 | class Disable extends Command implements CompletionAwareInterface { |
37 | 37 | |
38 | - /** @var IAppManager */ |
|
39 | - protected $appManager; |
|
38 | + /** @var IAppManager */ |
|
39 | + protected $appManager; |
|
40 | 40 | |
41 | - /** @var int */ |
|
42 | - protected $exitCode = 0; |
|
41 | + /** @var int */ |
|
42 | + protected $exitCode = 0; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param IAppManager $appManager |
|
46 | - */ |
|
47 | - public function __construct(IAppManager $appManager) { |
|
48 | - parent::__construct(); |
|
49 | - $this->appManager = $appManager; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @param IAppManager $appManager |
|
46 | + */ |
|
47 | + public function __construct(IAppManager $appManager) { |
|
48 | + parent::__construct(); |
|
49 | + $this->appManager = $appManager; |
|
50 | + } |
|
51 | 51 | |
52 | - protected function configure(): void { |
|
53 | - $this |
|
54 | - ->setName('app:disable') |
|
55 | - ->setDescription('disable an app') |
|
56 | - ->addArgument( |
|
57 | - 'app-id', |
|
58 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
59 | - 'disable the specified app' |
|
60 | - ); |
|
61 | - } |
|
52 | + protected function configure(): void { |
|
53 | + $this |
|
54 | + ->setName('app:disable') |
|
55 | + ->setDescription('disable an app') |
|
56 | + ->addArgument( |
|
57 | + 'app-id', |
|
58 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
59 | + 'disable the specified app' |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | - $appIds = $input->getArgument('app-id'); |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | + $appIds = $input->getArgument('app-id'); |
|
65 | 65 | |
66 | - foreach ($appIds as $appId) { |
|
67 | - $this->disableApp($appId, $output); |
|
68 | - } |
|
66 | + foreach ($appIds as $appId) { |
|
67 | + $this->disableApp($appId, $output); |
|
68 | + } |
|
69 | 69 | |
70 | - return $this->exitCode; |
|
71 | - } |
|
70 | + return $this->exitCode; |
|
71 | + } |
|
72 | 72 | |
73 | - private function disableApp(string $appId, OutputInterface $output): void { |
|
74 | - if ($this->appManager->isInstalled($appId) === false) { |
|
75 | - $output->writeln('No such app enabled: ' . $appId); |
|
76 | - return; |
|
77 | - } |
|
73 | + private function disableApp(string $appId, OutputInterface $output): void { |
|
74 | + if ($this->appManager->isInstalled($appId) === false) { |
|
75 | + $output->writeln('No such app enabled: ' . $appId); |
|
76 | + return; |
|
77 | + } |
|
78 | 78 | |
79 | - try { |
|
80 | - $this->appManager->disableApp($appId); |
|
81 | - $output->writeln($appId . ' disabled'); |
|
82 | - } catch (\Exception $e) { |
|
83 | - $output->writeln($e->getMessage()); |
|
84 | - $this->exitCode = 2; |
|
85 | - } |
|
86 | - } |
|
79 | + try { |
|
80 | + $this->appManager->disableApp($appId); |
|
81 | + $output->writeln($appId . ' disabled'); |
|
82 | + } catch (\Exception $e) { |
|
83 | + $output->writeln($e->getMessage()); |
|
84 | + $this->exitCode = 2; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param string $optionName |
|
90 | - * @param CompletionContext $context |
|
91 | - * @return string[] |
|
92 | - */ |
|
93 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
94 | - return []; |
|
95 | - } |
|
88 | + /** |
|
89 | + * @param string $optionName |
|
90 | + * @param CompletionContext $context |
|
91 | + * @return string[] |
|
92 | + */ |
|
93 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
94 | + return []; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param string $argumentName |
|
99 | - * @param CompletionContext $context |
|
100 | - * @return string[] |
|
101 | - */ |
|
102 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
103 | - if ($argumentName === 'app-id') { |
|
104 | - return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps()); |
|
105 | - } |
|
106 | - return []; |
|
107 | - } |
|
97 | + /** |
|
98 | + * @param string $argumentName |
|
99 | + * @param CompletionContext $context |
|
100 | + * @return string[] |
|
101 | + */ |
|
102 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
103 | + if ($argumentName === 'app-id') { |
|
104 | + return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps()); |
|
105 | + } |
|
106 | + return []; |
|
107 | + } |
|
108 | 108 | } |
@@ -33,55 +33,55 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class Install extends Command { |
36 | - protected function configure() { |
|
37 | - $this |
|
38 | - ->setName('app:install') |
|
39 | - ->setDescription('install an app') |
|
40 | - ->addArgument( |
|
41 | - 'app-id', |
|
42 | - InputArgument::REQUIRED, |
|
43 | - 'install the specified app' |
|
44 | - ) |
|
45 | - ->addOption( |
|
46 | - 'keep-disabled', |
|
47 | - null, |
|
48 | - InputOption::VALUE_NONE, |
|
49 | - 'don\'t enable the app afterwards' |
|
50 | - ) |
|
51 | - ; |
|
52 | - } |
|
36 | + protected function configure() { |
|
37 | + $this |
|
38 | + ->setName('app:install') |
|
39 | + ->setDescription('install an app') |
|
40 | + ->addArgument( |
|
41 | + 'app-id', |
|
42 | + InputArgument::REQUIRED, |
|
43 | + 'install the specified app' |
|
44 | + ) |
|
45 | + ->addOption( |
|
46 | + 'keep-disabled', |
|
47 | + null, |
|
48 | + InputOption::VALUE_NONE, |
|
49 | + 'don\'t enable the app afterwards' |
|
50 | + ) |
|
51 | + ; |
|
52 | + } |
|
53 | 53 | |
54 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | - $appId = $input->getArgument('app-id'); |
|
54 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | + $appId = $input->getArgument('app-id'); |
|
56 | 56 | |
57 | - if (\OC_App::getAppPath($appId)) { |
|
58 | - $output->writeln($appId . ' already installed'); |
|
59 | - return 1; |
|
60 | - } |
|
57 | + if (\OC_App::getAppPath($appId)) { |
|
58 | + $output->writeln($appId . ' already installed'); |
|
59 | + return 1; |
|
60 | + } |
|
61 | 61 | |
62 | - try { |
|
63 | - /** @var Installer $installer */ |
|
64 | - $installer = \OC::$server->query(Installer::class); |
|
65 | - $installer->downloadApp($appId); |
|
66 | - $result = $installer->installApp($appId); |
|
67 | - } catch (\Exception $e) { |
|
68 | - $output->writeln('Error: ' . $e->getMessage()); |
|
69 | - return 1; |
|
70 | - } |
|
62 | + try { |
|
63 | + /** @var Installer $installer */ |
|
64 | + $installer = \OC::$server->query(Installer::class); |
|
65 | + $installer->downloadApp($appId); |
|
66 | + $result = $installer->installApp($appId); |
|
67 | + } catch (\Exception $e) { |
|
68 | + $output->writeln('Error: ' . $e->getMessage()); |
|
69 | + return 1; |
|
70 | + } |
|
71 | 71 | |
72 | - if ($result === false) { |
|
73 | - $output->writeln($appId . ' couldn\'t be installed'); |
|
74 | - return 1; |
|
75 | - } |
|
72 | + if ($result === false) { |
|
73 | + $output->writeln($appId . ' couldn\'t be installed'); |
|
74 | + return 1; |
|
75 | + } |
|
76 | 76 | |
77 | - $output->writeln($appId . ' installed'); |
|
77 | + $output->writeln($appId . ' installed'); |
|
78 | 78 | |
79 | - if (!$input->getOption('keep-disabled')) { |
|
80 | - $appClass = new \OC_App(); |
|
81 | - $appClass->enable($appId); |
|
82 | - $output->writeln($appId . ' enabled'); |
|
83 | - } |
|
79 | + if (!$input->getOption('keep-disabled')) { |
|
80 | + $appClass = new \OC_App(); |
|
81 | + $appClass->enable($appId); |
|
82 | + $output->writeln($appId . ' enabled'); |
|
83 | + } |
|
84 | 84 | |
85 | - return 0; |
|
86 | - } |
|
85 | + return 0; |
|
86 | + } |
|
87 | 87 | } |
@@ -39,114 +39,114 @@ |
||
39 | 39 | |
40 | 40 | class Remove extends Command implements CompletionAwareInterface { |
41 | 41 | |
42 | - /** @var IAppManager */ |
|
43 | - protected $manager; |
|
44 | - /** @var Installer */ |
|
45 | - private $installer; |
|
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IAppManager $manager |
|
51 | - * @param Installer $installer |
|
52 | - * @param ILogger $logger |
|
53 | - */ |
|
54 | - public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) { |
|
55 | - parent::__construct(); |
|
56 | - $this->manager = $manager; |
|
57 | - $this->installer = $installer; |
|
58 | - $this->logger = $logger; |
|
59 | - } |
|
60 | - |
|
61 | - protected function configure() { |
|
62 | - $this |
|
63 | - ->setName('app:remove') |
|
64 | - ->setDescription('remove an app') |
|
65 | - ->addArgument( |
|
66 | - 'app-id', |
|
67 | - InputArgument::REQUIRED, |
|
68 | - 'remove the specified app' |
|
69 | - ) |
|
70 | - ->addOption( |
|
71 | - 'keep-data', |
|
72 | - null, |
|
73 | - InputOption::VALUE_NONE, |
|
74 | - 'keep app data and do not remove them' |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
79 | - $appId = $input->getArgument('app-id'); |
|
80 | - |
|
81 | - // Check if the app is installed |
|
82 | - if (!\OC_App::getAppPath($appId)) { |
|
83 | - $output->writeln($appId . ' is not installed'); |
|
84 | - return 1; |
|
85 | - } |
|
86 | - |
|
87 | - // Removing shipped apps is not possible, therefore we pre-check that |
|
88 | - // before trying to remove it |
|
89 | - if ($this->manager->isShipped($appId)) { |
|
90 | - $output->writeln($appId . ' could not be removed as it is a shipped app'); |
|
91 | - return 1; |
|
92 | - } |
|
93 | - |
|
94 | - // If we want to keep the data of the app, we simply don't disable it here. |
|
95 | - // App uninstall tasks are being executed when disabled. More info: PR #11627. |
|
96 | - if (!$input->getOption('keep-data')) { |
|
97 | - try { |
|
98 | - $this->manager->disableApp($appId); |
|
99 | - $output->writeln($appId . ' disabled'); |
|
100 | - } catch (Throwable $e) { |
|
101 | - $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
|
102 | - $this->logger->logException($e, [ |
|
103 | - 'app' => 'CLI', |
|
104 | - 'level' => ILogger::ERROR |
|
105 | - ]); |
|
106 | - return 1; |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - // Let's try to remove the app... |
|
111 | - try { |
|
112 | - $result = $this->installer->removeApp($appId); |
|
113 | - } catch (Throwable $e) { |
|
114 | - $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
|
115 | - $this->logger->logException($e, [ |
|
116 | - 'app' => 'CLI', |
|
117 | - 'level' => ILogger::ERROR |
|
118 | - ]); |
|
119 | - return 1; |
|
120 | - } |
|
121 | - |
|
122 | - if ($result === false) { |
|
123 | - $output->writeln($appId . ' could not be removed'); |
|
124 | - return 1; |
|
125 | - } |
|
126 | - |
|
127 | - $output->writeln($appId . ' removed'); |
|
128 | - |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $optionName |
|
134 | - * @param CompletionContext $context |
|
135 | - * @return string[] |
|
136 | - */ |
|
137 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
138 | - return []; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $argumentName |
|
143 | - * @param CompletionContext $context |
|
144 | - * @return string[] |
|
145 | - */ |
|
146 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
147 | - if ($argumentName === 'app-id') { |
|
148 | - return \OC_App::getAllApps(); |
|
149 | - } |
|
150 | - return []; |
|
151 | - } |
|
42 | + /** @var IAppManager */ |
|
43 | + protected $manager; |
|
44 | + /** @var Installer */ |
|
45 | + private $installer; |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IAppManager $manager |
|
51 | + * @param Installer $installer |
|
52 | + * @param ILogger $logger |
|
53 | + */ |
|
54 | + public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) { |
|
55 | + parent::__construct(); |
|
56 | + $this->manager = $manager; |
|
57 | + $this->installer = $installer; |
|
58 | + $this->logger = $logger; |
|
59 | + } |
|
60 | + |
|
61 | + protected function configure() { |
|
62 | + $this |
|
63 | + ->setName('app:remove') |
|
64 | + ->setDescription('remove an app') |
|
65 | + ->addArgument( |
|
66 | + 'app-id', |
|
67 | + InputArgument::REQUIRED, |
|
68 | + 'remove the specified app' |
|
69 | + ) |
|
70 | + ->addOption( |
|
71 | + 'keep-data', |
|
72 | + null, |
|
73 | + InputOption::VALUE_NONE, |
|
74 | + 'keep app data and do not remove them' |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
79 | + $appId = $input->getArgument('app-id'); |
|
80 | + |
|
81 | + // Check if the app is installed |
|
82 | + if (!\OC_App::getAppPath($appId)) { |
|
83 | + $output->writeln($appId . ' is not installed'); |
|
84 | + return 1; |
|
85 | + } |
|
86 | + |
|
87 | + // Removing shipped apps is not possible, therefore we pre-check that |
|
88 | + // before trying to remove it |
|
89 | + if ($this->manager->isShipped($appId)) { |
|
90 | + $output->writeln($appId . ' could not be removed as it is a shipped app'); |
|
91 | + return 1; |
|
92 | + } |
|
93 | + |
|
94 | + // If we want to keep the data of the app, we simply don't disable it here. |
|
95 | + // App uninstall tasks are being executed when disabled. More info: PR #11627. |
|
96 | + if (!$input->getOption('keep-data')) { |
|
97 | + try { |
|
98 | + $this->manager->disableApp($appId); |
|
99 | + $output->writeln($appId . ' disabled'); |
|
100 | + } catch (Throwable $e) { |
|
101 | + $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
|
102 | + $this->logger->logException($e, [ |
|
103 | + 'app' => 'CLI', |
|
104 | + 'level' => ILogger::ERROR |
|
105 | + ]); |
|
106 | + return 1; |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + // Let's try to remove the app... |
|
111 | + try { |
|
112 | + $result = $this->installer->removeApp($appId); |
|
113 | + } catch (Throwable $e) { |
|
114 | + $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
|
115 | + $this->logger->logException($e, [ |
|
116 | + 'app' => 'CLI', |
|
117 | + 'level' => ILogger::ERROR |
|
118 | + ]); |
|
119 | + return 1; |
|
120 | + } |
|
121 | + |
|
122 | + if ($result === false) { |
|
123 | + $output->writeln($appId . ' could not be removed'); |
|
124 | + return 1; |
|
125 | + } |
|
126 | + |
|
127 | + $output->writeln($appId . ' removed'); |
|
128 | + |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $optionName |
|
134 | + * @param CompletionContext $context |
|
135 | + * @return string[] |
|
136 | + */ |
|
137 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
138 | + return []; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $argumentName |
|
143 | + * @param CompletionContext $context |
|
144 | + * @return string[] |
|
145 | + */ |
|
146 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
147 | + if ($argumentName === 'app-id') { |
|
148 | + return \OC_App::getAllApps(); |
|
149 | + } |
|
150 | + return []; |
|
151 | + } |
|
152 | 152 | } |
@@ -44,167 +44,167 @@ |
||
44 | 44 | use Symfony\Component\Console\Output\OutputInterface; |
45 | 45 | |
46 | 46 | class CheckCode extends Command implements CompletionAwareInterface { |
47 | - protected $checkers = [ |
|
48 | - 'private' => PrivateCheck::class, |
|
49 | - 'deprecation' => DeprecationCheck::class, |
|
50 | - 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | - ]; |
|
52 | - |
|
53 | - protected function configure() { |
|
54 | - $this |
|
55 | - ->setName('app:check-code') |
|
56 | - ->setDescription('check code to be compliant') |
|
57 | - ->addArgument( |
|
58 | - 'app-id', |
|
59 | - InputArgument::REQUIRED, |
|
60 | - 'check the specified app' |
|
61 | - ) |
|
62 | - ->addOption( |
|
63 | - 'checker', |
|
64 | - 'c', |
|
65 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | - 'enable the specified checker(s)', |
|
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | - ) |
|
69 | - ->addOption( |
|
70 | - '--skip-checkers', |
|
71 | - null, |
|
72 | - InputOption::VALUE_NONE, |
|
73 | - 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | - ) |
|
75 | - ->addOption( |
|
76 | - '--skip-validate-info', |
|
77 | - null, |
|
78 | - InputOption::VALUE_NONE, |
|
79 | - 'skips the info.xml/version check' |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | - $appId = $input->getArgument('app-id'); |
|
85 | - |
|
86 | - $checkList = new EmptyCheck(); |
|
87 | - foreach ($input->getOption('checker') as $checker) { |
|
88 | - if (!isset($this->checkers[$checker])) { |
|
89 | - throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | - } |
|
91 | - $checkerClass = $this->checkers[$checker]; |
|
92 | - $checkList = new $checkerClass($checkList); |
|
93 | - } |
|
94 | - |
|
95 | - $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | - |
|
97 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | - if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | - $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | - } |
|
101 | - }); |
|
102 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | - $count = count($errors); |
|
104 | - |
|
105 | - // show filename if the verbosity is low, but there are errors in a file |
|
106 | - if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | - $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | - } |
|
109 | - |
|
110 | - // show error count if there are errors present or the verbosity is high |
|
111 | - if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | - $output->writeln(" {$count} errors"); |
|
113 | - } |
|
114 | - usort($errors, function ($a, $b) { |
|
115 | - return $a['line'] >$b['line']; |
|
116 | - }); |
|
117 | - |
|
118 | - foreach ($errors as $p) { |
|
119 | - $line = sprintf("%' 4d", $p['line']); |
|
120 | - $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | - } |
|
122 | - }); |
|
123 | - $errors = []; |
|
124 | - if (!$input->getOption('skip-checkers')) { |
|
125 | - $errors = $codeChecker->analyse($appId); |
|
126 | - } |
|
127 | - |
|
128 | - if (!$input->getOption('skip-validate-info')) { |
|
129 | - $infoChecker = new InfoChecker(); |
|
130 | - $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | - $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | - }); |
|
133 | - |
|
134 | - $infoErrors = $infoChecker->analyse($appId); |
|
135 | - |
|
136 | - $errors = array_merge($errors, $infoErrors); |
|
137 | - |
|
138 | - $languageParser = new LanguageParseChecker(); |
|
139 | - $languageErrors = $languageParser->analyse($appId); |
|
140 | - |
|
141 | - foreach ($languageErrors as $languageError) { |
|
142 | - $output->writeln("<error>$languageError</error>"); |
|
143 | - } |
|
144 | - |
|
145 | - $errors = array_merge($errors, $languageErrors); |
|
146 | - |
|
147 | - $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | - $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | - |
|
150 | - foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | - $output->writeln("<error>$schemaError</error>"); |
|
152 | - } |
|
153 | - foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | - $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | - } |
|
156 | - |
|
157 | - $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | - } |
|
159 | - |
|
160 | - $this->analyseUpdateFile($appId, $output); |
|
161 | - |
|
162 | - if (empty($errors)) { |
|
163 | - $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | - return 0; |
|
165 | - } else { |
|
166 | - $output->writeln('<error>App is not compliant</error>'); |
|
167 | - return 101; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $appId |
|
173 | - * @param $output |
|
174 | - */ |
|
175 | - private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | - $appPath = \OC_App::getAppPath($appId); |
|
177 | - if ($appPath === false) { |
|
178 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | - } |
|
180 | - |
|
181 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | - if (file_exists($updatePhp)) { |
|
183 | - $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $optionName |
|
189 | - * @param CompletionContext $context |
|
190 | - * @return string[] |
|
191 | - */ |
|
192 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | - if ($optionName === 'checker') { |
|
194 | - return ['private', 'deprecation', 'strong-comparison']; |
|
195 | - } |
|
196 | - return []; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $argumentName |
|
201 | - * @param CompletionContext $context |
|
202 | - * @return string[] |
|
203 | - */ |
|
204 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | - if ($argumentName === 'app-id') { |
|
206 | - return \OC_App::getAllApps(); |
|
207 | - } |
|
208 | - return []; |
|
209 | - } |
|
47 | + protected $checkers = [ |
|
48 | + 'private' => PrivateCheck::class, |
|
49 | + 'deprecation' => DeprecationCheck::class, |
|
50 | + 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | + ]; |
|
52 | + |
|
53 | + protected function configure() { |
|
54 | + $this |
|
55 | + ->setName('app:check-code') |
|
56 | + ->setDescription('check code to be compliant') |
|
57 | + ->addArgument( |
|
58 | + 'app-id', |
|
59 | + InputArgument::REQUIRED, |
|
60 | + 'check the specified app' |
|
61 | + ) |
|
62 | + ->addOption( |
|
63 | + 'checker', |
|
64 | + 'c', |
|
65 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | + 'enable the specified checker(s)', |
|
67 | + [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | + ) |
|
69 | + ->addOption( |
|
70 | + '--skip-checkers', |
|
71 | + null, |
|
72 | + InputOption::VALUE_NONE, |
|
73 | + 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | + ) |
|
75 | + ->addOption( |
|
76 | + '--skip-validate-info', |
|
77 | + null, |
|
78 | + InputOption::VALUE_NONE, |
|
79 | + 'skips the info.xml/version check' |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | + $appId = $input->getArgument('app-id'); |
|
85 | + |
|
86 | + $checkList = new EmptyCheck(); |
|
87 | + foreach ($input->getOption('checker') as $checker) { |
|
88 | + if (!isset($this->checkers[$checker])) { |
|
89 | + throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | + } |
|
91 | + $checkerClass = $this->checkers[$checker]; |
|
92 | + $checkList = new $checkerClass($checkList); |
|
93 | + } |
|
94 | + |
|
95 | + $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | + |
|
97 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | + if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | + $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | + } |
|
101 | + }); |
|
102 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | + $count = count($errors); |
|
104 | + |
|
105 | + // show filename if the verbosity is low, but there are errors in a file |
|
106 | + if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | + $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | + } |
|
109 | + |
|
110 | + // show error count if there are errors present or the verbosity is high |
|
111 | + if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | + $output->writeln(" {$count} errors"); |
|
113 | + } |
|
114 | + usort($errors, function ($a, $b) { |
|
115 | + return $a['line'] >$b['line']; |
|
116 | + }); |
|
117 | + |
|
118 | + foreach ($errors as $p) { |
|
119 | + $line = sprintf("%' 4d", $p['line']); |
|
120 | + $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | + } |
|
122 | + }); |
|
123 | + $errors = []; |
|
124 | + if (!$input->getOption('skip-checkers')) { |
|
125 | + $errors = $codeChecker->analyse($appId); |
|
126 | + } |
|
127 | + |
|
128 | + if (!$input->getOption('skip-validate-info')) { |
|
129 | + $infoChecker = new InfoChecker(); |
|
130 | + $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | + $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | + }); |
|
133 | + |
|
134 | + $infoErrors = $infoChecker->analyse($appId); |
|
135 | + |
|
136 | + $errors = array_merge($errors, $infoErrors); |
|
137 | + |
|
138 | + $languageParser = new LanguageParseChecker(); |
|
139 | + $languageErrors = $languageParser->analyse($appId); |
|
140 | + |
|
141 | + foreach ($languageErrors as $languageError) { |
|
142 | + $output->writeln("<error>$languageError</error>"); |
|
143 | + } |
|
144 | + |
|
145 | + $errors = array_merge($errors, $languageErrors); |
|
146 | + |
|
147 | + $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | + $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | + |
|
150 | + foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | + $output->writeln("<error>$schemaError</error>"); |
|
152 | + } |
|
153 | + foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | + $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | + } |
|
156 | + |
|
157 | + $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | + } |
|
159 | + |
|
160 | + $this->analyseUpdateFile($appId, $output); |
|
161 | + |
|
162 | + if (empty($errors)) { |
|
163 | + $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | + return 0; |
|
165 | + } else { |
|
166 | + $output->writeln('<error>App is not compliant</error>'); |
|
167 | + return 101; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $appId |
|
173 | + * @param $output |
|
174 | + */ |
|
175 | + private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | + $appPath = \OC_App::getAppPath($appId); |
|
177 | + if ($appPath === false) { |
|
178 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | + } |
|
180 | + |
|
181 | + $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | + if (file_exists($updatePhp)) { |
|
183 | + $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $optionName |
|
189 | + * @param CompletionContext $context |
|
190 | + * @return string[] |
|
191 | + */ |
|
192 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | + if ($optionName === 'checker') { |
|
194 | + return ['private', 'deprecation', 'strong-comparison']; |
|
195 | + } |
|
196 | + return []; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $argumentName |
|
201 | + * @param CompletionContext $context |
|
202 | + * @return string[] |
|
203 | + */ |
|
204 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | + if ($argumentName === 'app-id') { |
|
206 | + return \OC_App::getAllApps(); |
|
207 | + } |
|
208 | + return []; |
|
209 | + } |
|
210 | 210 | } |
@@ -41,141 +41,141 @@ |
||
41 | 41 | |
42 | 42 | class Enable extends Command implements CompletionAwareInterface { |
43 | 43 | |
44 | - /** @var IAppManager */ |
|
45 | - protected $appManager; |
|
46 | - |
|
47 | - /** @var IGroupManager */ |
|
48 | - protected $groupManager; |
|
49 | - |
|
50 | - /** @var int */ |
|
51 | - protected $exitCode = 0; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param IAppManager $appManager |
|
55 | - * @param IGroupManager $groupManager |
|
56 | - */ |
|
57 | - public function __construct(IAppManager $appManager, IGroupManager $groupManager) { |
|
58 | - parent::__construct(); |
|
59 | - $this->appManager = $appManager; |
|
60 | - $this->groupManager = $groupManager; |
|
61 | - } |
|
62 | - |
|
63 | - protected function configure(): void { |
|
64 | - $this |
|
65 | - ->setName('app:enable') |
|
66 | - ->setDescription('enable an app') |
|
67 | - ->addArgument( |
|
68 | - 'app-id', |
|
69 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
70 | - 'enable the specified app' |
|
71 | - ) |
|
72 | - ->addOption( |
|
73 | - 'groups', |
|
74 | - 'g', |
|
75 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
76 | - 'enable the app only for a list of groups' |
|
77 | - ) |
|
78 | - ->addOption( |
|
79 | - 'force', |
|
80 | - 'f', |
|
81 | - InputOption::VALUE_NONE, |
|
82 | - 'enable the app regardless of the Nextcloud version requirement' |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
87 | - $appIds = $input->getArgument('app-id'); |
|
88 | - $groups = $this->resolveGroupIds($input->getOption('groups')); |
|
89 | - $forceEnable = (bool) $input->getOption('force'); |
|
90 | - |
|
91 | - foreach ($appIds as $appId) { |
|
92 | - $this->enableApp($appId, $groups, $forceEnable, $output); |
|
93 | - } |
|
94 | - |
|
95 | - return $this->exitCode; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $appId |
|
100 | - * @param array $groupIds |
|
101 | - * @param bool $forceEnable |
|
102 | - * @param OutputInterface $output |
|
103 | - */ |
|
104 | - private function enableApp(string $appId, array $groupIds, bool $forceEnable, OutputInterface $output): void { |
|
105 | - $groupNames = array_map(function (IGroup $group) { |
|
106 | - return $group->getDisplayName(); |
|
107 | - }, $groupIds); |
|
108 | - |
|
109 | - if ($this->appManager->isInstalled($appId) && $groupIds === []) { |
|
110 | - $output->writeln($appId . ' already enabled'); |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - try { |
|
115 | - /** @var Installer $installer */ |
|
116 | - $installer = \OC::$server->query(Installer::class); |
|
117 | - |
|
118 | - if (false === $installer->isDownloaded($appId)) { |
|
119 | - $installer->downloadApp($appId); |
|
120 | - } |
|
121 | - |
|
122 | - $installer->installApp($appId, $forceEnable); |
|
123 | - |
|
124 | - if ($groupIds === []) { |
|
125 | - $this->appManager->enableApp($appId, $forceEnable); |
|
126 | - $output->writeln($appId . ' enabled'); |
|
127 | - } else { |
|
128 | - $this->appManager->enableAppForGroups($appId, $groupIds, $forceEnable); |
|
129 | - $output->writeln($appId . ' enabled for groups: ' . implode(', ', $groupNames)); |
|
130 | - } |
|
131 | - } catch (AppPathNotFoundException $e) { |
|
132 | - $output->writeln($appId . ' not found'); |
|
133 | - $this->exitCode = 1; |
|
134 | - } catch (\Exception $e) { |
|
135 | - $output->writeln($e->getMessage()); |
|
136 | - $this->exitCode = 1; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param array $groupIds |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - private function resolveGroupIds(array $groupIds): array { |
|
145 | - $groups = []; |
|
146 | - foreach ($groupIds as $groupId) { |
|
147 | - $group = $this->groupManager->get($groupId); |
|
148 | - if ($group instanceof IGroup) { |
|
149 | - $groups[] = $group; |
|
150 | - } |
|
151 | - } |
|
152 | - return $groups; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $optionName |
|
157 | - * @param CompletionContext $context |
|
158 | - * @return string[] |
|
159 | - */ |
|
160 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
161 | - if ($optionName === 'groups') { |
|
162 | - return array_map(function (IGroup $group) { |
|
163 | - return $group->getGID(); |
|
164 | - }, $this->groupManager->search($context->getCurrentWord())); |
|
165 | - } |
|
166 | - return []; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $argumentName |
|
171 | - * @param CompletionContext $context |
|
172 | - * @return string[] |
|
173 | - */ |
|
174 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
175 | - if ($argumentName === 'app-id') { |
|
176 | - $allApps = \OC_App::getAllApps(); |
|
177 | - return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
178 | - } |
|
179 | - return []; |
|
180 | - } |
|
44 | + /** @var IAppManager */ |
|
45 | + protected $appManager; |
|
46 | + |
|
47 | + /** @var IGroupManager */ |
|
48 | + protected $groupManager; |
|
49 | + |
|
50 | + /** @var int */ |
|
51 | + protected $exitCode = 0; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param IAppManager $appManager |
|
55 | + * @param IGroupManager $groupManager |
|
56 | + */ |
|
57 | + public function __construct(IAppManager $appManager, IGroupManager $groupManager) { |
|
58 | + parent::__construct(); |
|
59 | + $this->appManager = $appManager; |
|
60 | + $this->groupManager = $groupManager; |
|
61 | + } |
|
62 | + |
|
63 | + protected function configure(): void { |
|
64 | + $this |
|
65 | + ->setName('app:enable') |
|
66 | + ->setDescription('enable an app') |
|
67 | + ->addArgument( |
|
68 | + 'app-id', |
|
69 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
70 | + 'enable the specified app' |
|
71 | + ) |
|
72 | + ->addOption( |
|
73 | + 'groups', |
|
74 | + 'g', |
|
75 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
76 | + 'enable the app only for a list of groups' |
|
77 | + ) |
|
78 | + ->addOption( |
|
79 | + 'force', |
|
80 | + 'f', |
|
81 | + InputOption::VALUE_NONE, |
|
82 | + 'enable the app regardless of the Nextcloud version requirement' |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
87 | + $appIds = $input->getArgument('app-id'); |
|
88 | + $groups = $this->resolveGroupIds($input->getOption('groups')); |
|
89 | + $forceEnable = (bool) $input->getOption('force'); |
|
90 | + |
|
91 | + foreach ($appIds as $appId) { |
|
92 | + $this->enableApp($appId, $groups, $forceEnable, $output); |
|
93 | + } |
|
94 | + |
|
95 | + return $this->exitCode; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $appId |
|
100 | + * @param array $groupIds |
|
101 | + * @param bool $forceEnable |
|
102 | + * @param OutputInterface $output |
|
103 | + */ |
|
104 | + private function enableApp(string $appId, array $groupIds, bool $forceEnable, OutputInterface $output): void { |
|
105 | + $groupNames = array_map(function (IGroup $group) { |
|
106 | + return $group->getDisplayName(); |
|
107 | + }, $groupIds); |
|
108 | + |
|
109 | + if ($this->appManager->isInstalled($appId) && $groupIds === []) { |
|
110 | + $output->writeln($appId . ' already enabled'); |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + try { |
|
115 | + /** @var Installer $installer */ |
|
116 | + $installer = \OC::$server->query(Installer::class); |
|
117 | + |
|
118 | + if (false === $installer->isDownloaded($appId)) { |
|
119 | + $installer->downloadApp($appId); |
|
120 | + } |
|
121 | + |
|
122 | + $installer->installApp($appId, $forceEnable); |
|
123 | + |
|
124 | + if ($groupIds === []) { |
|
125 | + $this->appManager->enableApp($appId, $forceEnable); |
|
126 | + $output->writeln($appId . ' enabled'); |
|
127 | + } else { |
|
128 | + $this->appManager->enableAppForGroups($appId, $groupIds, $forceEnable); |
|
129 | + $output->writeln($appId . ' enabled for groups: ' . implode(', ', $groupNames)); |
|
130 | + } |
|
131 | + } catch (AppPathNotFoundException $e) { |
|
132 | + $output->writeln($appId . ' not found'); |
|
133 | + $this->exitCode = 1; |
|
134 | + } catch (\Exception $e) { |
|
135 | + $output->writeln($e->getMessage()); |
|
136 | + $this->exitCode = 1; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param array $groupIds |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + private function resolveGroupIds(array $groupIds): array { |
|
145 | + $groups = []; |
|
146 | + foreach ($groupIds as $groupId) { |
|
147 | + $group = $this->groupManager->get($groupId); |
|
148 | + if ($group instanceof IGroup) { |
|
149 | + $groups[] = $group; |
|
150 | + } |
|
151 | + } |
|
152 | + return $groups; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $optionName |
|
157 | + * @param CompletionContext $context |
|
158 | + * @return string[] |
|
159 | + */ |
|
160 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
161 | + if ($optionName === 'groups') { |
|
162 | + return array_map(function (IGroup $group) { |
|
163 | + return $group->getGID(); |
|
164 | + }, $this->groupManager->search($context->getCurrentWord())); |
|
165 | + } |
|
166 | + return []; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $argumentName |
|
171 | + * @param CompletionContext $context |
|
172 | + * @return string[] |
|
173 | + */ |
|
174 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
175 | + if ($argumentName === 'app-id') { |
|
176 | + $allApps = \OC_App::getAllApps(); |
|
177 | + return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
178 | + } |
|
179 | + return []; |
|
180 | + } |
|
181 | 181 | } |
@@ -30,48 +30,48 @@ |
||
30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 31 | |
32 | 32 | class GetPath extends Base { |
33 | - protected function configure() { |
|
34 | - parent::configure(); |
|
33 | + protected function configure() { |
|
34 | + parent::configure(); |
|
35 | 35 | |
36 | - $this |
|
37 | - ->setName('app:getpath') |
|
38 | - ->setDescription('Get an absolute path to the app directory') |
|
39 | - ->addArgument( |
|
40 | - 'app', |
|
41 | - InputArgument::REQUIRED, |
|
42 | - 'Name of the app' |
|
43 | - ) |
|
44 | - ; |
|
45 | - } |
|
36 | + $this |
|
37 | + ->setName('app:getpath') |
|
38 | + ->setDescription('Get an absolute path to the app directory') |
|
39 | + ->addArgument( |
|
40 | + 'app', |
|
41 | + InputArgument::REQUIRED, |
|
42 | + 'Name of the app' |
|
43 | + ) |
|
44 | + ; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Executes the current command. |
|
49 | - * |
|
50 | - * @param InputInterface $input An InputInterface instance |
|
51 | - * @param OutputInterface $output An OutputInterface instance |
|
52 | - * @return null|int null or 0 if everything went fine, or an error code |
|
53 | - */ |
|
54 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | - $appName = $input->getArgument('app'); |
|
56 | - $path = \OC_App::getAppPath($appName); |
|
57 | - if ($path !== false) { |
|
58 | - $output->writeln($path); |
|
59 | - return 0; |
|
60 | - } |
|
47 | + /** |
|
48 | + * Executes the current command. |
|
49 | + * |
|
50 | + * @param InputInterface $input An InputInterface instance |
|
51 | + * @param OutputInterface $output An OutputInterface instance |
|
52 | + * @return null|int null or 0 if everything went fine, or an error code |
|
53 | + */ |
|
54 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | + $appName = $input->getArgument('app'); |
|
56 | + $path = \OC_App::getAppPath($appName); |
|
57 | + if ($path !== false) { |
|
58 | + $output->writeln($path); |
|
59 | + return 0; |
|
60 | + } |
|
61 | 61 | |
62 | - // App not found, exit with non-zero |
|
63 | - return 1; |
|
64 | - } |
|
62 | + // App not found, exit with non-zero |
|
63 | + return 1; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $argumentName |
|
68 | - * @param CompletionContext $context |
|
69 | - * @return string[] |
|
70 | - */ |
|
71 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
72 | - if ($argumentName === 'app') { |
|
73 | - return \OC_App::getAllApps(); |
|
74 | - } |
|
75 | - return []; |
|
76 | - } |
|
66 | + /** |
|
67 | + * @param string $argumentName |
|
68 | + * @param CompletionContext $context |
|
69 | + * @return string[] |
|
70 | + */ |
|
71 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
72 | + if ($argumentName === 'app') { |
|
73 | + return \OC_App::getAllApps(); |
|
74 | + } |
|
75 | + return []; |
|
76 | + } |
|
77 | 77 | } |
@@ -37,92 +37,92 @@ |
||
37 | 37 | |
38 | 38 | class Update extends Command { |
39 | 39 | |
40 | - /** @var IAppManager */ |
|
41 | - protected $manager; |
|
42 | - /** @var Installer */ |
|
43 | - private $installer; |
|
44 | - /** @var ILogger */ |
|
45 | - private $logger; |
|
40 | + /** @var IAppManager */ |
|
41 | + protected $manager; |
|
42 | + /** @var Installer */ |
|
43 | + private $installer; |
|
44 | + /** @var ILogger */ |
|
45 | + private $logger; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param IAppManager $manager |
|
49 | - * @param Installer $installer |
|
50 | - */ |
|
51 | - public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) { |
|
52 | - parent::__construct(); |
|
53 | - $this->manager = $manager; |
|
54 | - $this->installer = $installer; |
|
55 | - $this->logger = $logger; |
|
56 | - } |
|
47 | + /** |
|
48 | + * @param IAppManager $manager |
|
49 | + * @param Installer $installer |
|
50 | + */ |
|
51 | + public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) { |
|
52 | + parent::__construct(); |
|
53 | + $this->manager = $manager; |
|
54 | + $this->installer = $installer; |
|
55 | + $this->logger = $logger; |
|
56 | + } |
|
57 | 57 | |
58 | - protected function configure() { |
|
59 | - $this |
|
60 | - ->setName('app:update') |
|
61 | - ->setDescription('update an app or all apps') |
|
62 | - ->addArgument( |
|
63 | - 'app-id', |
|
64 | - InputArgument::OPTIONAL, |
|
65 | - 'update the specified app' |
|
66 | - ) |
|
67 | - ->addOption( |
|
68 | - 'all', |
|
69 | - null, |
|
70 | - InputOption::VALUE_NONE, |
|
71 | - 'update all updatable apps' |
|
72 | - ) |
|
73 | - ->addOption( |
|
74 | - 'showonly', |
|
75 | - null, |
|
76 | - InputOption::VALUE_NONE, |
|
77 | - 'show update(s) without updating' |
|
78 | - ) |
|
58 | + protected function configure() { |
|
59 | + $this |
|
60 | + ->setName('app:update') |
|
61 | + ->setDescription('update an app or all apps') |
|
62 | + ->addArgument( |
|
63 | + 'app-id', |
|
64 | + InputArgument::OPTIONAL, |
|
65 | + 'update the specified app' |
|
66 | + ) |
|
67 | + ->addOption( |
|
68 | + 'all', |
|
69 | + null, |
|
70 | + InputOption::VALUE_NONE, |
|
71 | + 'update all updatable apps' |
|
72 | + ) |
|
73 | + ->addOption( |
|
74 | + 'showonly', |
|
75 | + null, |
|
76 | + InputOption::VALUE_NONE, |
|
77 | + 'show update(s) without updating' |
|
78 | + ) |
|
79 | 79 | |
80 | - ; |
|
81 | - } |
|
80 | + ; |
|
81 | + } |
|
82 | 82 | |
83 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | - $singleAppId = $input->getArgument('app-id'); |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | + $singleAppId = $input->getArgument('app-id'); |
|
85 | 85 | |
86 | - if ($singleAppId) { |
|
87 | - $apps = [$singleAppId]; |
|
88 | - try { |
|
89 | - $this->manager->getAppPath($singleAppId); |
|
90 | - } catch (\OCP\App\AppPathNotFoundException $e) { |
|
91 | - $output->writeln($singleAppId . ' not installed'); |
|
92 | - return 1; |
|
93 | - } |
|
94 | - } elseif ($input->getOption('all') || $input->getOption('showonly')) { |
|
95 | - $apps = \OC_App::getAllApps(); |
|
96 | - } else { |
|
97 | - $output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>"); |
|
98 | - return 1; |
|
99 | - } |
|
86 | + if ($singleAppId) { |
|
87 | + $apps = [$singleAppId]; |
|
88 | + try { |
|
89 | + $this->manager->getAppPath($singleAppId); |
|
90 | + } catch (\OCP\App\AppPathNotFoundException $e) { |
|
91 | + $output->writeln($singleAppId . ' not installed'); |
|
92 | + return 1; |
|
93 | + } |
|
94 | + } elseif ($input->getOption('all') || $input->getOption('showonly')) { |
|
95 | + $apps = \OC_App::getAllApps(); |
|
96 | + } else { |
|
97 | + $output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>"); |
|
98 | + return 1; |
|
99 | + } |
|
100 | 100 | |
101 | - $return = 0; |
|
102 | - foreach ($apps as $appId) { |
|
103 | - $newVersion = $this->installer->isUpdateAvailable($appId); |
|
104 | - if ($newVersion) { |
|
105 | - $output->writeln($appId . ' new version available: ' . $newVersion); |
|
101 | + $return = 0; |
|
102 | + foreach ($apps as $appId) { |
|
103 | + $newVersion = $this->installer->isUpdateAvailable($appId); |
|
104 | + if ($newVersion) { |
|
105 | + $output->writeln($appId . ' new version available: ' . $newVersion); |
|
106 | 106 | |
107 | - if (!$input->getOption('showonly')) { |
|
108 | - try { |
|
109 | - $result = $this->installer->updateAppstoreApp($appId); |
|
110 | - } catch (\Exception $e) { |
|
111 | - $this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']); |
|
112 | - $output->writeln('Error: ' . $e->getMessage()); |
|
113 | - $return = 1; |
|
114 | - } |
|
107 | + if (!$input->getOption('showonly')) { |
|
108 | + try { |
|
109 | + $result = $this->installer->updateAppstoreApp($appId); |
|
110 | + } catch (\Exception $e) { |
|
111 | + $this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']); |
|
112 | + $output->writeln('Error: ' . $e->getMessage()); |
|
113 | + $return = 1; |
|
114 | + } |
|
115 | 115 | |
116 | - if ($result === false) { |
|
117 | - $output->writeln($appId . ' couldn\'t be updated'); |
|
118 | - $return = 1; |
|
119 | - } elseif ($result === true) { |
|
120 | - $output->writeln($appId . ' updated'); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
116 | + if ($result === false) { |
|
117 | + $output->writeln($appId . ' couldn\'t be updated'); |
|
118 | + $return = 1; |
|
119 | + } elseif ($result === true) { |
|
120 | + $output->writeln($appId . ' updated'); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - return $return; |
|
127 | - } |
|
126 | + return $return; |
|
127 | + } |
|
128 | 128 | } |
@@ -35,110 +35,110 @@ |
||
35 | 35 | |
36 | 36 | class ListApps extends Base { |
37 | 37 | |
38 | - /** @var IAppManager */ |
|
39 | - protected $manager; |
|
40 | - |
|
41 | - /** |
|
42 | - * @param IAppManager $manager |
|
43 | - */ |
|
44 | - public function __construct(IAppManager $manager) { |
|
45 | - parent::__construct(); |
|
46 | - $this->manager = $manager; |
|
47 | - } |
|
48 | - |
|
49 | - protected function configure() { |
|
50 | - parent::configure(); |
|
51 | - |
|
52 | - $this |
|
53 | - ->setName('app:list') |
|
54 | - ->setDescription('List all available apps') |
|
55 | - ->addOption( |
|
56 | - 'shipped', |
|
57 | - null, |
|
58 | - InputOption::VALUE_REQUIRED, |
|
59 | - 'true - limit to shipped apps only, false - limit to non-shipped apps only' |
|
60 | - ) |
|
61 | - ; |
|
62 | - } |
|
63 | - |
|
64 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
65 | - if ($input->getOption('shipped') === 'true' || $input->getOption('shipped') === 'false') { |
|
66 | - $shippedFilter = $input->getOption('shipped') === 'true'; |
|
67 | - } else { |
|
68 | - $shippedFilter = null; |
|
69 | - } |
|
70 | - |
|
71 | - $apps = \OC_App::getAllApps(); |
|
72 | - $enabledApps = $disabledApps = []; |
|
73 | - $versions = \OC_App::getAppVersions(); |
|
74 | - |
|
75 | - //sort enabled apps above disabled apps |
|
76 | - foreach ($apps as $app) { |
|
77 | - if ($shippedFilter !== null && $this->manager->isShipped($app) !== $shippedFilter) { |
|
78 | - continue; |
|
79 | - } |
|
80 | - if ($this->manager->isInstalled($app)) { |
|
81 | - $enabledApps[] = $app; |
|
82 | - } else { |
|
83 | - $disabledApps[] = $app; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $apps = ['enabled' => [], 'disabled' => []]; |
|
88 | - |
|
89 | - sort($enabledApps); |
|
90 | - foreach ($enabledApps as $app) { |
|
91 | - $apps['enabled'][$app] = isset($versions[$app]) ? $versions[$app] : true; |
|
92 | - } |
|
93 | - |
|
94 | - sort($disabledApps); |
|
95 | - foreach ($disabledApps as $app) { |
|
96 | - $apps['disabled'][$app] = null; |
|
97 | - } |
|
98 | - |
|
99 | - $this->writeAppList($input, $output, $apps); |
|
100 | - return 0; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param InputInterface $input |
|
105 | - * @param OutputInterface $output |
|
106 | - * @param array $items |
|
107 | - */ |
|
108 | - protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { |
|
109 | - switch ($input->getOption('output')) { |
|
110 | - case self::OUTPUT_FORMAT_PLAIN: |
|
111 | - $output->writeln('Enabled:'); |
|
112 | - parent::writeArrayInOutputFormat($input, $output, $items['enabled']); |
|
113 | - |
|
114 | - $output->writeln('Disabled:'); |
|
115 | - parent::writeArrayInOutputFormat($input, $output, $items['disabled']); |
|
116 | - break; |
|
117 | - |
|
118 | - default: |
|
119 | - parent::writeArrayInOutputFormat($input, $output, $items); |
|
120 | - break; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $optionName |
|
126 | - * @param CompletionContext $completionContext |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function completeOptionValues($optionName, CompletionContext $completionContext) { |
|
130 | - if ($optionName === 'shipped') { |
|
131 | - return ['true', 'false']; |
|
132 | - } |
|
133 | - return []; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $argumentName |
|
138 | - * @param CompletionContext $context |
|
139 | - * @return string[] |
|
140 | - */ |
|
141 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
142 | - return []; |
|
143 | - } |
|
38 | + /** @var IAppManager */ |
|
39 | + protected $manager; |
|
40 | + |
|
41 | + /** |
|
42 | + * @param IAppManager $manager |
|
43 | + */ |
|
44 | + public function __construct(IAppManager $manager) { |
|
45 | + parent::__construct(); |
|
46 | + $this->manager = $manager; |
|
47 | + } |
|
48 | + |
|
49 | + protected function configure() { |
|
50 | + parent::configure(); |
|
51 | + |
|
52 | + $this |
|
53 | + ->setName('app:list') |
|
54 | + ->setDescription('List all available apps') |
|
55 | + ->addOption( |
|
56 | + 'shipped', |
|
57 | + null, |
|
58 | + InputOption::VALUE_REQUIRED, |
|
59 | + 'true - limit to shipped apps only, false - limit to non-shipped apps only' |
|
60 | + ) |
|
61 | + ; |
|
62 | + } |
|
63 | + |
|
64 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
65 | + if ($input->getOption('shipped') === 'true' || $input->getOption('shipped') === 'false') { |
|
66 | + $shippedFilter = $input->getOption('shipped') === 'true'; |
|
67 | + } else { |
|
68 | + $shippedFilter = null; |
|
69 | + } |
|
70 | + |
|
71 | + $apps = \OC_App::getAllApps(); |
|
72 | + $enabledApps = $disabledApps = []; |
|
73 | + $versions = \OC_App::getAppVersions(); |
|
74 | + |
|
75 | + //sort enabled apps above disabled apps |
|
76 | + foreach ($apps as $app) { |
|
77 | + if ($shippedFilter !== null && $this->manager->isShipped($app) !== $shippedFilter) { |
|
78 | + continue; |
|
79 | + } |
|
80 | + if ($this->manager->isInstalled($app)) { |
|
81 | + $enabledApps[] = $app; |
|
82 | + } else { |
|
83 | + $disabledApps[] = $app; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $apps = ['enabled' => [], 'disabled' => []]; |
|
88 | + |
|
89 | + sort($enabledApps); |
|
90 | + foreach ($enabledApps as $app) { |
|
91 | + $apps['enabled'][$app] = isset($versions[$app]) ? $versions[$app] : true; |
|
92 | + } |
|
93 | + |
|
94 | + sort($disabledApps); |
|
95 | + foreach ($disabledApps as $app) { |
|
96 | + $apps['disabled'][$app] = null; |
|
97 | + } |
|
98 | + |
|
99 | + $this->writeAppList($input, $output, $apps); |
|
100 | + return 0; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param InputInterface $input |
|
105 | + * @param OutputInterface $output |
|
106 | + * @param array $items |
|
107 | + */ |
|
108 | + protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { |
|
109 | + switch ($input->getOption('output')) { |
|
110 | + case self::OUTPUT_FORMAT_PLAIN: |
|
111 | + $output->writeln('Enabled:'); |
|
112 | + parent::writeArrayInOutputFormat($input, $output, $items['enabled']); |
|
113 | + |
|
114 | + $output->writeln('Disabled:'); |
|
115 | + parent::writeArrayInOutputFormat($input, $output, $items['disabled']); |
|
116 | + break; |
|
117 | + |
|
118 | + default: |
|
119 | + parent::writeArrayInOutputFormat($input, $output, $items); |
|
120 | + break; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $optionName |
|
126 | + * @param CompletionContext $completionContext |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function completeOptionValues($optionName, CompletionContext $completionContext) { |
|
130 | + if ($optionName === 'shipped') { |
|
131 | + return ['true', 'false']; |
|
132 | + } |
|
133 | + return []; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $argumentName |
|
138 | + * @param CompletionContext $context |
|
139 | + * @return string[] |
|
140 | + */ |
|
141 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
142 | + return []; |
|
143 | + } |
|
144 | 144 | } |
@@ -28,31 +28,31 @@ |
||
28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | 29 | |
30 | 30 | class Disable extends Command { |
31 | - /** @var IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param IConfig $config |
|
36 | - */ |
|
37 | - public function __construct(IConfig $config) { |
|
38 | - parent::__construct(); |
|
39 | - $this->config = $config; |
|
40 | - } |
|
34 | + /** |
|
35 | + * @param IConfig $config |
|
36 | + */ |
|
37 | + public function __construct(IConfig $config) { |
|
38 | + parent::__construct(); |
|
39 | + $this->config = $config; |
|
40 | + } |
|
41 | 41 | |
42 | - protected function configure() { |
|
43 | - $this |
|
44 | - ->setName('encryption:disable') |
|
45 | - ->setDescription('Disable encryption') |
|
46 | - ; |
|
47 | - } |
|
42 | + protected function configure() { |
|
43 | + $this |
|
44 | + ->setName('encryption:disable') |
|
45 | + ->setDescription('Disable encryption') |
|
46 | + ; |
|
47 | + } |
|
48 | 48 | |
49 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
50 | - if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') { |
|
51 | - $output->writeln('Encryption is already disabled'); |
|
52 | - } else { |
|
53 | - $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
54 | - $output->writeln('<info>Encryption disabled</info>'); |
|
55 | - } |
|
56 | - return 0; |
|
57 | - } |
|
49 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
50 | + if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') { |
|
51 | + $output->writeln('Encryption is already disabled'); |
|
52 | + } else { |
|
53 | + $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
54 | + $output->writeln('<info>Encryption disabled</info>'); |
|
55 | + } |
|
56 | + return 0; |
|
57 | + } |
|
58 | 58 | } |