@@ -44,168 +44,168 @@ |
||
44 | 44 | |
45 | 45 | class CheckCode extends Command implements CompletionAwareInterface { |
46 | 46 | |
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) { |
|
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 | - // Can not inject because of circular dependency |
|
130 | - $infoChecker = new InfoChecker(\OC::$server->getAppManager()); |
|
131 | - $infoChecker->listen('InfoChecker', 'parseError', function($error) use ($output) { |
|
132 | - $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
133 | - }); |
|
134 | - |
|
135 | - $infoErrors = $infoChecker->analyse($appId); |
|
136 | - |
|
137 | - $errors = array_merge($errors, $infoErrors); |
|
138 | - |
|
139 | - $languageParser = new LanguageParseChecker(); |
|
140 | - $languageErrors = $languageParser->analyse($appId); |
|
141 | - |
|
142 | - foreach ($languageErrors as $languageError) { |
|
143 | - $output->writeln("<error>$languageError</error>"); |
|
144 | - } |
|
145 | - |
|
146 | - $errors = array_merge($errors, $languageErrors); |
|
147 | - |
|
148 | - $databaseSchema = new DatabaseSchemaChecker(); |
|
149 | - $schemaErrors = $databaseSchema->analyse($appId); |
|
150 | - |
|
151 | - foreach ($schemaErrors['errors'] as $schemaError) { |
|
152 | - $output->writeln("<error>$schemaError</error>"); |
|
153 | - } |
|
154 | - foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
155 | - $output->writeln("<comment>$schemaWarning</comment>"); |
|
156 | - } |
|
157 | - |
|
158 | - $errors = array_merge($errors, $schemaErrors['errors']); |
|
159 | - } |
|
160 | - |
|
161 | - $this->analyseUpdateFile($appId, $output); |
|
162 | - |
|
163 | - if (empty($errors)) { |
|
164 | - $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
165 | - return 0; |
|
166 | - } else { |
|
167 | - $output->writeln('<error>App is not compliant</error>'); |
|
168 | - return 101; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @param string $appId |
|
174 | - * @param $output |
|
175 | - */ |
|
176 | - private function analyseUpdateFile($appId, OutputInterface $output) { |
|
177 | - $appPath = \OC_App::getAppPath($appId); |
|
178 | - if ($appPath === false) { |
|
179 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
180 | - } |
|
181 | - |
|
182 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
183 | - if (file_exists($updatePhp)) { |
|
184 | - $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $optionName |
|
190 | - * @param CompletionContext $context |
|
191 | - * @return string[] |
|
192 | - */ |
|
193 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
194 | - if ($optionName === 'checker') { |
|
195 | - return ['private', 'deprecation', 'strong-comparison']; |
|
196 | - } |
|
197 | - return []; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $argumentName |
|
202 | - * @param CompletionContext $context |
|
203 | - * @return string[] |
|
204 | - */ |
|
205 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
206 | - if ($argumentName === 'app-id') { |
|
207 | - return \OC_App::getAllApps(); |
|
208 | - } |
|
209 | - return []; |
|
210 | - } |
|
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) { |
|
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 | + // Can not inject because of circular dependency |
|
130 | + $infoChecker = new InfoChecker(\OC::$server->getAppManager()); |
|
131 | + $infoChecker->listen('InfoChecker', 'parseError', function($error) use ($output) { |
|
132 | + $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
133 | + }); |
|
134 | + |
|
135 | + $infoErrors = $infoChecker->analyse($appId); |
|
136 | + |
|
137 | + $errors = array_merge($errors, $infoErrors); |
|
138 | + |
|
139 | + $languageParser = new LanguageParseChecker(); |
|
140 | + $languageErrors = $languageParser->analyse($appId); |
|
141 | + |
|
142 | + foreach ($languageErrors as $languageError) { |
|
143 | + $output->writeln("<error>$languageError</error>"); |
|
144 | + } |
|
145 | + |
|
146 | + $errors = array_merge($errors, $languageErrors); |
|
147 | + |
|
148 | + $databaseSchema = new DatabaseSchemaChecker(); |
|
149 | + $schemaErrors = $databaseSchema->analyse($appId); |
|
150 | + |
|
151 | + foreach ($schemaErrors['errors'] as $schemaError) { |
|
152 | + $output->writeln("<error>$schemaError</error>"); |
|
153 | + } |
|
154 | + foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
155 | + $output->writeln("<comment>$schemaWarning</comment>"); |
|
156 | + } |
|
157 | + |
|
158 | + $errors = array_merge($errors, $schemaErrors['errors']); |
|
159 | + } |
|
160 | + |
|
161 | + $this->analyseUpdateFile($appId, $output); |
|
162 | + |
|
163 | + if (empty($errors)) { |
|
164 | + $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
165 | + return 0; |
|
166 | + } else { |
|
167 | + $output->writeln('<error>App is not compliant</error>'); |
|
168 | + return 101; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @param string $appId |
|
174 | + * @param $output |
|
175 | + */ |
|
176 | + private function analyseUpdateFile($appId, OutputInterface $output) { |
|
177 | + $appPath = \OC_App::getAppPath($appId); |
|
178 | + if ($appPath === false) { |
|
179 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
180 | + } |
|
181 | + |
|
182 | + $updatePhp = $appPath . '/appinfo/update.php'; |
|
183 | + if (file_exists($updatePhp)) { |
|
184 | + $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $optionName |
|
190 | + * @param CompletionContext $context |
|
191 | + * @return string[] |
|
192 | + */ |
|
193 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
194 | + if ($optionName === 'checker') { |
|
195 | + return ['private', 'deprecation', 'strong-comparison']; |
|
196 | + } |
|
197 | + return []; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $argumentName |
|
202 | + * @param CompletionContext $context |
|
203 | + * @return string[] |
|
204 | + */ |
|
205 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
206 | + if ($argumentName === 'app-id') { |
|
207 | + return \OC_App::getAllApps(); |
|
208 | + } |
|
209 | + return []; |
|
210 | + } |
|
211 | 211 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | use OC\App\CodeChecker\DeprecationCheck; |
43 | 43 | use OC\App\CodeChecker\PrivateCheck; |
44 | 44 | |
45 | -class CheckCode extends Command implements CompletionAwareInterface { |
|
45 | +class CheckCode extends Command implements CompletionAwareInterface { |
|
46 | 46 | |
47 | 47 | protected $checkers = [ |
48 | 48 | 'private' => PrivateCheck::class, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | 'c', |
65 | 65 | InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
66 | 66 | 'enable the specified checker(s)', |
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
67 | + ['private', 'deprecation', 'strong-comparison'] |
|
68 | 68 | ) |
69 | 69 | ->addOption( |
70 | 70 | '--skip-checkers', |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
96 | 96 | |
97 | 97 | $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
98 | - if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
98 | + if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | 99 | $output->writeln("<info>Analysing {$params}</info>"); |
100 | 100 | } |
101 | 101 | }); |
@@ -103,29 +103,29 @@ discard block |
||
103 | 103 | $count = count($errors); |
104 | 104 | |
105 | 105 | // show filename if the verbosity is low, but there are errors in a file |
106 | - if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
106 | + if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | 107 | $output->writeln("<info>Analysing {$filename}</info>"); |
108 | 108 | } |
109 | 109 | |
110 | 110 | // show error count if there are errors present or the verbosity is high |
111 | - if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
111 | + if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | 112 | $output->writeln(" {$count} errors"); |
113 | 113 | } |
114 | 114 | usort($errors, function($a, $b) { |
115 | - return $a['line'] >$b['line']; |
|
115 | + return $a['line'] > $b['line']; |
|
116 | 116 | }); |
117 | 117 | |
118 | - foreach($errors as $p) { |
|
118 | + foreach ($errors as $p) { |
|
119 | 119 | $line = sprintf("%' 4d", $p['line']); |
120 | 120 | $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
121 | 121 | } |
122 | 122 | }); |
123 | 123 | $errors = []; |
124 | - if(!$input->getOption('skip-checkers')) { |
|
124 | + if (!$input->getOption('skip-checkers')) { |
|
125 | 125 | $errors = $codeChecker->analyse($appId); |
126 | 126 | } |
127 | 127 | |
128 | - if(!$input->getOption('skip-validate-info')) { |
|
128 | + if (!$input->getOption('skip-validate-info')) { |
|
129 | 129 | // Can not inject because of circular dependency |
130 | 130 | $infoChecker = new InfoChecker(\OC::$server->getAppManager()); |
131 | 131 | $infoChecker->listen('InfoChecker', 'parseError', function($error) use ($output) { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | throw new \RuntimeException("No app with given id <$appId> known."); |
180 | 180 | } |
181 | 181 | |
182 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | + $updatePhp = $appPath.'/appinfo/update.php'; |
|
183 | 183 | if (file_exists($updatePhp)) { |
184 | 184 | $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
185 | 185 | } |
@@ -30,7 +30,6 @@ |
||
30 | 30 | use OC\App\CodeChecker\EmptyCheck; |
31 | 31 | use OC\App\CodeChecker\InfoChecker; |
32 | 32 | use OC\App\CodeChecker\LanguageParseChecker; |
33 | -use OC\App\InfoParser; |
|
34 | 33 | use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; |
35 | 34 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
36 | 35 | use Symfony\Component\Console\Command\Command; |
@@ -43,123 +43,123 @@ |
||
43 | 43 | $application->add(new OC\Core\Command\App\CheckCode()); |
44 | 44 | $application->add(new OC\Core\Command\L10n\CreateJs()); |
45 | 45 | $application->add(new \OC\Core\Command\Integrity\SignApp( |
46 | - \OC::$server->getIntegrityCodeChecker(), |
|
47 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
48 | - \OC::$server->getURLGenerator() |
|
46 | + \OC::$server->getIntegrityCodeChecker(), |
|
47 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
48 | + \OC::$server->getURLGenerator() |
|
49 | 49 | )); |
50 | 50 | $application->add(new \OC\Core\Command\Integrity\SignCore( |
51 | - \OC::$server->getIntegrityCodeChecker(), |
|
52 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
51 | + \OC::$server->getIntegrityCodeChecker(), |
|
52 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
53 | 53 | )); |
54 | 54 | $application->add(new \OC\Core\Command\Integrity\CheckApp( |
55 | - \OC::$server->getIntegrityCodeChecker() |
|
55 | + \OC::$server->getIntegrityCodeChecker() |
|
56 | 56 | )); |
57 | 57 | $application->add(new \OC\Core\Command\Integrity\CheckCore( |
58 | - \OC::$server->getIntegrityCodeChecker() |
|
58 | + \OC::$server->getIntegrityCodeChecker() |
|
59 | 59 | )); |
60 | 60 | |
61 | 61 | |
62 | 62 | if (\OC::$server->getConfig()->getSystemValue('installed', false)) { |
63 | - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
64 | - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
65 | - $application->add(new OC\Core\Command\App\Install()); |
|
66 | - $application->add(new OC\Core\Command\App\GetPath()); |
|
67 | - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
63 | + $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
64 | + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
65 | + $application->add(new OC\Core\Command\App\Install()); |
|
66 | + $application->add(new OC\Core\Command\App\GetPath()); |
|
67 | + $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
68 | 68 | |
69 | - $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
70 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
71 | - )); |
|
72 | - $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
73 | - \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
74 | - )); |
|
69 | + $application->add(new OC\Core\Command\TwoFactorAuth\Enable( |
|
70 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
71 | + )); |
|
72 | + $application->add(new OC\Core\Command\TwoFactorAuth\Disable( |
|
73 | + \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager() |
|
74 | + )); |
|
75 | 75 | |
76 | - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
77 | - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
78 | - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
76 | + $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
77 | + $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
78 | + $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
79 | 79 | |
80 | - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
81 | - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
82 | - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
83 | - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
84 | - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
85 | - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
86 | - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
87 | - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
80 | + $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
81 | + $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
82 | + $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
83 | + $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
84 | + $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
85 | + $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
86 | + $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
87 | + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
88 | 88 | |
89 | - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
90 | - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
91 | - $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
92 | - $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection())); |
|
93 | - $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
94 | - $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
95 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection())); |
|
96 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
97 | - $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig())); |
|
89 | + $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
90 | + $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
91 | + $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
92 | + $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection())); |
|
93 | + $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
94 | + $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
95 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection())); |
|
96 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
97 | + $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig())); |
|
98 | 98 | |
99 | - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
100 | - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
101 | - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
102 | - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
103 | - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
104 | - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
105 | - $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
106 | - \OC::$server->getEncryptionManager(), |
|
107 | - \OC::$server->getAppManager(), |
|
108 | - \OC::$server->getConfig(), |
|
109 | - new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
110 | - new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
111 | - ); |
|
99 | + $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
100 | + $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
101 | + $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
102 | + $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
103 | + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
104 | + $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
105 | + $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
106 | + \OC::$server->getEncryptionManager(), |
|
107 | + \OC::$server->getAppManager(), |
|
108 | + \OC::$server->getConfig(), |
|
109 | + new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
110 | + new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
111 | + ); |
|
112 | 112 | |
113 | - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
114 | - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
113 | + $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
114 | + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
115 | 115 | |
116 | - $view = new \OC\Files\View(); |
|
117 | - $util = new \OC\Encryption\Util( |
|
118 | - $view, |
|
119 | - \OC::$server->getUserManager(), |
|
120 | - \OC::$server->getGroupManager(), |
|
121 | - \OC::$server->getConfig() |
|
122 | - ); |
|
123 | - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
124 | - $view, |
|
125 | - \OC::$server->getUserManager(), |
|
126 | - \OC::$server->getConfig(), |
|
127 | - $util, |
|
128 | - new \Symfony\Component\Console\Helper\QuestionHelper() |
|
129 | - ) |
|
130 | - ); |
|
131 | - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
116 | + $view = new \OC\Files\View(); |
|
117 | + $util = new \OC\Encryption\Util( |
|
118 | + $view, |
|
119 | + \OC::$server->getUserManager(), |
|
120 | + \OC::$server->getGroupManager(), |
|
121 | + \OC::$server->getConfig() |
|
122 | + ); |
|
123 | + $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
124 | + $view, |
|
125 | + \OC::$server->getUserManager(), |
|
126 | + \OC::$server->getConfig(), |
|
127 | + $util, |
|
128 | + new \Symfony\Component\Console\Helper\QuestionHelper() |
|
129 | + ) |
|
130 | + ); |
|
131 | + $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
132 | 132 | |
133 | - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
134 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
135 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
136 | - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
137 | - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
138 | - $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
133 | + $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
134 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
135 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
136 | + $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
137 | + $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
138 | + $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
139 | 139 | |
140 | - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
141 | - $application->add(new OC\Core\Command\Maintenance\Repair( |
|
142 | - new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
143 | - \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
140 | + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
141 | + $application->add(new OC\Core\Command\Maintenance\Repair( |
|
142 | + new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
143 | + \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
144 | 144 | |
145 | - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
146 | - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
147 | - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
148 | - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
149 | - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
150 | - $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
151 | - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
152 | - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
153 | - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
154 | - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
145 | + $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
146 | + $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
147 | + $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
148 | + $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
149 | + $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
150 | + $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
151 | + $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
152 | + $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
153 | + $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
154 | + $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
155 | 155 | |
156 | - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
157 | - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
158 | - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
156 | + $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
157 | + $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
158 | + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
159 | 159 | |
160 | - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
161 | - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
162 | - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
160 | + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
161 | + $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
162 | + $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
163 | 163 | } else { |
164 | - $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
164 | + $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
165 | 165 | } |
@@ -29,82 +29,82 @@ |
||
29 | 29 | |
30 | 30 | class InfoChecker extends BasicEmitter { |
31 | 31 | |
32 | - /** @var string[] */ |
|
33 | - private $shippedApps; |
|
32 | + /** @var string[] */ |
|
33 | + private $shippedApps; |
|
34 | 34 | |
35 | - /** @var string[] */ |
|
36 | - private $alwaysEnabled; |
|
35 | + /** @var string[] */ |
|
36 | + private $alwaysEnabled; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $appId |
|
40 | - * @return array |
|
41 | - * @throws \RuntimeException |
|
42 | - */ |
|
43 | - public function analyse($appId): array { |
|
44 | - $appPath = \OC_App::getAppPath($appId); |
|
45 | - if ($appPath === false) { |
|
46 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param string $appId |
|
40 | + * @return array |
|
41 | + * @throws \RuntimeException |
|
42 | + */ |
|
43 | + public function analyse($appId): array { |
|
44 | + $appPath = \OC_App::getAppPath($appId); |
|
45 | + if ($appPath === false) { |
|
46 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
47 | + } |
|
48 | 48 | |
49 | - $xml = new \DOMDocument(); |
|
50 | - $xml->load($appPath . '/appinfo/info.xml'); |
|
49 | + $xml = new \DOMDocument(); |
|
50 | + $xml->load($appPath . '/appinfo/info.xml'); |
|
51 | 51 | |
52 | - $schema = \OC::$SERVERROOT . '/resources/app-info.xsd'; |
|
53 | - try { |
|
54 | - if ($this->isShipped($appId)) { |
|
55 | - // Shipped apps are allowed to have the public and default_enabled tags |
|
56 | - $schema = \OC::$SERVERROOT . '/resources/app-info-shipped.xsd'; |
|
57 | - } |
|
58 | - } catch (\Exception $e) { |
|
59 | - // Assume it is not shipped |
|
60 | - } |
|
52 | + $schema = \OC::$SERVERROOT . '/resources/app-info.xsd'; |
|
53 | + try { |
|
54 | + if ($this->isShipped($appId)) { |
|
55 | + // Shipped apps are allowed to have the public and default_enabled tags |
|
56 | + $schema = \OC::$SERVERROOT . '/resources/app-info-shipped.xsd'; |
|
57 | + } |
|
58 | + } catch (\Exception $e) { |
|
59 | + // Assume it is not shipped |
|
60 | + } |
|
61 | 61 | |
62 | - $errors = []; |
|
63 | - if (!$xml->schemaValidate($schema)) { |
|
64 | - foreach (libxml_get_errors() as $error) { |
|
65 | - $errors[] = [ |
|
66 | - 'type' => 'parseError', |
|
67 | - 'field' => $error->message, |
|
68 | - ]; |
|
69 | - $this->emit('InfoChecker', 'parseError', [$error->message]); |
|
70 | - } |
|
71 | - } |
|
62 | + $errors = []; |
|
63 | + if (!$xml->schemaValidate($schema)) { |
|
64 | + foreach (libxml_get_errors() as $error) { |
|
65 | + $errors[] = [ |
|
66 | + 'type' => 'parseError', |
|
67 | + 'field' => $error->message, |
|
68 | + ]; |
|
69 | + $this->emit('InfoChecker', 'parseError', [$error->message]); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - return $errors; |
|
74 | - } |
|
73 | + return $errors; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * This is a copy of \OC\App\AppManager::isShipped(), keep both in sync. |
|
78 | - * This method is copied, so the code checker works even when Nextcloud is |
|
79 | - * not installed yet. The AppManager requires a database connection, which |
|
80 | - * fails in that case. |
|
81 | - * |
|
82 | - * @param string $appId |
|
83 | - * @return bool |
|
84 | - * @throws \Exception |
|
85 | - */ |
|
86 | - protected function isShipped(string $appId): bool { |
|
87 | - $this->loadShippedJson(); |
|
88 | - return \in_array($appId, $this->shippedApps, true); |
|
89 | - } |
|
76 | + /** |
|
77 | + * This is a copy of \OC\App\AppManager::isShipped(), keep both in sync. |
|
78 | + * This method is copied, so the code checker works even when Nextcloud is |
|
79 | + * not installed yet. The AppManager requires a database connection, which |
|
80 | + * fails in that case. |
|
81 | + * |
|
82 | + * @param string $appId |
|
83 | + * @return bool |
|
84 | + * @throws \Exception |
|
85 | + */ |
|
86 | + protected function isShipped(string $appId): bool { |
|
87 | + $this->loadShippedJson(); |
|
88 | + return \in_array($appId, $this->shippedApps, true); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * This is a copy of \OC\App\AppManager::loadShippedJson(), keep both in sync |
|
93 | - * This method is copied, so the code checker works even when Nextcloud is |
|
94 | - * not installed yet. The AppManager requires a database connection, which |
|
95 | - * fails in that case. |
|
96 | - * |
|
97 | - * @throws \Exception |
|
98 | - */ |
|
99 | - protected function loadShippedJson() { |
|
100 | - if ($this->shippedApps === null) { |
|
101 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
102 | - if (!file_exists($shippedJson)) { |
|
103 | - throw new \Exception("File not found: $shippedJson"); |
|
104 | - } |
|
105 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
106 | - $this->shippedApps = $content['shippedApps']; |
|
107 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
108 | - } |
|
109 | - } |
|
91 | + /** |
|
92 | + * This is a copy of \OC\App\AppManager::loadShippedJson(), keep both in sync |
|
93 | + * This method is copied, so the code checker works even when Nextcloud is |
|
94 | + * not installed yet. The AppManager requires a database connection, which |
|
95 | + * fails in that case. |
|
96 | + * |
|
97 | + * @throws \Exception |
|
98 | + */ |
|
99 | + protected function loadShippedJson() { |
|
100 | + if ($this->shippedApps === null) { |
|
101 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
102 | + if (!file_exists($shippedJson)) { |
|
103 | + throw new \Exception("File not found: $shippedJson"); |
|
104 | + } |
|
105 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
106 | + $this->shippedApps = $content['shippedApps']; |
|
107 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | } |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | $xml = new \DOMDocument(); |
50 | - $xml->load($appPath . '/appinfo/info.xml'); |
|
50 | + $xml->load($appPath.'/appinfo/info.xml'); |
|
51 | 51 | |
52 | - $schema = \OC::$SERVERROOT . '/resources/app-info.xsd'; |
|
52 | + $schema = \OC::$SERVERROOT.'/resources/app-info.xsd'; |
|
53 | 53 | try { |
54 | 54 | if ($this->isShipped($appId)) { |
55 | 55 | // Shipped apps are allowed to have the public and default_enabled tags |
56 | - $schema = \OC::$SERVERROOT . '/resources/app-info-shipped.xsd'; |
|
56 | + $schema = \OC::$SERVERROOT.'/resources/app-info-shipped.xsd'; |
|
57 | 57 | } |
58 | 58 | } catch (\Exception $e) { |
59 | 59 | // Assume it is not shipped |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function loadShippedJson() { |
100 | 100 | if ($this->shippedApps === null) { |
101 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
101 | + $shippedJson = \OC::$SERVERROOT.'/core/shipped.json'; |
|
102 | 102 | if (!file_exists($shippedJson)) { |
103 | 103 | throw new \Exception("File not found: $shippedJson"); |
104 | 104 | } |
@@ -44,406 +44,406 @@ |
||
44 | 44 | |
45 | 45 | class AppManager implements IAppManager { |
46 | 46 | |
47 | - /** |
|
48 | - * Apps with these types can not be enabled for certain groups only |
|
49 | - * @var string[] |
|
50 | - */ |
|
51 | - protected $protectedAppTypes = [ |
|
52 | - 'filesystem', |
|
53 | - 'prelogin', |
|
54 | - 'authentication', |
|
55 | - 'logging', |
|
56 | - 'prevent_group_restriction', |
|
57 | - ]; |
|
58 | - |
|
59 | - /** @var IUserSession */ |
|
60 | - private $userSession; |
|
61 | - |
|
62 | - /** @var AppConfig */ |
|
63 | - private $appConfig; |
|
64 | - |
|
65 | - /** @var IGroupManager */ |
|
66 | - private $groupManager; |
|
67 | - |
|
68 | - /** @var ICacheFactory */ |
|
69 | - private $memCacheFactory; |
|
70 | - |
|
71 | - /** @var EventDispatcherInterface */ |
|
72 | - private $dispatcher; |
|
73 | - |
|
74 | - /** @var string[] $appId => $enabled */ |
|
75 | - private $installedAppsCache; |
|
76 | - |
|
77 | - /** @var string[] */ |
|
78 | - private $shippedApps; |
|
79 | - |
|
80 | - /** @var string[] */ |
|
81 | - private $alwaysEnabled; |
|
82 | - |
|
83 | - /** @var array */ |
|
84 | - private $appInfos = []; |
|
85 | - |
|
86 | - /** @var array */ |
|
87 | - private $appVersions = []; |
|
88 | - |
|
89 | - /** |
|
90 | - * @param IUserSession $userSession |
|
91 | - * @param AppConfig $appConfig |
|
92 | - * @param IGroupManager $groupManager |
|
93 | - * @param ICacheFactory $memCacheFactory |
|
94 | - * @param EventDispatcherInterface $dispatcher |
|
95 | - */ |
|
96 | - public function __construct(IUserSession $userSession, |
|
97 | - AppConfig $appConfig, |
|
98 | - IGroupManager $groupManager, |
|
99 | - ICacheFactory $memCacheFactory, |
|
100 | - EventDispatcherInterface $dispatcher) { |
|
101 | - $this->userSession = $userSession; |
|
102 | - $this->appConfig = $appConfig; |
|
103 | - $this->groupManager = $groupManager; |
|
104 | - $this->memCacheFactory = $memCacheFactory; |
|
105 | - $this->dispatcher = $dispatcher; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return string[] $appId => $enabled |
|
110 | - */ |
|
111 | - private function getInstalledAppsValues() { |
|
112 | - if (!$this->installedAppsCache) { |
|
113 | - $values = $this->appConfig->getValues(false, 'enabled'); |
|
114 | - |
|
115 | - $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
116 | - foreach($alwaysEnabledApps as $appId) { |
|
117 | - $values[$appId] = 'yes'; |
|
118 | - } |
|
119 | - |
|
120 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
121 | - return $value !== 'no'; |
|
122 | - }); |
|
123 | - ksort($this->installedAppsCache); |
|
124 | - } |
|
125 | - return $this->installedAppsCache; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * List all installed apps |
|
130 | - * |
|
131 | - * @return string[] |
|
132 | - */ |
|
133 | - public function getInstalledApps() { |
|
134 | - return array_keys($this->getInstalledAppsValues()); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * List all apps enabled for a user |
|
139 | - * |
|
140 | - * @param \OCP\IUser $user |
|
141 | - * @return string[] |
|
142 | - */ |
|
143 | - public function getEnabledAppsForUser(IUser $user) { |
|
144 | - $apps = $this->getInstalledAppsValues(); |
|
145 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
146 | - return $this->checkAppForUser($enabled, $user); |
|
147 | - }); |
|
148 | - return array_keys($appsForUser); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Check if an app is enabled for user |
|
153 | - * |
|
154 | - * @param string $appId |
|
155 | - * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - public function isEnabledForUser($appId, $user = null) { |
|
159 | - if ($this->isAlwaysEnabled($appId)) { |
|
160 | - return true; |
|
161 | - } |
|
162 | - if ($user === null) { |
|
163 | - $user = $this->userSession->getUser(); |
|
164 | - } |
|
165 | - $installedApps = $this->getInstalledAppsValues(); |
|
166 | - if (isset($installedApps[$appId])) { |
|
167 | - return $this->checkAppForUser($installedApps[$appId], $user); |
|
168 | - } else { |
|
169 | - return false; |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $enabled |
|
175 | - * @param IUser $user |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - private function checkAppForUser($enabled, $user) { |
|
179 | - if ($enabled === 'yes') { |
|
180 | - return true; |
|
181 | - } elseif ($user === null) { |
|
182 | - return false; |
|
183 | - } else { |
|
184 | - if(empty($enabled)){ |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - $groupIds = json_decode($enabled); |
|
189 | - |
|
190 | - if (!is_array($groupIds)) { |
|
191 | - $jsonError = json_last_error(); |
|
192 | - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
197 | - foreach ($userGroups as $groupId) { |
|
198 | - if (in_array($groupId, $groupIds, true)) { |
|
199 | - return true; |
|
200 | - } |
|
201 | - } |
|
202 | - return false; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Check if an app is installed in the instance |
|
208 | - * |
|
209 | - * @param string $appId |
|
210 | - * @return bool |
|
211 | - */ |
|
212 | - public function isInstalled($appId) { |
|
213 | - $installedApps = $this->getInstalledAppsValues(); |
|
214 | - return isset($installedApps[$appId]); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Enable an app for every user |
|
219 | - * |
|
220 | - * @param string $appId |
|
221 | - * @throws AppPathNotFoundException |
|
222 | - */ |
|
223 | - public function enableApp($appId) { |
|
224 | - // Check if app exists |
|
225 | - $this->getAppPath($appId); |
|
226 | - |
|
227 | - $this->installedAppsCache[$appId] = 'yes'; |
|
228 | - $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
229 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
230 | - ManagerEvent::EVENT_APP_ENABLE, $appId |
|
231 | - )); |
|
232 | - $this->clearAppsCache(); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Whether a list of types contains a protected app type |
|
237 | - * |
|
238 | - * @param string[] $types |
|
239 | - * @return bool |
|
240 | - */ |
|
241 | - public function hasProtectedAppType($types) { |
|
242 | - if (empty($types)) { |
|
243 | - return false; |
|
244 | - } |
|
245 | - |
|
246 | - $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
247 | - return !empty($protectedTypes); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Enable an app only for specific groups |
|
252 | - * |
|
253 | - * @param string $appId |
|
254 | - * @param \OCP\IGroup[] $groups |
|
255 | - * @throws \Exception if app can't be enabled for groups |
|
256 | - */ |
|
257 | - public function enableAppForGroups($appId, $groups) { |
|
258 | - $info = $this->getAppInfo($appId); |
|
259 | - if (!empty($info['types'])) { |
|
260 | - $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
261 | - if (!empty($protectedTypes)) { |
|
262 | - throw new \Exception("$appId can't be enabled for groups."); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - $groupIds = array_map(function ($group) { |
|
267 | - /** @var \OCP\IGroup $group */ |
|
268 | - return $group->getGID(); |
|
269 | - }, $groups); |
|
270 | - $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
271 | - $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
272 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
273 | - ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
274 | - )); |
|
275 | - $this->clearAppsCache(); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Disable an app for every user |
|
280 | - * |
|
281 | - * @param string $appId |
|
282 | - * @throws \Exception if app can't be disabled |
|
283 | - */ |
|
284 | - public function disableApp($appId) { |
|
285 | - if ($this->isAlwaysEnabled($appId)) { |
|
286 | - throw new \Exception("$appId can't be disabled."); |
|
287 | - } |
|
288 | - unset($this->installedAppsCache[$appId]); |
|
289 | - $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
290 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
291 | - ManagerEvent::EVENT_APP_DISABLE, $appId |
|
292 | - )); |
|
293 | - $this->clearAppsCache(); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Get the directory for the given app. |
|
298 | - * |
|
299 | - * @param string $appId |
|
300 | - * @return string |
|
301 | - * @throws AppPathNotFoundException if app folder can't be found |
|
302 | - */ |
|
303 | - public function getAppPath($appId) { |
|
304 | - $appPath = \OC_App::getAppPath($appId); |
|
305 | - if($appPath === false) { |
|
306 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
307 | - } |
|
308 | - return $appPath; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Clear the cached list of apps when enabling/disabling an app |
|
313 | - */ |
|
314 | - public function clearAppsCache() { |
|
315 | - $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
316 | - $settingsMemCache->clear('listApps'); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Returns a list of apps that need upgrade |
|
321 | - * |
|
322 | - * @param string $version Nextcloud version as array of version components |
|
323 | - * @return array list of app info from apps that need an upgrade |
|
324 | - * |
|
325 | - * @internal |
|
326 | - */ |
|
327 | - public function getAppsNeedingUpgrade($version) { |
|
328 | - $appsToUpgrade = []; |
|
329 | - $apps = $this->getInstalledApps(); |
|
330 | - foreach ($apps as $appId) { |
|
331 | - $appInfo = $this->getAppInfo($appId); |
|
332 | - $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
333 | - if ($appDbVersion |
|
334 | - && isset($appInfo['version']) |
|
335 | - && version_compare($appInfo['version'], $appDbVersion, '>') |
|
336 | - && \OC_App::isAppCompatible($version, $appInfo) |
|
337 | - ) { |
|
338 | - $appsToUpgrade[] = $appInfo; |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - return $appsToUpgrade; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Returns the app information from "appinfo/info.xml". |
|
347 | - * |
|
348 | - * @param string $appId app id |
|
349 | - * |
|
350 | - * @param bool $path |
|
351 | - * @param null $lang |
|
352 | - * @return array app info |
|
353 | - */ |
|
354 | - public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
355 | - if ($path) { |
|
356 | - $file = $appId; |
|
357 | - } else { |
|
358 | - if ($lang === null && isset($this->appInfos[$appId])) { |
|
359 | - return $this->appInfos[$appId]; |
|
360 | - } |
|
361 | - try { |
|
362 | - $appPath = $this->getAppPath($appId); |
|
363 | - } catch (AppPathNotFoundException $e) { |
|
364 | - return null; |
|
365 | - } |
|
366 | - $file = $appPath . '/appinfo/info.xml'; |
|
367 | - } |
|
368 | - |
|
369 | - $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
370 | - $data = $parser->parse($file); |
|
371 | - |
|
372 | - if (is_array($data)) { |
|
373 | - $data = \OC_App::parseAppInfo($data, $lang); |
|
374 | - } |
|
375 | - |
|
376 | - if ($lang === null) { |
|
377 | - $this->appInfos[$appId] = $data; |
|
378 | - } |
|
379 | - |
|
380 | - return $data; |
|
381 | - } |
|
382 | - |
|
383 | - public function getAppVersion(string $appId, bool $useCache = true) { |
|
384 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
385 | - $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
386 | - $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
|
387 | - } |
|
388 | - return $this->appVersions[$appId]; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Returns a list of apps incompatible with the given version |
|
393 | - * |
|
394 | - * @param string $version Nextcloud version as array of version components |
|
395 | - * |
|
396 | - * @return array list of app info from incompatible apps |
|
397 | - * |
|
398 | - * @internal |
|
399 | - */ |
|
400 | - public function getIncompatibleApps($version) { |
|
401 | - $apps = $this->getInstalledApps(); |
|
402 | - $incompatibleApps = array(); |
|
403 | - foreach ($apps as $appId) { |
|
404 | - $info = $this->getAppInfo($appId); |
|
405 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
406 | - $incompatibleApps[] = $info; |
|
407 | - } |
|
408 | - } |
|
409 | - return $incompatibleApps; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * @inheritdoc |
|
414 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
415 | - */ |
|
416 | - public function isShipped($appId) { |
|
417 | - $this->loadShippedJson(); |
|
418 | - return in_array($appId, $this->shippedApps, true); |
|
419 | - } |
|
420 | - |
|
421 | - private function isAlwaysEnabled($appId) { |
|
422 | - $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
423 | - return in_array($appId, $alwaysEnabled, true); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
428 | - * @throws \Exception |
|
429 | - */ |
|
430 | - private function loadShippedJson() { |
|
431 | - if ($this->shippedApps === null) { |
|
432 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
433 | - if (!file_exists($shippedJson)) { |
|
434 | - throw new \Exception("File not found: $shippedJson"); |
|
435 | - } |
|
436 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
437 | - $this->shippedApps = $content['shippedApps']; |
|
438 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @inheritdoc |
|
444 | - */ |
|
445 | - public function getAlwaysEnabledApps() { |
|
446 | - $this->loadShippedJson(); |
|
447 | - return $this->alwaysEnabled; |
|
448 | - } |
|
47 | + /** |
|
48 | + * Apps with these types can not be enabled for certain groups only |
|
49 | + * @var string[] |
|
50 | + */ |
|
51 | + protected $protectedAppTypes = [ |
|
52 | + 'filesystem', |
|
53 | + 'prelogin', |
|
54 | + 'authentication', |
|
55 | + 'logging', |
|
56 | + 'prevent_group_restriction', |
|
57 | + ]; |
|
58 | + |
|
59 | + /** @var IUserSession */ |
|
60 | + private $userSession; |
|
61 | + |
|
62 | + /** @var AppConfig */ |
|
63 | + private $appConfig; |
|
64 | + |
|
65 | + /** @var IGroupManager */ |
|
66 | + private $groupManager; |
|
67 | + |
|
68 | + /** @var ICacheFactory */ |
|
69 | + private $memCacheFactory; |
|
70 | + |
|
71 | + /** @var EventDispatcherInterface */ |
|
72 | + private $dispatcher; |
|
73 | + |
|
74 | + /** @var string[] $appId => $enabled */ |
|
75 | + private $installedAppsCache; |
|
76 | + |
|
77 | + /** @var string[] */ |
|
78 | + private $shippedApps; |
|
79 | + |
|
80 | + /** @var string[] */ |
|
81 | + private $alwaysEnabled; |
|
82 | + |
|
83 | + /** @var array */ |
|
84 | + private $appInfos = []; |
|
85 | + |
|
86 | + /** @var array */ |
|
87 | + private $appVersions = []; |
|
88 | + |
|
89 | + /** |
|
90 | + * @param IUserSession $userSession |
|
91 | + * @param AppConfig $appConfig |
|
92 | + * @param IGroupManager $groupManager |
|
93 | + * @param ICacheFactory $memCacheFactory |
|
94 | + * @param EventDispatcherInterface $dispatcher |
|
95 | + */ |
|
96 | + public function __construct(IUserSession $userSession, |
|
97 | + AppConfig $appConfig, |
|
98 | + IGroupManager $groupManager, |
|
99 | + ICacheFactory $memCacheFactory, |
|
100 | + EventDispatcherInterface $dispatcher) { |
|
101 | + $this->userSession = $userSession; |
|
102 | + $this->appConfig = $appConfig; |
|
103 | + $this->groupManager = $groupManager; |
|
104 | + $this->memCacheFactory = $memCacheFactory; |
|
105 | + $this->dispatcher = $dispatcher; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return string[] $appId => $enabled |
|
110 | + */ |
|
111 | + private function getInstalledAppsValues() { |
|
112 | + if (!$this->installedAppsCache) { |
|
113 | + $values = $this->appConfig->getValues(false, 'enabled'); |
|
114 | + |
|
115 | + $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
116 | + foreach($alwaysEnabledApps as $appId) { |
|
117 | + $values[$appId] = 'yes'; |
|
118 | + } |
|
119 | + |
|
120 | + $this->installedAppsCache = array_filter($values, function ($value) { |
|
121 | + return $value !== 'no'; |
|
122 | + }); |
|
123 | + ksort($this->installedAppsCache); |
|
124 | + } |
|
125 | + return $this->installedAppsCache; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * List all installed apps |
|
130 | + * |
|
131 | + * @return string[] |
|
132 | + */ |
|
133 | + public function getInstalledApps() { |
|
134 | + return array_keys($this->getInstalledAppsValues()); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * List all apps enabled for a user |
|
139 | + * |
|
140 | + * @param \OCP\IUser $user |
|
141 | + * @return string[] |
|
142 | + */ |
|
143 | + public function getEnabledAppsForUser(IUser $user) { |
|
144 | + $apps = $this->getInstalledAppsValues(); |
|
145 | + $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
146 | + return $this->checkAppForUser($enabled, $user); |
|
147 | + }); |
|
148 | + return array_keys($appsForUser); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Check if an app is enabled for user |
|
153 | + * |
|
154 | + * @param string $appId |
|
155 | + * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + public function isEnabledForUser($appId, $user = null) { |
|
159 | + if ($this->isAlwaysEnabled($appId)) { |
|
160 | + return true; |
|
161 | + } |
|
162 | + if ($user === null) { |
|
163 | + $user = $this->userSession->getUser(); |
|
164 | + } |
|
165 | + $installedApps = $this->getInstalledAppsValues(); |
|
166 | + if (isset($installedApps[$appId])) { |
|
167 | + return $this->checkAppForUser($installedApps[$appId], $user); |
|
168 | + } else { |
|
169 | + return false; |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $enabled |
|
175 | + * @param IUser $user |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + private function checkAppForUser($enabled, $user) { |
|
179 | + if ($enabled === 'yes') { |
|
180 | + return true; |
|
181 | + } elseif ($user === null) { |
|
182 | + return false; |
|
183 | + } else { |
|
184 | + if(empty($enabled)){ |
|
185 | + return false; |
|
186 | + } |
|
187 | + |
|
188 | + $groupIds = json_decode($enabled); |
|
189 | + |
|
190 | + if (!is_array($groupIds)) { |
|
191 | + $jsonError = json_last_error(); |
|
192 | + \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
197 | + foreach ($userGroups as $groupId) { |
|
198 | + if (in_array($groupId, $groupIds, true)) { |
|
199 | + return true; |
|
200 | + } |
|
201 | + } |
|
202 | + return false; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Check if an app is installed in the instance |
|
208 | + * |
|
209 | + * @param string $appId |
|
210 | + * @return bool |
|
211 | + */ |
|
212 | + public function isInstalled($appId) { |
|
213 | + $installedApps = $this->getInstalledAppsValues(); |
|
214 | + return isset($installedApps[$appId]); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Enable an app for every user |
|
219 | + * |
|
220 | + * @param string $appId |
|
221 | + * @throws AppPathNotFoundException |
|
222 | + */ |
|
223 | + public function enableApp($appId) { |
|
224 | + // Check if app exists |
|
225 | + $this->getAppPath($appId); |
|
226 | + |
|
227 | + $this->installedAppsCache[$appId] = 'yes'; |
|
228 | + $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
229 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
230 | + ManagerEvent::EVENT_APP_ENABLE, $appId |
|
231 | + )); |
|
232 | + $this->clearAppsCache(); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Whether a list of types contains a protected app type |
|
237 | + * |
|
238 | + * @param string[] $types |
|
239 | + * @return bool |
|
240 | + */ |
|
241 | + public function hasProtectedAppType($types) { |
|
242 | + if (empty($types)) { |
|
243 | + return false; |
|
244 | + } |
|
245 | + |
|
246 | + $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
247 | + return !empty($protectedTypes); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Enable an app only for specific groups |
|
252 | + * |
|
253 | + * @param string $appId |
|
254 | + * @param \OCP\IGroup[] $groups |
|
255 | + * @throws \Exception if app can't be enabled for groups |
|
256 | + */ |
|
257 | + public function enableAppForGroups($appId, $groups) { |
|
258 | + $info = $this->getAppInfo($appId); |
|
259 | + if (!empty($info['types'])) { |
|
260 | + $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
261 | + if (!empty($protectedTypes)) { |
|
262 | + throw new \Exception("$appId can't be enabled for groups."); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + $groupIds = array_map(function ($group) { |
|
267 | + /** @var \OCP\IGroup $group */ |
|
268 | + return $group->getGID(); |
|
269 | + }, $groups); |
|
270 | + $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
271 | + $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
272 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
273 | + ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
274 | + )); |
|
275 | + $this->clearAppsCache(); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Disable an app for every user |
|
280 | + * |
|
281 | + * @param string $appId |
|
282 | + * @throws \Exception if app can't be disabled |
|
283 | + */ |
|
284 | + public function disableApp($appId) { |
|
285 | + if ($this->isAlwaysEnabled($appId)) { |
|
286 | + throw new \Exception("$appId can't be disabled."); |
|
287 | + } |
|
288 | + unset($this->installedAppsCache[$appId]); |
|
289 | + $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
290 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
291 | + ManagerEvent::EVENT_APP_DISABLE, $appId |
|
292 | + )); |
|
293 | + $this->clearAppsCache(); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Get the directory for the given app. |
|
298 | + * |
|
299 | + * @param string $appId |
|
300 | + * @return string |
|
301 | + * @throws AppPathNotFoundException if app folder can't be found |
|
302 | + */ |
|
303 | + public function getAppPath($appId) { |
|
304 | + $appPath = \OC_App::getAppPath($appId); |
|
305 | + if($appPath === false) { |
|
306 | + throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
307 | + } |
|
308 | + return $appPath; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Clear the cached list of apps when enabling/disabling an app |
|
313 | + */ |
|
314 | + public function clearAppsCache() { |
|
315 | + $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
316 | + $settingsMemCache->clear('listApps'); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Returns a list of apps that need upgrade |
|
321 | + * |
|
322 | + * @param string $version Nextcloud version as array of version components |
|
323 | + * @return array list of app info from apps that need an upgrade |
|
324 | + * |
|
325 | + * @internal |
|
326 | + */ |
|
327 | + public function getAppsNeedingUpgrade($version) { |
|
328 | + $appsToUpgrade = []; |
|
329 | + $apps = $this->getInstalledApps(); |
|
330 | + foreach ($apps as $appId) { |
|
331 | + $appInfo = $this->getAppInfo($appId); |
|
332 | + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
333 | + if ($appDbVersion |
|
334 | + && isset($appInfo['version']) |
|
335 | + && version_compare($appInfo['version'], $appDbVersion, '>') |
|
336 | + && \OC_App::isAppCompatible($version, $appInfo) |
|
337 | + ) { |
|
338 | + $appsToUpgrade[] = $appInfo; |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + return $appsToUpgrade; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Returns the app information from "appinfo/info.xml". |
|
347 | + * |
|
348 | + * @param string $appId app id |
|
349 | + * |
|
350 | + * @param bool $path |
|
351 | + * @param null $lang |
|
352 | + * @return array app info |
|
353 | + */ |
|
354 | + public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
355 | + if ($path) { |
|
356 | + $file = $appId; |
|
357 | + } else { |
|
358 | + if ($lang === null && isset($this->appInfos[$appId])) { |
|
359 | + return $this->appInfos[$appId]; |
|
360 | + } |
|
361 | + try { |
|
362 | + $appPath = $this->getAppPath($appId); |
|
363 | + } catch (AppPathNotFoundException $e) { |
|
364 | + return null; |
|
365 | + } |
|
366 | + $file = $appPath . '/appinfo/info.xml'; |
|
367 | + } |
|
368 | + |
|
369 | + $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
370 | + $data = $parser->parse($file); |
|
371 | + |
|
372 | + if (is_array($data)) { |
|
373 | + $data = \OC_App::parseAppInfo($data, $lang); |
|
374 | + } |
|
375 | + |
|
376 | + if ($lang === null) { |
|
377 | + $this->appInfos[$appId] = $data; |
|
378 | + } |
|
379 | + |
|
380 | + return $data; |
|
381 | + } |
|
382 | + |
|
383 | + public function getAppVersion(string $appId, bool $useCache = true) { |
|
384 | + if(!$useCache || !isset($this->appVersions[$appId])) { |
|
385 | + $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
386 | + $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
|
387 | + } |
|
388 | + return $this->appVersions[$appId]; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Returns a list of apps incompatible with the given version |
|
393 | + * |
|
394 | + * @param string $version Nextcloud version as array of version components |
|
395 | + * |
|
396 | + * @return array list of app info from incompatible apps |
|
397 | + * |
|
398 | + * @internal |
|
399 | + */ |
|
400 | + public function getIncompatibleApps($version) { |
|
401 | + $apps = $this->getInstalledApps(); |
|
402 | + $incompatibleApps = array(); |
|
403 | + foreach ($apps as $appId) { |
|
404 | + $info = $this->getAppInfo($appId); |
|
405 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
406 | + $incompatibleApps[] = $info; |
|
407 | + } |
|
408 | + } |
|
409 | + return $incompatibleApps; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * @inheritdoc |
|
414 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
415 | + */ |
|
416 | + public function isShipped($appId) { |
|
417 | + $this->loadShippedJson(); |
|
418 | + return in_array($appId, $this->shippedApps, true); |
|
419 | + } |
|
420 | + |
|
421 | + private function isAlwaysEnabled($appId) { |
|
422 | + $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
423 | + return in_array($appId, $alwaysEnabled, true); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
428 | + * @throws \Exception |
|
429 | + */ |
|
430 | + private function loadShippedJson() { |
|
431 | + if ($this->shippedApps === null) { |
|
432 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
433 | + if (!file_exists($shippedJson)) { |
|
434 | + throw new \Exception("File not found: $shippedJson"); |
|
435 | + } |
|
436 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
437 | + $this->shippedApps = $content['shippedApps']; |
|
438 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @inheritdoc |
|
444 | + */ |
|
445 | + public function getAlwaysEnabledApps() { |
|
446 | + $this->loadShippedJson(); |
|
447 | + return $this->alwaysEnabled; |
|
448 | + } |
|
449 | 449 | } |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | $values = $this->appConfig->getValues(false, 'enabled'); |
114 | 114 | |
115 | 115 | $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
116 | - foreach($alwaysEnabledApps as $appId) { |
|
116 | + foreach ($alwaysEnabledApps as $appId) { |
|
117 | 117 | $values[$appId] = 'yes'; |
118 | 118 | } |
119 | 119 | |
120 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
120 | + $this->installedAppsCache = array_filter($values, function($value) { |
|
121 | 121 | return $value !== 'no'; |
122 | 122 | }); |
123 | 123 | ksort($this->installedAppsCache); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function getEnabledAppsForUser(IUser $user) { |
144 | 144 | $apps = $this->getInstalledAppsValues(); |
145 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
145 | + $appsForUser = array_filter($apps, function($enabled) use ($user) { |
|
146 | 146 | return $this->checkAppForUser($enabled, $user); |
147 | 147 | }); |
148 | 148 | return array_keys($appsForUser); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } elseif ($user === null) { |
182 | 182 | return false; |
183 | 183 | } else { |
184 | - if(empty($enabled)){ |
|
184 | + if (empty($enabled)) { |
|
185 | 185 | return false; |
186 | 186 | } |
187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | if (!is_array($groupIds)) { |
191 | 191 | $jsonError = json_last_error(); |
192 | - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
192 | + \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: '.print_r($enabled, true).' - json error code: '.$jsonError, ['app' => 'lib']); |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - $groupIds = array_map(function ($group) { |
|
266 | + $groupIds = array_map(function($group) { |
|
267 | 267 | /** @var \OCP\IGroup $group */ |
268 | 268 | return $group->getGID(); |
269 | 269 | }, $groups); |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function getAppPath($appId) { |
304 | 304 | $appPath = \OC_App::getAppPath($appId); |
305 | - if($appPath === false) { |
|
306 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
305 | + if ($appPath === false) { |
|
306 | + throw new AppPathNotFoundException('Could not find path for '.$appId); |
|
307 | 307 | } |
308 | 308 | return $appPath; |
309 | 309 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | } catch (AppPathNotFoundException $e) { |
364 | 364 | return null; |
365 | 365 | } |
366 | - $file = $appPath . '/appinfo/info.xml'; |
|
366 | + $file = $appPath.'/appinfo/info.xml'; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } |
382 | 382 | |
383 | 383 | public function getAppVersion(string $appId, bool $useCache = true) { |
384 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
384 | + if (!$useCache || !isset($this->appVersions[$appId])) { |
|
385 | 385 | $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
386 | 386 | $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
387 | 387 | } |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | private function loadShippedJson() { |
431 | 431 | if ($this->shippedApps === null) { |
432 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
432 | + $shippedJson = \OC::$SERVERROOT.'/core/shipped.json'; |
|
433 | 433 | if (!file_exists($shippedJson)) { |
434 | 434 | throw new \Exception("File not found: $shippedJson"); |
435 | 435 | } |