@@ -33,10 +33,10 @@ |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function setupDatabase($username) { |
36 | - $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
36 | + $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
37 | 37 | |
38 | 38 | //delete the old sqlite database first, might cause infinte loops otherwise |
39 | - if(file_exists("$datadir/owncloud.db")) { |
|
39 | + if (file_exists("$datadir/owncloud.db")) { |
|
40 | 40 | unlink("$datadir/owncloud.db"); |
41 | 41 | } |
42 | 42 | //in case of sqlite, we can always fill the database |
@@ -23,23 +23,23 @@ |
||
23 | 23 | namespace OC\Setup; |
24 | 24 | |
25 | 25 | class Sqlite extends AbstractDatabase { |
26 | - public $dbprettyname = 'Sqlite'; |
|
26 | + public $dbprettyname = 'Sqlite'; |
|
27 | 27 | |
28 | - public function validate($config) { |
|
29 | - return array(); |
|
30 | - } |
|
28 | + public function validate($config) { |
|
29 | + return array(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function initialize($config) { |
|
33 | - } |
|
32 | + public function initialize($config) { |
|
33 | + } |
|
34 | 34 | |
35 | - public function setupDatabase($username) { |
|
36 | - $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
35 | + public function setupDatabase($username) { |
|
36 | + $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
37 | 37 | |
38 | - //delete the old sqlite database first, might cause infinte loops otherwise |
|
39 | - if(file_exists("$datadir/owncloud.db")) { |
|
40 | - unlink("$datadir/owncloud.db"); |
|
41 | - } |
|
42 | - //in case of sqlite, we can always fill the database |
|
43 | - error_log("creating sqlite db"); |
|
44 | - } |
|
38 | + //delete the old sqlite database first, might cause infinte loops otherwise |
|
39 | + if(file_exists("$datadir/owncloud.db")) { |
|
40 | + unlink("$datadir/owncloud.db"); |
|
41 | + } |
|
42 | + //in case of sqlite, we can always fill the database |
|
43 | + error_log("creating sqlite db"); |
|
44 | + } |
|
45 | 45 | } |
@@ -39,33 +39,33 @@ |
||
39 | 39 | * @package OCA\DAV\Connector\Sabre |
40 | 40 | */ |
41 | 41 | class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin { |
42 | - /** @var \Sabre\DAV\Server */ |
|
43 | - protected $server; |
|
42 | + /** @var \Sabre\DAV\Server */ |
|
43 | + protected $server; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param \Sabre\DAV\Server $server |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - function initialize(\Sabre\DAV\Server $server) { |
|
50 | - $this->server = $server; |
|
51 | - $this->server->on('method:GET', [$this, 'httpGet'], 200); |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param \Sabre\DAV\Server $server |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + function initialize(\Sabre\DAV\Server $server) { |
|
50 | + $this->server = $server; |
|
51 | + $this->server->on('method:GET', [$this, 'httpGet'], 200); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param RequestInterface $request |
|
56 | - * @param ResponseInterface $response |
|
57 | - * @return false |
|
58 | - */ |
|
59 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
60 | - $string = 'This is the WebDAV interface. It can only be accessed by ' . |
|
61 | - 'WebDAV clients such as the Nextcloud desktop sync client.'; |
|
62 | - $stream = fopen('php://memory','r+'); |
|
63 | - fwrite($stream, $string); |
|
64 | - rewind($stream); |
|
54 | + /** |
|
55 | + * @param RequestInterface $request |
|
56 | + * @param ResponseInterface $response |
|
57 | + * @return false |
|
58 | + */ |
|
59 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
60 | + $string = 'This is the WebDAV interface. It can only be accessed by ' . |
|
61 | + 'WebDAV clients such as the Nextcloud desktop sync client.'; |
|
62 | + $stream = fopen('php://memory','r+'); |
|
63 | + fwrite($stream, $string); |
|
64 | + rewind($stream); |
|
65 | 65 | |
66 | - $response->setStatus(200); |
|
67 | - $response->setBody($stream); |
|
66 | + $response->setStatus(200); |
|
67 | + $response->setBody($stream); |
|
68 | 68 | |
69 | - return false; |
|
70 | - } |
|
69 | + return false; |
|
70 | + } |
|
71 | 71 | } |
@@ -57,9 +57,9 @@ |
||
57 | 57 | * @return false |
58 | 58 | */ |
59 | 59 | function httpGet(RequestInterface $request, ResponseInterface $response) { |
60 | - $string = 'This is the WebDAV interface. It can only be accessed by ' . |
|
60 | + $string = 'This is the WebDAV interface. It can only be accessed by '. |
|
61 | 61 | 'WebDAV clients such as the Nextcloud desktop sync client.'; |
62 | - $stream = fopen('php://memory','r+'); |
|
62 | + $stream = fopen('php://memory', 'r+'); |
|
63 | 63 | fwrite($stream, $string); |
64 | 64 | rewind($stream); |
65 | 65 |
@@ -37,57 +37,57 @@ |
||
37 | 37 | */ |
38 | 38 | class ConsoleOutput implements IOutput { |
39 | 39 | |
40 | - /** @var OutputInterface */ |
|
41 | - private $output; |
|
40 | + /** @var OutputInterface */ |
|
41 | + private $output; |
|
42 | 42 | |
43 | - /** @var ProgressBar */ |
|
44 | - private $progressBar; |
|
43 | + /** @var ProgressBar */ |
|
44 | + private $progressBar; |
|
45 | 45 | |
46 | - public function __construct(OutputInterface $output) { |
|
47 | - $this->output = $output; |
|
48 | - } |
|
46 | + public function __construct(OutputInterface $output) { |
|
47 | + $this->output = $output; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $message |
|
52 | - */ |
|
53 | - public function info($message) { |
|
54 | - $this->output->writeln("<info>$message</info>"); |
|
55 | - } |
|
50 | + /** |
|
51 | + * @param string $message |
|
52 | + */ |
|
53 | + public function info($message) { |
|
54 | + $this->output->writeln("<info>$message</info>"); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param string $message |
|
59 | - */ |
|
60 | - public function warning($message) { |
|
61 | - $this->output->writeln("<comment>$message</comment>"); |
|
62 | - } |
|
57 | + /** |
|
58 | + * @param string $message |
|
59 | + */ |
|
60 | + public function warning($message) { |
|
61 | + $this->output->writeln("<comment>$message</comment>"); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param int $max |
|
66 | - */ |
|
67 | - public function startProgress($max = 0) { |
|
68 | - if (!is_null($this->progressBar)) { |
|
69 | - $this->progressBar->finish(); |
|
70 | - } |
|
71 | - $this->progressBar = new ProgressBar($this->output); |
|
72 | - $this->progressBar->start($max); |
|
73 | - } |
|
64 | + /** |
|
65 | + * @param int $max |
|
66 | + */ |
|
67 | + public function startProgress($max = 0) { |
|
68 | + if (!is_null($this->progressBar)) { |
|
69 | + $this->progressBar->finish(); |
|
70 | + } |
|
71 | + $this->progressBar = new ProgressBar($this->output); |
|
72 | + $this->progressBar->start($max); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param int $step |
|
77 | - * @param string $description |
|
78 | - */ |
|
79 | - public function advance($step = 1, $description = '') { |
|
80 | - if (!is_null($this->progressBar)) { |
|
81 | - $this->progressBar = new ProgressBar($this->output); |
|
82 | - $this->progressBar->start(); |
|
83 | - } |
|
84 | - $this->progressBar->advance($step); |
|
85 | - } |
|
75 | + /** |
|
76 | + * @param int $step |
|
77 | + * @param string $description |
|
78 | + */ |
|
79 | + public function advance($step = 1, $description = '') { |
|
80 | + if (!is_null($this->progressBar)) { |
|
81 | + $this->progressBar = new ProgressBar($this->output); |
|
82 | + $this->progressBar->start(); |
|
83 | + } |
|
84 | + $this->progressBar->advance($step); |
|
85 | + } |
|
86 | 86 | |
87 | - public function finishProgress() { |
|
88 | - if (is_null($this->progressBar)) { |
|
89 | - return; |
|
90 | - } |
|
91 | - $this->progressBar->finish(); |
|
92 | - } |
|
87 | + public function finishProgress() { |
|
88 | + if (is_null($this->progressBar)) { |
|
89 | + return; |
|
90 | + } |
|
91 | + $this->progressBar->finish(); |
|
92 | + } |
|
93 | 93 | } |
@@ -34,102 +34,102 @@ |
||
34 | 34 | |
35 | 35 | class EncryptAll extends Command { |
36 | 36 | |
37 | - /** @var IManager */ |
|
38 | - protected $encryptionManager; |
|
39 | - |
|
40 | - /** @var IAppManager */ |
|
41 | - protected $appManager; |
|
42 | - |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
45 | - |
|
46 | - /** @var QuestionHelper */ |
|
47 | - protected $questionHelper; |
|
48 | - |
|
49 | - /** @var bool */ |
|
50 | - protected $wasTrashbinEnabled; |
|
51 | - |
|
52 | - /** @var bool */ |
|
53 | - protected $wasMaintenanceModeEnabled; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param IManager $encryptionManager |
|
57 | - * @param IAppManager $appManager |
|
58 | - * @param IConfig $config |
|
59 | - * @param QuestionHelper $questionHelper |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - IManager $encryptionManager, |
|
63 | - IAppManager $appManager, |
|
64 | - IConfig $config, |
|
65 | - QuestionHelper $questionHelper |
|
66 | - ) { |
|
67 | - parent::__construct(); |
|
68 | - $this->appManager = $appManager; |
|
69 | - $this->encryptionManager = $encryptionManager; |
|
70 | - $this->config = $config; |
|
71 | - $this->questionHelper = $questionHelper; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Set maintenance mode and disable the trashbin app |
|
76 | - */ |
|
77 | - protected function forceMaintenanceAndTrashbin() { |
|
78 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
79 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
80 | - $this->config->setSystemValue('maintenance', true); |
|
81 | - $this->appManager->disableApp('files_trashbin'); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Reset the maintenance mode and re-enable the trashbin app |
|
86 | - */ |
|
87 | - protected function resetMaintenanceAndTrashbin() { |
|
88 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
89 | - if ($this->wasTrashbinEnabled) { |
|
90 | - $this->appManager->enableApp('files_trashbin'); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - protected function configure() { |
|
95 | - parent::configure(); |
|
96 | - |
|
97 | - $this->setName('encryption:encrypt-all'); |
|
98 | - $this->setDescription('Encrypt all files for all users'); |
|
99 | - $this->setHelp( |
|
100 | - 'This will encrypt all files for all users. ' |
|
101 | - . 'Please make sure that no user access his files during this process!' |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
106 | - |
|
107 | - if ($this->encryptionManager->isEnabled() === false) { |
|
108 | - throw new \Exception('Server side encryption is not enabled'); |
|
109 | - } |
|
110 | - |
|
111 | - $output->writeln("\n"); |
|
112 | - $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); |
|
113 | - $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); |
|
114 | - $output->writeln('Please ensure that no user accesses their files during this time!'); |
|
115 | - $output->writeln('Note: The encryption module you use determines which files get encrypted.'); |
|
116 | - $output->writeln(''); |
|
117 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
118 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
119 | - $this->forceMaintenanceAndTrashbin(); |
|
120 | - |
|
121 | - try { |
|
122 | - $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
123 | - $defaultModule->encryptAll($input, $output); |
|
124 | - } catch (\Exception $ex) { |
|
125 | - $this->resetMaintenanceAndTrashbin(); |
|
126 | - throw $ex; |
|
127 | - } |
|
128 | - |
|
129 | - $this->resetMaintenanceAndTrashbin(); |
|
130 | - } else { |
|
131 | - $output->writeln('aborted'); |
|
132 | - } |
|
133 | - } |
|
37 | + /** @var IManager */ |
|
38 | + protected $encryptionManager; |
|
39 | + |
|
40 | + /** @var IAppManager */ |
|
41 | + protected $appManager; |
|
42 | + |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | + |
|
46 | + /** @var QuestionHelper */ |
|
47 | + protected $questionHelper; |
|
48 | + |
|
49 | + /** @var bool */ |
|
50 | + protected $wasTrashbinEnabled; |
|
51 | + |
|
52 | + /** @var bool */ |
|
53 | + protected $wasMaintenanceModeEnabled; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param IManager $encryptionManager |
|
57 | + * @param IAppManager $appManager |
|
58 | + * @param IConfig $config |
|
59 | + * @param QuestionHelper $questionHelper |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + IManager $encryptionManager, |
|
63 | + IAppManager $appManager, |
|
64 | + IConfig $config, |
|
65 | + QuestionHelper $questionHelper |
|
66 | + ) { |
|
67 | + parent::__construct(); |
|
68 | + $this->appManager = $appManager; |
|
69 | + $this->encryptionManager = $encryptionManager; |
|
70 | + $this->config = $config; |
|
71 | + $this->questionHelper = $questionHelper; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Set maintenance mode and disable the trashbin app |
|
76 | + */ |
|
77 | + protected function forceMaintenanceAndTrashbin() { |
|
78 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
79 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
80 | + $this->config->setSystemValue('maintenance', true); |
|
81 | + $this->appManager->disableApp('files_trashbin'); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Reset the maintenance mode and re-enable the trashbin app |
|
86 | + */ |
|
87 | + protected function resetMaintenanceAndTrashbin() { |
|
88 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
89 | + if ($this->wasTrashbinEnabled) { |
|
90 | + $this->appManager->enableApp('files_trashbin'); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + protected function configure() { |
|
95 | + parent::configure(); |
|
96 | + |
|
97 | + $this->setName('encryption:encrypt-all'); |
|
98 | + $this->setDescription('Encrypt all files for all users'); |
|
99 | + $this->setHelp( |
|
100 | + 'This will encrypt all files for all users. ' |
|
101 | + . 'Please make sure that no user access his files during this process!' |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
106 | + |
|
107 | + if ($this->encryptionManager->isEnabled() === false) { |
|
108 | + throw new \Exception('Server side encryption is not enabled'); |
|
109 | + } |
|
110 | + |
|
111 | + $output->writeln("\n"); |
|
112 | + $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); |
|
113 | + $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); |
|
114 | + $output->writeln('Please ensure that no user accesses their files during this time!'); |
|
115 | + $output->writeln('Note: The encryption module you use determines which files get encrypted.'); |
|
116 | + $output->writeln(''); |
|
117 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
118 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
119 | + $this->forceMaintenanceAndTrashbin(); |
|
120 | + |
|
121 | + try { |
|
122 | + $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
123 | + $defaultModule->encryptAll($input, $output); |
|
124 | + } catch (\Exception $ex) { |
|
125 | + $this->resetMaintenanceAndTrashbin(); |
|
126 | + throw $ex; |
|
127 | + } |
|
128 | + |
|
129 | + $this->resetMaintenanceAndTrashbin(); |
|
130 | + } else { |
|
131 | + $output->writeln('aborted'); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * List all installed apps |
123 | 123 | * |
124 | - * @return string[] |
|
124 | + * @return integer[] |
|
125 | 125 | */ |
126 | 126 | public function getInstalledApps() { |
127 | 127 | return array_keys($this->getInstalledAppsValues()); |
@@ -382,6 +382,9 @@ discard block |
||
382 | 382 | return in_array($appId, $this->shippedApps, true); |
383 | 383 | } |
384 | 384 | |
385 | + /** |
|
386 | + * @param string $appId |
|
387 | + */ |
|
385 | 388 | private function isAlwaysEnabled($appId) { |
386 | 389 | $alwaysEnabled = $this->getAlwaysEnabledApps(); |
387 | 390 | return in_array($appId, $alwaysEnabled, true); |
@@ -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): string { |
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 && isset($appInfo['version'])) ? $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 | } |
@@ -44,418 +44,418 @@ |
||
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 enabled in the instance |
|
208 | - * |
|
209 | - * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
210 | - * |
|
211 | - * @param string $appId |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - public function isInstalled($appId) { |
|
215 | - $installedApps = $this->getInstalledAppsValues(); |
|
216 | - return isset($installedApps[$appId]); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Enable an app for every user |
|
221 | - * |
|
222 | - * @param string $appId |
|
223 | - * @throws AppPathNotFoundException |
|
224 | - */ |
|
225 | - public function enableApp($appId) { |
|
226 | - // Check if app exists |
|
227 | - $this->getAppPath($appId); |
|
228 | - |
|
229 | - $this->installedAppsCache[$appId] = 'yes'; |
|
230 | - $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
231 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
232 | - ManagerEvent::EVENT_APP_ENABLE, $appId |
|
233 | - )); |
|
234 | - $this->clearAppsCache(); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Whether a list of types contains a protected app type |
|
239 | - * |
|
240 | - * @param string[] $types |
|
241 | - * @return bool |
|
242 | - */ |
|
243 | - public function hasProtectedAppType($types) { |
|
244 | - if (empty($types)) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
249 | - return !empty($protectedTypes); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Enable an app only for specific groups |
|
254 | - * |
|
255 | - * @param string $appId |
|
256 | - * @param \OCP\IGroup[] $groups |
|
257 | - * @throws \Exception if app can't be enabled for groups |
|
258 | - */ |
|
259 | - public function enableAppForGroups($appId, $groups) { |
|
260 | - $info = $this->getAppInfo($appId); |
|
261 | - if (!empty($info['types'])) { |
|
262 | - $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
263 | - if (!empty($protectedTypes)) { |
|
264 | - throw new \Exception("$appId can't be enabled for groups."); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - $groupIds = array_map(function ($group) { |
|
269 | - /** @var \OCP\IGroup $group */ |
|
270 | - return $group->getGID(); |
|
271 | - }, $groups); |
|
272 | - $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
273 | - $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
274 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
275 | - ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
276 | - )); |
|
277 | - $this->clearAppsCache(); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Disable an app for every user |
|
282 | - * |
|
283 | - * @param string $appId |
|
284 | - * @throws \Exception if app can't be disabled |
|
285 | - */ |
|
286 | - public function disableApp($appId) { |
|
287 | - if ($this->isAlwaysEnabled($appId)) { |
|
288 | - throw new \Exception("$appId can't be disabled."); |
|
289 | - } |
|
290 | - unset($this->installedAppsCache[$appId]); |
|
291 | - $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
292 | - |
|
293 | - // run uninstall steps |
|
294 | - $appData = $this->getAppInfo($appId); |
|
295 | - if (!is_null($appData)) { |
|
296 | - \OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); |
|
297 | - } |
|
298 | - |
|
299 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
300 | - ManagerEvent::EVENT_APP_DISABLE, $appId |
|
301 | - )); |
|
302 | - $this->clearAppsCache(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Get the directory for the given app. |
|
307 | - * |
|
308 | - * @param string $appId |
|
309 | - * @return string |
|
310 | - * @throws AppPathNotFoundException if app folder can't be found |
|
311 | - */ |
|
312 | - public function getAppPath($appId) { |
|
313 | - $appPath = \OC_App::getAppPath($appId); |
|
314 | - if($appPath === false) { |
|
315 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
316 | - } |
|
317 | - return $appPath; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Clear the cached list of apps when enabling/disabling an app |
|
322 | - */ |
|
323 | - public function clearAppsCache() { |
|
324 | - $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
325 | - $settingsMemCache->clear('listApps'); |
|
326 | - $this->appInfos = []; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns a list of apps that need upgrade |
|
331 | - * |
|
332 | - * @param string $version Nextcloud version as array of version components |
|
333 | - * @return array list of app info from apps that need an upgrade |
|
334 | - * |
|
335 | - * @internal |
|
336 | - */ |
|
337 | - public function getAppsNeedingUpgrade($version) { |
|
338 | - $appsToUpgrade = []; |
|
339 | - $apps = $this->getInstalledApps(); |
|
340 | - foreach ($apps as $appId) { |
|
341 | - $appInfo = $this->getAppInfo($appId); |
|
342 | - $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
343 | - if ($appDbVersion |
|
344 | - && isset($appInfo['version']) |
|
345 | - && version_compare($appInfo['version'], $appDbVersion, '>') |
|
346 | - && \OC_App::isAppCompatible($version, $appInfo) |
|
347 | - ) { |
|
348 | - $appsToUpgrade[] = $appInfo; |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - return $appsToUpgrade; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns the app information from "appinfo/info.xml". |
|
357 | - * |
|
358 | - * @param string $appId app id |
|
359 | - * |
|
360 | - * @param bool $path |
|
361 | - * @param null $lang |
|
362 | - * @return array|null app info |
|
363 | - */ |
|
364 | - public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
365 | - if ($path) { |
|
366 | - $file = $appId; |
|
367 | - } else { |
|
368 | - if ($lang === null && isset($this->appInfos[$appId])) { |
|
369 | - return $this->appInfos[$appId]; |
|
370 | - } |
|
371 | - try { |
|
372 | - $appPath = $this->getAppPath($appId); |
|
373 | - } catch (AppPathNotFoundException $e) { |
|
374 | - return null; |
|
375 | - } |
|
376 | - $file = $appPath . '/appinfo/info.xml'; |
|
377 | - } |
|
378 | - |
|
379 | - $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
380 | - $data = $parser->parse($file); |
|
381 | - |
|
382 | - if (is_array($data)) { |
|
383 | - $data = \OC_App::parseAppInfo($data, $lang); |
|
384 | - } |
|
385 | - |
|
386 | - if ($lang === null) { |
|
387 | - $this->appInfos[$appId] = $data; |
|
388 | - } |
|
389 | - |
|
390 | - return $data; |
|
391 | - } |
|
392 | - |
|
393 | - public function getAppVersion(string $appId, bool $useCache = true): string { |
|
394 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
395 | - $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
396 | - $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; |
|
397 | - } |
|
398 | - return $this->appVersions[$appId]; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Returns a list of apps incompatible with the given version |
|
403 | - * |
|
404 | - * @param string $version Nextcloud version as array of version components |
|
405 | - * |
|
406 | - * @return array list of app info from incompatible apps |
|
407 | - * |
|
408 | - * @internal |
|
409 | - */ |
|
410 | - public function getIncompatibleApps(string $version): array { |
|
411 | - $apps = $this->getInstalledApps(); |
|
412 | - $incompatibleApps = array(); |
|
413 | - foreach ($apps as $appId) { |
|
414 | - $info = $this->getAppInfo($appId); |
|
415 | - if ($info === null) { |
|
416 | - $incompatibleApps[] = ['id' => $appId]; |
|
417 | - } else if (!\OC_App::isAppCompatible($version, $info)) { |
|
418 | - $incompatibleApps[] = $info; |
|
419 | - } |
|
420 | - } |
|
421 | - return $incompatibleApps; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * @inheritdoc |
|
426 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
427 | - */ |
|
428 | - public function isShipped($appId) { |
|
429 | - $this->loadShippedJson(); |
|
430 | - return in_array($appId, $this->shippedApps, true); |
|
431 | - } |
|
432 | - |
|
433 | - private function isAlwaysEnabled($appId) { |
|
434 | - $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
435 | - return in_array($appId, $alwaysEnabled, true); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
440 | - * @throws \Exception |
|
441 | - */ |
|
442 | - private function loadShippedJson() { |
|
443 | - if ($this->shippedApps === null) { |
|
444 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
445 | - if (!file_exists($shippedJson)) { |
|
446 | - throw new \Exception("File not found: $shippedJson"); |
|
447 | - } |
|
448 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
449 | - $this->shippedApps = $content['shippedApps']; |
|
450 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @inheritdoc |
|
456 | - */ |
|
457 | - public function getAlwaysEnabledApps() { |
|
458 | - $this->loadShippedJson(); |
|
459 | - return $this->alwaysEnabled; |
|
460 | - } |
|
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 enabled in the instance |
|
208 | + * |
|
209 | + * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
210 | + * |
|
211 | + * @param string $appId |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + public function isInstalled($appId) { |
|
215 | + $installedApps = $this->getInstalledAppsValues(); |
|
216 | + return isset($installedApps[$appId]); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Enable an app for every user |
|
221 | + * |
|
222 | + * @param string $appId |
|
223 | + * @throws AppPathNotFoundException |
|
224 | + */ |
|
225 | + public function enableApp($appId) { |
|
226 | + // Check if app exists |
|
227 | + $this->getAppPath($appId); |
|
228 | + |
|
229 | + $this->installedAppsCache[$appId] = 'yes'; |
|
230 | + $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
231 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
232 | + ManagerEvent::EVENT_APP_ENABLE, $appId |
|
233 | + )); |
|
234 | + $this->clearAppsCache(); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Whether a list of types contains a protected app type |
|
239 | + * |
|
240 | + * @param string[] $types |
|
241 | + * @return bool |
|
242 | + */ |
|
243 | + public function hasProtectedAppType($types) { |
|
244 | + if (empty($types)) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
249 | + return !empty($protectedTypes); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Enable an app only for specific groups |
|
254 | + * |
|
255 | + * @param string $appId |
|
256 | + * @param \OCP\IGroup[] $groups |
|
257 | + * @throws \Exception if app can't be enabled for groups |
|
258 | + */ |
|
259 | + public function enableAppForGroups($appId, $groups) { |
|
260 | + $info = $this->getAppInfo($appId); |
|
261 | + if (!empty($info['types'])) { |
|
262 | + $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
263 | + if (!empty($protectedTypes)) { |
|
264 | + throw new \Exception("$appId can't be enabled for groups."); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + $groupIds = array_map(function ($group) { |
|
269 | + /** @var \OCP\IGroup $group */ |
|
270 | + return $group->getGID(); |
|
271 | + }, $groups); |
|
272 | + $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
273 | + $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
274 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
275 | + ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
276 | + )); |
|
277 | + $this->clearAppsCache(); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Disable an app for every user |
|
282 | + * |
|
283 | + * @param string $appId |
|
284 | + * @throws \Exception if app can't be disabled |
|
285 | + */ |
|
286 | + public function disableApp($appId) { |
|
287 | + if ($this->isAlwaysEnabled($appId)) { |
|
288 | + throw new \Exception("$appId can't be disabled."); |
|
289 | + } |
|
290 | + unset($this->installedAppsCache[$appId]); |
|
291 | + $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
292 | + |
|
293 | + // run uninstall steps |
|
294 | + $appData = $this->getAppInfo($appId); |
|
295 | + if (!is_null($appData)) { |
|
296 | + \OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); |
|
297 | + } |
|
298 | + |
|
299 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
300 | + ManagerEvent::EVENT_APP_DISABLE, $appId |
|
301 | + )); |
|
302 | + $this->clearAppsCache(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Get the directory for the given app. |
|
307 | + * |
|
308 | + * @param string $appId |
|
309 | + * @return string |
|
310 | + * @throws AppPathNotFoundException if app folder can't be found |
|
311 | + */ |
|
312 | + public function getAppPath($appId) { |
|
313 | + $appPath = \OC_App::getAppPath($appId); |
|
314 | + if($appPath === false) { |
|
315 | + throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
316 | + } |
|
317 | + return $appPath; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Clear the cached list of apps when enabling/disabling an app |
|
322 | + */ |
|
323 | + public function clearAppsCache() { |
|
324 | + $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
325 | + $settingsMemCache->clear('listApps'); |
|
326 | + $this->appInfos = []; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns a list of apps that need upgrade |
|
331 | + * |
|
332 | + * @param string $version Nextcloud version as array of version components |
|
333 | + * @return array list of app info from apps that need an upgrade |
|
334 | + * |
|
335 | + * @internal |
|
336 | + */ |
|
337 | + public function getAppsNeedingUpgrade($version) { |
|
338 | + $appsToUpgrade = []; |
|
339 | + $apps = $this->getInstalledApps(); |
|
340 | + foreach ($apps as $appId) { |
|
341 | + $appInfo = $this->getAppInfo($appId); |
|
342 | + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
343 | + if ($appDbVersion |
|
344 | + && isset($appInfo['version']) |
|
345 | + && version_compare($appInfo['version'], $appDbVersion, '>') |
|
346 | + && \OC_App::isAppCompatible($version, $appInfo) |
|
347 | + ) { |
|
348 | + $appsToUpgrade[] = $appInfo; |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + return $appsToUpgrade; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns the app information from "appinfo/info.xml". |
|
357 | + * |
|
358 | + * @param string $appId app id |
|
359 | + * |
|
360 | + * @param bool $path |
|
361 | + * @param null $lang |
|
362 | + * @return array|null app info |
|
363 | + */ |
|
364 | + public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
365 | + if ($path) { |
|
366 | + $file = $appId; |
|
367 | + } else { |
|
368 | + if ($lang === null && isset($this->appInfos[$appId])) { |
|
369 | + return $this->appInfos[$appId]; |
|
370 | + } |
|
371 | + try { |
|
372 | + $appPath = $this->getAppPath($appId); |
|
373 | + } catch (AppPathNotFoundException $e) { |
|
374 | + return null; |
|
375 | + } |
|
376 | + $file = $appPath . '/appinfo/info.xml'; |
|
377 | + } |
|
378 | + |
|
379 | + $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
380 | + $data = $parser->parse($file); |
|
381 | + |
|
382 | + if (is_array($data)) { |
|
383 | + $data = \OC_App::parseAppInfo($data, $lang); |
|
384 | + } |
|
385 | + |
|
386 | + if ($lang === null) { |
|
387 | + $this->appInfos[$appId] = $data; |
|
388 | + } |
|
389 | + |
|
390 | + return $data; |
|
391 | + } |
|
392 | + |
|
393 | + public function getAppVersion(string $appId, bool $useCache = true): string { |
|
394 | + if(!$useCache || !isset($this->appVersions[$appId])) { |
|
395 | + $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
396 | + $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; |
|
397 | + } |
|
398 | + return $this->appVersions[$appId]; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Returns a list of apps incompatible with the given version |
|
403 | + * |
|
404 | + * @param string $version Nextcloud version as array of version components |
|
405 | + * |
|
406 | + * @return array list of app info from incompatible apps |
|
407 | + * |
|
408 | + * @internal |
|
409 | + */ |
|
410 | + public function getIncompatibleApps(string $version): array { |
|
411 | + $apps = $this->getInstalledApps(); |
|
412 | + $incompatibleApps = array(); |
|
413 | + foreach ($apps as $appId) { |
|
414 | + $info = $this->getAppInfo($appId); |
|
415 | + if ($info === null) { |
|
416 | + $incompatibleApps[] = ['id' => $appId]; |
|
417 | + } else if (!\OC_App::isAppCompatible($version, $info)) { |
|
418 | + $incompatibleApps[] = $info; |
|
419 | + } |
|
420 | + } |
|
421 | + return $incompatibleApps; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * @inheritdoc |
|
426 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
427 | + */ |
|
428 | + public function isShipped($appId) { |
|
429 | + $this->loadShippedJson(); |
|
430 | + return in_array($appId, $this->shippedApps, true); |
|
431 | + } |
|
432 | + |
|
433 | + private function isAlwaysEnabled($appId) { |
|
434 | + $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
435 | + return in_array($appId, $alwaysEnabled, true); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
440 | + * @throws \Exception |
|
441 | + */ |
|
442 | + private function loadShippedJson() { |
|
443 | + if ($this->shippedApps === null) { |
|
444 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
445 | + if (!file_exists($shippedJson)) { |
|
446 | + throw new \Exception("File not found: $shippedJson"); |
|
447 | + } |
|
448 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
449 | + $this->shippedApps = $content['shippedApps']; |
|
450 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @inheritdoc |
|
456 | + */ |
|
457 | + public function getAlwaysEnabledApps() { |
|
458 | + $this->loadShippedJson(); |
|
459 | + return $this->alwaysEnabled; |
|
460 | + } |
|
461 | 461 | } |
@@ -29,141 +29,141 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function(IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @return string|null image URI |
|
49 | - */ |
|
50 | - public function getAvatar(); |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @return string|null image URI |
|
49 | + */ |
|
50 | + public function getAvatar(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 12.0 |
|
54 | - * @param IAction $action an action to show in the contacts menu |
|
55 | - */ |
|
56 | - public function addAction(IAction $action); |
|
52 | + /** |
|
53 | + * @since 12.0 |
|
54 | + * @param IAction $action an action to show in the contacts menu |
|
55 | + */ |
|
56 | + public function addAction(IAction $action); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get an arbitrary property from the contact |
|
60 | - * |
|
61 | - * @since 12.0 |
|
62 | - * @param string $key |
|
63 | - * @return mixed the value of the property or null |
|
64 | - */ |
|
65 | - public function getProperty($key); |
|
58 | + /** |
|
59 | + * Get an arbitrary property from the contact |
|
60 | + * |
|
61 | + * @since 12.0 |
|
62 | + * @param string $key |
|
63 | + * @return mixed the value of the property or null |
|
64 | + */ |
|
65 | + public function getProperty($key); |
|
66 | 66 | } |
@@ -47,58 +47,58 @@ |
||
47 | 47 | */ |
48 | 48 | interface IContainer { |
49 | 49 | |
50 | - /** |
|
51 | - * If a parameter is not registered in the container try to instantiate it |
|
52 | - * by using reflection to find out how to build the class |
|
53 | - * @param string $name the class name to resolve |
|
54 | - * @return \stdClass |
|
55 | - * @since 8.2.0 |
|
56 | - * @throws QueryException if the class could not be found or instantiated |
|
57 | - */ |
|
58 | - public function resolve($name); |
|
50 | + /** |
|
51 | + * If a parameter is not registered in the container try to instantiate it |
|
52 | + * by using reflection to find out how to build the class |
|
53 | + * @param string $name the class name to resolve |
|
54 | + * @return \stdClass |
|
55 | + * @since 8.2.0 |
|
56 | + * @throws QueryException if the class could not be found or instantiated |
|
57 | + */ |
|
58 | + public function resolve($name); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Look up a service for a given name in the container. |
|
62 | - * |
|
63 | - * @param string $name |
|
64 | - * @return mixed |
|
65 | - * @throws QueryException if the query could not be resolved |
|
66 | - * @since 6.0.0 |
|
67 | - */ |
|
68 | - public function query($name); |
|
60 | + /** |
|
61 | + * Look up a service for a given name in the container. |
|
62 | + * |
|
63 | + * @param string $name |
|
64 | + * @return mixed |
|
65 | + * @throws QueryException if the query could not be resolved |
|
66 | + * @since 6.0.0 |
|
67 | + */ |
|
68 | + public function query($name); |
|
69 | 69 | |
70 | - /** |
|
71 | - * A value is stored in the container with it's corresponding name |
|
72 | - * |
|
73 | - * @param string $name |
|
74 | - * @param mixed $value |
|
75 | - * @return void |
|
76 | - * @since 6.0.0 |
|
77 | - */ |
|
78 | - public function registerParameter($name, $value); |
|
70 | + /** |
|
71 | + * A value is stored in the container with it's corresponding name |
|
72 | + * |
|
73 | + * @param string $name |
|
74 | + * @param mixed $value |
|
75 | + * @return void |
|
76 | + * @since 6.0.0 |
|
77 | + */ |
|
78 | + public function registerParameter($name, $value); |
|
79 | 79 | |
80 | - /** |
|
81 | - * A service is registered in the container where a closure is passed in which will actually |
|
82 | - * create the service on demand. |
|
83 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | - * memory and be reused on subsequent calls. |
|
85 | - * In case the parameter is false the service will be recreated on every call. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @param \Closure $closure |
|
89 | - * @param bool $shared |
|
90 | - * @return void |
|
91 | - * @since 6.0.0 |
|
92 | - */ |
|
93 | - public function registerService($name, Closure $closure, $shared = true); |
|
80 | + /** |
|
81 | + * A service is registered in the container where a closure is passed in which will actually |
|
82 | + * create the service on demand. |
|
83 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | + * memory and be reused on subsequent calls. |
|
85 | + * In case the parameter is false the service will be recreated on every call. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @param \Closure $closure |
|
89 | + * @param bool $shared |
|
90 | + * @return void |
|
91 | + * @since 6.0.0 |
|
92 | + */ |
|
93 | + public function registerService($name, Closure $closure, $shared = true); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Shortcut for returning a service from a service under a different key, |
|
97 | - * e.g. to tell the container to return a class when queried for an |
|
98 | - * interface |
|
99 | - * @param string $alias the alias that should be registered |
|
100 | - * @param string $target the target that should be resolved instead |
|
101 | - * @since 8.2.0 |
|
102 | - */ |
|
103 | - public function registerAlias($alias, $target); |
|
95 | + /** |
|
96 | + * Shortcut for returning a service from a service under a different key, |
|
97 | + * e.g. to tell the container to return a class when queried for an |
|
98 | + * interface |
|
99 | + * @param string $alias the alias that should be registered |
|
100 | + * @param string $target the target that should be resolved instead |
|
101 | + * @since 8.2.0 |
|
102 | + */ |
|
103 | + public function registerAlias($alias, $target); |
|
104 | 104 | } |
@@ -30,6 +30,9 @@ discard block |
||
30 | 30 | /** @var JSCombiner */ |
31 | 31 | protected $jsCombiner; |
32 | 32 | |
33 | + /** |
|
34 | + * @param string $theme |
|
35 | + */ |
|
33 | 36 | public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
34 | 37 | parent::__construct($logger, $theme, $core_map, $party_map); |
35 | 38 | |
@@ -91,6 +94,9 @@ discard block |
||
91 | 94 | public function doFindTheme($script) { |
92 | 95 | } |
93 | 96 | |
97 | + /** |
|
98 | + * @param string $file |
|
99 | + */ |
|
94 | 100 | protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
95 | 101 | if (is_file($root.'/'.$file)) { |
96 | 102 | if ($this->jsCombiner->process($root, $file, $app)) { |
@@ -71,26 +71,26 @@ |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $app = substr($script, 0, strpos($script, '/')); |
74 | - $script = substr($script, strpos($script, '/')+1); |
|
74 | + $script = substr($script, strpos($script, '/') + 1); |
|
75 | 75 | $app_path = \OC_App::getAppPath($app); |
76 | 76 | $app_url = \OC_App::getAppWebPath($app); |
77 | 77 | |
78 | 78 | // missing translations files fill be ignored |
79 | 79 | if (strpos($script, 'l10n/') === 0) { |
80 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
80 | + $this->appendIfExist($app_path, $script.'.js', $app_url); |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | 84 | if ($app_path === false && $app_url === false) { |
85 | 85 | $this->logger->error('Could not find resource {resource} to load', [ |
86 | - 'resource' => $app . '/' . $script . '.js', |
|
86 | + 'resource' => $app.'/'.$script.'.js', |
|
87 | 87 | 'app' => 'jsresourceloader', |
88 | 88 | ]); |
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | 92 | if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
93 | - $this->append($app_path, $script . '.js', $app_url); |
|
93 | + $this->append($app_path, $script.'.js', $app_url); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 |
@@ -28,102 +28,102 @@ |
||
28 | 28 | |
29 | 29 | class JSResourceLocator extends ResourceLocator { |
30 | 30 | |
31 | - /** @var JSCombiner */ |
|
32 | - protected $jsCombiner; |
|
33 | - |
|
34 | - public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
35 | - parent::__construct($logger, $theme, $core_map, $party_map); |
|
36 | - |
|
37 | - $this->jsCombiner = $JSCombiner; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string $script |
|
42 | - */ |
|
43 | - public function doFind($script) { |
|
44 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
45 | - if (strpos($script, '3rdparty') === 0 |
|
46 | - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
47 | - return; |
|
48 | - } |
|
49 | - |
|
50 | - if (strpos($script, '/l10n/') !== false) { |
|
51 | - // For language files we try to load them all, so themes can overwrite |
|
52 | - // single l10n strings without having to translate all of them. |
|
53 | - $found = 0; |
|
54 | - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
55 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
56 | - $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
57 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
58 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
59 | - |
|
60 | - if ($found) { |
|
61 | - return; |
|
62 | - } |
|
63 | - } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
64 | - || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
65 | - || $this->appendIfExist($this->serverroot, $script.'.js') |
|
66 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
67 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
68 | - || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
69 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
70 | - ) { |
|
71 | - return; |
|
72 | - } |
|
73 | - |
|
74 | - $app = substr($script, 0, strpos($script, '/')); |
|
75 | - $script = substr($script, strpos($script, '/')+1); |
|
76 | - $app_path = \OC_App::getAppPath($app); |
|
77 | - $app_url = \OC_App::getAppWebPath($app); |
|
78 | - |
|
79 | - if ($app_path !== false) { |
|
80 | - // Account for the possibility of having symlinks in app path. Only |
|
81 | - // do this if $app_path is set, because an empty argument to realpath |
|
82 | - // gets turned into cwd. |
|
83 | - $app_path = realpath($app_path); |
|
84 | - } |
|
85 | - |
|
86 | - // missing translations files fill be ignored |
|
87 | - if (strpos($script, 'l10n/') === 0) { |
|
88 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
89 | - return; |
|
90 | - } |
|
91 | - |
|
92 | - if ($app_path === false && $app_url === false) { |
|
93 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
94 | - 'resource' => $app . '/' . $script . '.js', |
|
95 | - 'app' => 'jsresourceloader', |
|
96 | - ]); |
|
97 | - return; |
|
98 | - } |
|
99 | - |
|
100 | - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
101 | - $this->append($app_path, $script . '.js', $app_url); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $script |
|
107 | - */ |
|
108 | - public function doFindTheme($script) { |
|
109 | - } |
|
110 | - |
|
111 | - protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
112 | - if (is_file($root.'/'.$file)) { |
|
113 | - if ($this->jsCombiner->process($root, $file, $app)) { |
|
114 | - $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
115 | - } else { |
|
116 | - // Add all the files from the json |
|
117 | - $files = $this->jsCombiner->getContent($root, $file); |
|
118 | - $app_url = \OC_App::getAppWebPath($app); |
|
119 | - |
|
120 | - foreach ($files as $jsFile) { |
|
121 | - $this->append($root, $jsFile, $app_url); |
|
122 | - } |
|
123 | - } |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
31 | + /** @var JSCombiner */ |
|
32 | + protected $jsCombiner; |
|
33 | + |
|
34 | + public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
35 | + parent::__construct($logger, $theme, $core_map, $party_map); |
|
36 | + |
|
37 | + $this->jsCombiner = $JSCombiner; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string $script |
|
42 | + */ |
|
43 | + public function doFind($script) { |
|
44 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
45 | + if (strpos($script, '3rdparty') === 0 |
|
46 | + && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
47 | + return; |
|
48 | + } |
|
49 | + |
|
50 | + if (strpos($script, '/l10n/') !== false) { |
|
51 | + // For language files we try to load them all, so themes can overwrite |
|
52 | + // single l10n strings without having to translate all of them. |
|
53 | + $found = 0; |
|
54 | + $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
55 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
56 | + $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
57 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
58 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
59 | + |
|
60 | + if ($found) { |
|
61 | + return; |
|
62 | + } |
|
63 | + } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
64 | + || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
65 | + || $this->appendIfExist($this->serverroot, $script.'.js') |
|
66 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
67 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
68 | + || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
69 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
70 | + ) { |
|
71 | + return; |
|
72 | + } |
|
73 | + |
|
74 | + $app = substr($script, 0, strpos($script, '/')); |
|
75 | + $script = substr($script, strpos($script, '/')+1); |
|
76 | + $app_path = \OC_App::getAppPath($app); |
|
77 | + $app_url = \OC_App::getAppWebPath($app); |
|
78 | + |
|
79 | + if ($app_path !== false) { |
|
80 | + // Account for the possibility of having symlinks in app path. Only |
|
81 | + // do this if $app_path is set, because an empty argument to realpath |
|
82 | + // gets turned into cwd. |
|
83 | + $app_path = realpath($app_path); |
|
84 | + } |
|
85 | + |
|
86 | + // missing translations files fill be ignored |
|
87 | + if (strpos($script, 'l10n/') === 0) { |
|
88 | + $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
89 | + return; |
|
90 | + } |
|
91 | + |
|
92 | + if ($app_path === false && $app_url === false) { |
|
93 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
94 | + 'resource' => $app . '/' . $script . '.js', |
|
95 | + 'app' => 'jsresourceloader', |
|
96 | + ]); |
|
97 | + return; |
|
98 | + } |
|
99 | + |
|
100 | + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
101 | + $this->append($app_path, $script . '.js', $app_url); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $script |
|
107 | + */ |
|
108 | + public function doFindTheme($script) { |
|
109 | + } |
|
110 | + |
|
111 | + protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
112 | + if (is_file($root.'/'.$file)) { |
|
113 | + if ($this->jsCombiner->process($root, $file, $app)) { |
|
114 | + $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
115 | + } else { |
|
116 | + // Add all the files from the json |
|
117 | + $files = $this->jsCombiner->getContent($root, $file); |
|
118 | + $app_url = \OC_App::getAppWebPath($app); |
|
119 | + |
|
120 | + foreach ($files as $jsFile) { |
|
121 | + $this->append($root, $jsFile, $app_url); |
|
122 | + } |
|
123 | + } |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | } |