@@ -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 | } |
@@ -33,174 +33,174 @@ |
||
| 33 | 33 | use OCP\Share\IManager; |
| 34 | 34 | |
| 35 | 35 | class MountProvider implements IMountProvider { |
| 36 | - /** |
|
| 37 | - * @var \OCP\IConfig |
|
| 38 | - */ |
|
| 39 | - protected $config; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var IManager |
|
| 43 | - */ |
|
| 44 | - protected $shareManager; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var ILogger |
|
| 48 | - */ |
|
| 49 | - protected $logger; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param \OCP\IConfig $config |
|
| 53 | - * @param IManager $shareManager |
|
| 54 | - * @param ILogger $logger |
|
| 55 | - */ |
|
| 56 | - public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
| 57 | - $this->config = $config; |
|
| 58 | - $this->shareManager = $shareManager; |
|
| 59 | - $this->logger = $logger; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
| 65 | - * |
|
| 66 | - * @param \OCP\IUser $user |
|
| 67 | - * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
| 68 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 69 | - */ |
|
| 70 | - public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
| 71 | - |
|
| 72 | - $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
| 73 | - $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
| 74 | - $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
|
| 75 | - |
|
| 76 | - // filter out excluded shares and group shares that includes self |
|
| 77 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
| 78 | - return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
| 79 | - }); |
|
| 80 | - |
|
| 81 | - $superShares = $this->buildSuperShares($shares, $user); |
|
| 82 | - |
|
| 83 | - $mounts = []; |
|
| 84 | - foreach ($superShares as $share) { |
|
| 85 | - try { |
|
| 86 | - $mounts[] = new SharedMount( |
|
| 87 | - '\OCA\Files_Sharing\SharedStorage', |
|
| 88 | - $mounts, |
|
| 89 | - [ |
|
| 90 | - 'user' => $user->getUID(), |
|
| 91 | - // parent share |
|
| 92 | - 'superShare' => $share[0], |
|
| 93 | - // children/component of the superShare |
|
| 94 | - 'groupedShares' => $share[1], |
|
| 95 | - ], |
|
| 96 | - $storageFactory |
|
| 97 | - ); |
|
| 98 | - } catch (\Exception $e) { |
|
| 99 | - $this->logger->logException($e); |
|
| 100 | - $this->logger->error('Error while trying to create shared mount'); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // array_filter removes the null values from the array |
|
| 105 | - return array_filter($mounts); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Groups shares by path (nodeId) and target path |
|
| 110 | - * |
|
| 111 | - * @param \OCP\Share\IShare[] $shares |
|
| 112 | - * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
| 113 | - * array is a group which itself is an array of shares |
|
| 114 | - */ |
|
| 115 | - private function groupShares(array $shares) { |
|
| 116 | - $tmp = []; |
|
| 117 | - |
|
| 118 | - foreach ($shares as $share) { |
|
| 119 | - if (!isset($tmp[$share->getNodeId()])) { |
|
| 120 | - $tmp[$share->getNodeId()] = []; |
|
| 121 | - } |
|
| 122 | - $tmp[$share->getNodeId()][] = $share; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $result = []; |
|
| 126 | - // sort by stime, the super share will be based on the least recent share |
|
| 127 | - foreach ($tmp as &$tmp2) { |
|
| 128 | - @usort($tmp2, function($a, $b) { |
|
| 129 | - if ($a->getShareTime() <= $b->getShareTime()) { |
|
| 130 | - return -1; |
|
| 131 | - } |
|
| 132 | - return 1; |
|
| 133 | - }); |
|
| 134 | - $result[] = $tmp2; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return array_values($result); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Build super shares (virtual share) by grouping them by node id and target, |
|
| 142 | - * then for each group compute the super share and return it along with the matching |
|
| 143 | - * grouped shares. The most permissive permissions are used based on the permissions |
|
| 144 | - * of all shares within the group. |
|
| 145 | - * |
|
| 146 | - * @param \OCP\Share\IShare[] $allShares |
|
| 147 | - * @param \OCP\IUser $user user |
|
| 148 | - * @return array Tuple of [superShare, groupedShares] |
|
| 149 | - */ |
|
| 150 | - private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
| 151 | - $result = []; |
|
| 152 | - |
|
| 153 | - $groupedShares = $this->groupShares($allShares); |
|
| 154 | - |
|
| 155 | - /** @var \OCP\Share\IShare[] $shares */ |
|
| 156 | - foreach ($groupedShares as $shares) { |
|
| 157 | - if (count($shares) === 0) { |
|
| 158 | - continue; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $superShare = $this->shareManager->newShare(); |
|
| 162 | - |
|
| 163 | - // compute super share based on first entry of the group |
|
| 164 | - $superShare->setId($shares[0]->getId()) |
|
| 165 | - ->setShareOwner($shares[0]->getShareOwner()) |
|
| 166 | - ->setNodeId($shares[0]->getNodeId()) |
|
| 167 | - ->setTarget($shares[0]->getTarget()); |
|
| 168 | - |
|
| 169 | - // use most permissive permissions |
|
| 170 | - $permissions = 0; |
|
| 171 | - foreach ($shares as $share) { |
|
| 172 | - $permissions |= $share->getPermissions(); |
|
| 173 | - if ($share->getTarget() !== $superShare->getTarget()) { |
|
| 174 | - // adjust target, for database consistency |
|
| 175 | - $share->setTarget($superShare->getTarget()); |
|
| 176 | - try { |
|
| 177 | - $this->shareManager->moveShare($share, $user->getUID()); |
|
| 178 | - } catch (\InvalidArgumentException $e) { |
|
| 179 | - // ignore as it is not important and we don't want to |
|
| 180 | - // block FS setup |
|
| 181 | - |
|
| 182 | - // the subsequent code anyway only uses the target of the |
|
| 183 | - // super share |
|
| 184 | - |
|
| 185 | - // such issue can usually happen when dealing with |
|
| 186 | - // null groups which usually appear with group backend |
|
| 187 | - // caching inconsistencies |
|
| 188 | - $this->logger->debug( |
|
| 189 | - 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
| 190 | - ['app' => 'files_sharing'] |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if (!is_null($share->getNodeCacheEntry())) { |
|
| 195 | - $superShare->setNodeCacheEntry($share->getNodeCacheEntry()); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $superShare->setPermissions($permissions); |
|
| 200 | - |
|
| 201 | - $result[] = [$superShare, $shares]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $result; |
|
| 205 | - } |
|
| 36 | + /** |
|
| 37 | + * @var \OCP\IConfig |
|
| 38 | + */ |
|
| 39 | + protected $config; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var IManager |
|
| 43 | + */ |
|
| 44 | + protected $shareManager; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var ILogger |
|
| 48 | + */ |
|
| 49 | + protected $logger; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param \OCP\IConfig $config |
|
| 53 | + * @param IManager $shareManager |
|
| 54 | + * @param ILogger $logger |
|
| 55 | + */ |
|
| 56 | + public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
| 57 | + $this->config = $config; |
|
| 58 | + $this->shareManager = $shareManager; |
|
| 59 | + $this->logger = $logger; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
| 65 | + * |
|
| 66 | + * @param \OCP\IUser $user |
|
| 67 | + * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
| 68 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 69 | + */ |
|
| 70 | + public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
| 71 | + |
|
| 72 | + $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
| 73 | + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
| 74 | + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
|
| 75 | + |
|
| 76 | + // filter out excluded shares and group shares that includes self |
|
| 77 | + $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
| 78 | + return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
| 79 | + }); |
|
| 80 | + |
|
| 81 | + $superShares = $this->buildSuperShares($shares, $user); |
|
| 82 | + |
|
| 83 | + $mounts = []; |
|
| 84 | + foreach ($superShares as $share) { |
|
| 85 | + try { |
|
| 86 | + $mounts[] = new SharedMount( |
|
| 87 | + '\OCA\Files_Sharing\SharedStorage', |
|
| 88 | + $mounts, |
|
| 89 | + [ |
|
| 90 | + 'user' => $user->getUID(), |
|
| 91 | + // parent share |
|
| 92 | + 'superShare' => $share[0], |
|
| 93 | + // children/component of the superShare |
|
| 94 | + 'groupedShares' => $share[1], |
|
| 95 | + ], |
|
| 96 | + $storageFactory |
|
| 97 | + ); |
|
| 98 | + } catch (\Exception $e) { |
|
| 99 | + $this->logger->logException($e); |
|
| 100 | + $this->logger->error('Error while trying to create shared mount'); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // array_filter removes the null values from the array |
|
| 105 | + return array_filter($mounts); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Groups shares by path (nodeId) and target path |
|
| 110 | + * |
|
| 111 | + * @param \OCP\Share\IShare[] $shares |
|
| 112 | + * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
| 113 | + * array is a group which itself is an array of shares |
|
| 114 | + */ |
|
| 115 | + private function groupShares(array $shares) { |
|
| 116 | + $tmp = []; |
|
| 117 | + |
|
| 118 | + foreach ($shares as $share) { |
|
| 119 | + if (!isset($tmp[$share->getNodeId()])) { |
|
| 120 | + $tmp[$share->getNodeId()] = []; |
|
| 121 | + } |
|
| 122 | + $tmp[$share->getNodeId()][] = $share; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $result = []; |
|
| 126 | + // sort by stime, the super share will be based on the least recent share |
|
| 127 | + foreach ($tmp as &$tmp2) { |
|
| 128 | + @usort($tmp2, function($a, $b) { |
|
| 129 | + if ($a->getShareTime() <= $b->getShareTime()) { |
|
| 130 | + return -1; |
|
| 131 | + } |
|
| 132 | + return 1; |
|
| 133 | + }); |
|
| 134 | + $result[] = $tmp2; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return array_values($result); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Build super shares (virtual share) by grouping them by node id and target, |
|
| 142 | + * then for each group compute the super share and return it along with the matching |
|
| 143 | + * grouped shares. The most permissive permissions are used based on the permissions |
|
| 144 | + * of all shares within the group. |
|
| 145 | + * |
|
| 146 | + * @param \OCP\Share\IShare[] $allShares |
|
| 147 | + * @param \OCP\IUser $user user |
|
| 148 | + * @return array Tuple of [superShare, groupedShares] |
|
| 149 | + */ |
|
| 150 | + private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
| 151 | + $result = []; |
|
| 152 | + |
|
| 153 | + $groupedShares = $this->groupShares($allShares); |
|
| 154 | + |
|
| 155 | + /** @var \OCP\Share\IShare[] $shares */ |
|
| 156 | + foreach ($groupedShares as $shares) { |
|
| 157 | + if (count($shares) === 0) { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $superShare = $this->shareManager->newShare(); |
|
| 162 | + |
|
| 163 | + // compute super share based on first entry of the group |
|
| 164 | + $superShare->setId($shares[0]->getId()) |
|
| 165 | + ->setShareOwner($shares[0]->getShareOwner()) |
|
| 166 | + ->setNodeId($shares[0]->getNodeId()) |
|
| 167 | + ->setTarget($shares[0]->getTarget()); |
|
| 168 | + |
|
| 169 | + // use most permissive permissions |
|
| 170 | + $permissions = 0; |
|
| 171 | + foreach ($shares as $share) { |
|
| 172 | + $permissions |= $share->getPermissions(); |
|
| 173 | + if ($share->getTarget() !== $superShare->getTarget()) { |
|
| 174 | + // adjust target, for database consistency |
|
| 175 | + $share->setTarget($superShare->getTarget()); |
|
| 176 | + try { |
|
| 177 | + $this->shareManager->moveShare($share, $user->getUID()); |
|
| 178 | + } catch (\InvalidArgumentException $e) { |
|
| 179 | + // ignore as it is not important and we don't want to |
|
| 180 | + // block FS setup |
|
| 181 | + |
|
| 182 | + // the subsequent code anyway only uses the target of the |
|
| 183 | + // super share |
|
| 184 | + |
|
| 185 | + // such issue can usually happen when dealing with |
|
| 186 | + // null groups which usually appear with group backend |
|
| 187 | + // caching inconsistencies |
|
| 188 | + $this->logger->debug( |
|
| 189 | + 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
| 190 | + ['app' => 'files_sharing'] |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + if (!is_null($share->getNodeCacheEntry())) { |
|
| 195 | + $superShare->setNodeCacheEntry($share->getNodeCacheEntry()); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $superShare->setPermissions($permissions); |
|
| 200 | + |
|
| 201 | + $result[] = [$superShare, $shares]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $result; |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)); |
| 75 | 75 | |
| 76 | 76 | // filter out excluded shares and group shares that includes self |
| 77 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
| 77 | + $shares = array_filter($shares, function(\OCP\Share\IShare $share) use ($user) { |
|
| 78 | 78 | return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
| 79 | 79 | }); |
| 80 | 80 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | // null groups which usually appear with group backend |
| 187 | 187 | // caching inconsistencies |
| 188 | 188 | $this->logger->debug( |
| 189 | - 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(), |
|
| 189 | + 'Could not adjust share target for share '.$share->getId().' to make it consistent: '.$e->getMessage(), |
|
| 190 | 190 | ['app' => 'files_sharing'] |
| 191 | 191 | ); |
| 192 | 192 | } |
@@ -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 | } |
@@ -35,144 +35,144 @@ |
||
| 35 | 35 | use OCP\IUser; |
| 36 | 36 | |
| 37 | 37 | class MountProviderCollection implements IMountProviderCollection, Emitter { |
| 38 | - use EmitterTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var \OCP\Files\Config\IHomeMountProvider[] |
|
| 42 | - */ |
|
| 43 | - private $homeProviders = []; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var \OCP\Files\Config\IMountProvider[] |
|
| 47 | - */ |
|
| 48 | - private $providers = array(); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var \OCP\Files\Storage\IStorageFactory |
|
| 52 | - */ |
|
| 53 | - private $loader; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var \OCP\Files\Config\IUserMountCache |
|
| 57 | - */ |
|
| 58 | - private $mountCache; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 62 | - * @param IUserMountCache $mountCache |
|
| 63 | - */ |
|
| 64 | - public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
| 65 | - $this->loader = $loader; |
|
| 66 | - $this->mountCache = $mountCache; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get all configured mount points for the user |
|
| 71 | - * |
|
| 72 | - * @param \OCP\IUser $user |
|
| 73 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 74 | - */ |
|
| 75 | - public function getMountsForUser(IUser $user) { |
|
| 76 | - $loader = $this->loader; |
|
| 77 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 78 | - return $provider->getMountsForUser($user, $loader); |
|
| 79 | - }, $this->providers); |
|
| 80 | - $mounts = array_filter($mounts, function ($result) { |
|
| 81 | - return is_array($result); |
|
| 82 | - }); |
|
| 83 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 84 | - return array_merge($mounts, $providerMounts); |
|
| 85 | - }, array()); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function addMountForUser(IUser $user, IMountManager $mountManager) { |
|
| 89 | - // shared mount provider gets to go last since it needs to know existing files |
|
| 90 | - // to check for name collisions |
|
| 91 | - $firstMounts = []; |
|
| 92 | - $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 93 | - return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
|
| 94 | - }); |
|
| 95 | - $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 96 | - return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
|
| 97 | - }); |
|
| 98 | - foreach ($firstProviders as $provider) { |
|
| 99 | - $mounts = $provider->getMountsForUser($user, $this->loader); |
|
| 100 | - if (is_array($mounts)) { |
|
| 101 | - $firstMounts = array_merge($firstMounts, $mounts); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - array_walk($firstMounts, [$mountManager, 'addMount']); |
|
| 105 | - |
|
| 106 | - $lateMounts = []; |
|
| 107 | - foreach ($lastProviders as $provider) { |
|
| 108 | - $mounts = $provider->getMountsForUser($user, $this->loader); |
|
| 109 | - if (is_array($mounts)) { |
|
| 110 | - $lateMounts = array_merge($lateMounts, $mounts); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - array_walk($lateMounts, [$mountManager, 'addMount']); |
|
| 115 | - |
|
| 116 | - return array_merge($lateMounts, $firstMounts); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get the configured home mount for this user |
|
| 121 | - * |
|
| 122 | - * @param \OCP\IUser $user |
|
| 123 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 124 | - * @since 9.1.0 |
|
| 125 | - */ |
|
| 126 | - public function getHomeMountForUser(IUser $user) { |
|
| 127 | - /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
| 128 | - $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
| 129 | - foreach ($providers as $homeProvider) { |
|
| 130 | - if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
| 131 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 132 | - return $mount; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - throw new \Exception('No home storage configured for user ' . $user); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Add a provider for mount points |
|
| 140 | - * |
|
| 141 | - * @param \OCP\Files\Config\IMountProvider $provider |
|
| 142 | - */ |
|
| 143 | - public function registerProvider(IMountProvider $provider) { |
|
| 144 | - $this->providers[] = $provider; |
|
| 145 | - |
|
| 146 | - $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Add a provider for home mount points |
|
| 151 | - * |
|
| 152 | - * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
| 153 | - * @since 9.1.0 |
|
| 154 | - */ |
|
| 155 | - public function registerHomeProvider(IHomeMountProvider $provider) { |
|
| 156 | - $this->homeProviders[] = $provider; |
|
| 157 | - $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Cache mounts for user |
|
| 162 | - * |
|
| 163 | - * @param IUser $user |
|
| 164 | - * @param IMountPoint[] $mountPoints |
|
| 165 | - */ |
|
| 166 | - public function registerMounts(IUser $user, array $mountPoints) { |
|
| 167 | - $this->mountCache->registerMounts($user, $mountPoints); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
| 172 | - * |
|
| 173 | - * @return IUserMountCache |
|
| 174 | - */ |
|
| 175 | - public function getMountCache() { |
|
| 176 | - return $this->mountCache; |
|
| 177 | - } |
|
| 38 | + use EmitterTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var \OCP\Files\Config\IHomeMountProvider[] |
|
| 42 | + */ |
|
| 43 | + private $homeProviders = []; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var \OCP\Files\Config\IMountProvider[] |
|
| 47 | + */ |
|
| 48 | + private $providers = array(); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var \OCP\Files\Storage\IStorageFactory |
|
| 52 | + */ |
|
| 53 | + private $loader; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var \OCP\Files\Config\IUserMountCache |
|
| 57 | + */ |
|
| 58 | + private $mountCache; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 62 | + * @param IUserMountCache $mountCache |
|
| 63 | + */ |
|
| 64 | + public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
| 65 | + $this->loader = $loader; |
|
| 66 | + $this->mountCache = $mountCache; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get all configured mount points for the user |
|
| 71 | + * |
|
| 72 | + * @param \OCP\IUser $user |
|
| 73 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 74 | + */ |
|
| 75 | + public function getMountsForUser(IUser $user) { |
|
| 76 | + $loader = $this->loader; |
|
| 77 | + $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 78 | + return $provider->getMountsForUser($user, $loader); |
|
| 79 | + }, $this->providers); |
|
| 80 | + $mounts = array_filter($mounts, function ($result) { |
|
| 81 | + return is_array($result); |
|
| 82 | + }); |
|
| 83 | + return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 84 | + return array_merge($mounts, $providerMounts); |
|
| 85 | + }, array()); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function addMountForUser(IUser $user, IMountManager $mountManager) { |
|
| 89 | + // shared mount provider gets to go last since it needs to know existing files |
|
| 90 | + // to check for name collisions |
|
| 91 | + $firstMounts = []; |
|
| 92 | + $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 93 | + return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
|
| 94 | + }); |
|
| 95 | + $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 96 | + return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
|
| 97 | + }); |
|
| 98 | + foreach ($firstProviders as $provider) { |
|
| 99 | + $mounts = $provider->getMountsForUser($user, $this->loader); |
|
| 100 | + if (is_array($mounts)) { |
|
| 101 | + $firstMounts = array_merge($firstMounts, $mounts); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + array_walk($firstMounts, [$mountManager, 'addMount']); |
|
| 105 | + |
|
| 106 | + $lateMounts = []; |
|
| 107 | + foreach ($lastProviders as $provider) { |
|
| 108 | + $mounts = $provider->getMountsForUser($user, $this->loader); |
|
| 109 | + if (is_array($mounts)) { |
|
| 110 | + $lateMounts = array_merge($lateMounts, $mounts); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + array_walk($lateMounts, [$mountManager, 'addMount']); |
|
| 115 | + |
|
| 116 | + return array_merge($lateMounts, $firstMounts); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get the configured home mount for this user |
|
| 121 | + * |
|
| 122 | + * @param \OCP\IUser $user |
|
| 123 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 124 | + * @since 9.1.0 |
|
| 125 | + */ |
|
| 126 | + public function getHomeMountForUser(IUser $user) { |
|
| 127 | + /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
| 128 | + $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
| 129 | + foreach ($providers as $homeProvider) { |
|
| 130 | + if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
| 131 | + $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 132 | + return $mount; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + throw new \Exception('No home storage configured for user ' . $user); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Add a provider for mount points |
|
| 140 | + * |
|
| 141 | + * @param \OCP\Files\Config\IMountProvider $provider |
|
| 142 | + */ |
|
| 143 | + public function registerProvider(IMountProvider $provider) { |
|
| 144 | + $this->providers[] = $provider; |
|
| 145 | + |
|
| 146 | + $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Add a provider for home mount points |
|
| 151 | + * |
|
| 152 | + * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
| 153 | + * @since 9.1.0 |
|
| 154 | + */ |
|
| 155 | + public function registerHomeProvider(IHomeMountProvider $provider) { |
|
| 156 | + $this->homeProviders[] = $provider; |
|
| 157 | + $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Cache mounts for user |
|
| 162 | + * |
|
| 163 | + * @param IUser $user |
|
| 164 | + * @param IMountPoint[] $mountPoints |
|
| 165 | + */ |
|
| 166 | + public function registerMounts(IUser $user, array $mountPoints) { |
|
| 167 | + $this->mountCache->registerMounts($user, $mountPoints); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
| 172 | + * |
|
| 173 | + * @return IUserMountCache |
|
| 174 | + */ |
|
| 175 | + public function getMountCache() { |
|
| 176 | + return $this->mountCache; |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getMountsForUser(IUser $user) { |
| 76 | 76 | $loader = $this->loader; |
| 77 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 77 | + $mounts = array_map(function(IMountProvider $provider) use ($user, $loader) { |
|
| 78 | 78 | return $provider->getMountsForUser($user, $loader); |
| 79 | 79 | }, $this->providers); |
| 80 | - $mounts = array_filter($mounts, function ($result) { |
|
| 80 | + $mounts = array_filter($mounts, function($result) { |
|
| 81 | 81 | return is_array($result); |
| 82 | 82 | }); |
| 83 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 83 | + return array_reduce($mounts, function(array $mounts, array $providerMounts) { |
|
| 84 | 84 | return array_merge($mounts, $providerMounts); |
| 85 | 85 | }, array()); |
| 86 | 86 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | // shared mount provider gets to go last since it needs to know existing files |
| 90 | 90 | // to check for name collisions |
| 91 | 91 | $firstMounts = []; |
| 92 | - $firstProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 92 | + $firstProviders = array_filter($this->providers, function(IMountProvider $provider) { |
|
| 93 | 93 | return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider'); |
| 94 | 94 | }); |
| 95 | - $lastProviders = array_filter($this->providers, function (IMountProvider $provider) { |
|
| 95 | + $lastProviders = array_filter($this->providers, function(IMountProvider $provider) { |
|
| 96 | 96 | return (get_class($provider) === 'OCA\Files_Sharing\MountProvider'); |
| 97 | 97 | }); |
| 98 | 98 | foreach ($firstProviders as $provider) { |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
| 129 | 129 | foreach ($providers as $homeProvider) { |
| 130 | 130 | if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
| 131 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 131 | + $mount->setMountPoint('/'.$user->getUID()); //make sure the mountpoint is what we expect |
|
| 132 | 132 | return $mount; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | - throw new \Exception('No home storage configured for user ' . $user); |
|
| 135 | + throw new \Exception('No home storage configured for user '.$user); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $result = array(); |
| 45 | 45 | $timestamp = null; |
| 46 | 46 | |
| 47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
| 48 | 48 | |
| 49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
| 50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
| 73 | 73 | } |
| 74 | 74 | $originalPath = ''; |
| 75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 75 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
| 76 | 76 | if (isset($originalLocations[$originalName][$timestamp])) { |
| 77 | 77 | $originalPath = $originalLocations[$originalName][$timestamp]; |
| 78 | 78 | if (substr($originalPath, -1) === '/') { |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | ); |
| 93 | 93 | if ($originalPath) { |
| 94 | 94 | if ($originalPath !== '.') { |
| 95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 95 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
| 96 | 96 | } else { |
| 97 | 97 | $i['extraData'] = $originalName; |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 100 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ($sortAttribute !== '') { |
@@ -33,96 +33,96 @@ |
||
| 33 | 33 | use OCP\Files\Cache\ICacheEntry; |
| 34 | 34 | |
| 35 | 35 | class Helper { |
| 36 | - /** |
|
| 37 | - * Retrieves the contents of a trash bin directory. |
|
| 38 | - * |
|
| 39 | - * @param string $dir path to the directory inside the trashbin |
|
| 40 | - * or empty to retrieve the root of the trashbin |
|
| 41 | - * @param string $user |
|
| 42 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | - * @return \OCP\Files\FileInfo[] |
|
| 45 | - */ |
|
| 46 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | - $result = array(); |
|
| 48 | - $timestamp = null; |
|
| 36 | + /** |
|
| 37 | + * Retrieves the contents of a trash bin directory. |
|
| 38 | + * |
|
| 39 | + * @param string $dir path to the directory inside the trashbin |
|
| 40 | + * or empty to retrieve the root of the trashbin |
|
| 41 | + * @param string $user |
|
| 42 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | + * @return \OCP\Files\FileInfo[] |
|
| 45 | + */ |
|
| 46 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | + $result = array(); |
|
| 48 | + $timestamp = null; |
|
| 49 | 49 | |
| 50 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 50 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 51 | 51 | |
| 52 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | - throw new \Exception('Directory does not exists'); |
|
| 54 | - } |
|
| 52 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | + throw new \Exception('Directory does not exists'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $mount = $view->getMount($dir); |
|
| 57 | - $storage = $mount->getStorage(); |
|
| 58 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 56 | + $mount = $view->getMount($dir); |
|
| 57 | + $storage = $mount->getStorage(); |
|
| 58 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 60 | 60 | |
| 61 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | - foreach ($dirContent as $entry) { |
|
| 64 | - $entryName = $entry->getName(); |
|
| 65 | - $name = $entryName; |
|
| 66 | - if ($dir === '' || $dir === '/') { |
|
| 67 | - $pathparts = pathinfo($entryName); |
|
| 68 | - $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | - $name = $pathparts['filename']; |
|
| 61 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | + foreach ($dirContent as $entry) { |
|
| 64 | + $entryName = $entry->getName(); |
|
| 65 | + $name = $entryName; |
|
| 66 | + if ($dir === '' || $dir === '/') { |
|
| 67 | + $pathparts = pathinfo($entryName); |
|
| 68 | + $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | + $name = $pathparts['filename']; |
|
| 70 | 70 | |
| 71 | - } else if ($timestamp === null) { |
|
| 72 | - // for subfolders we need to calculate the timestamp only once |
|
| 73 | - $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | - } |
|
| 76 | - $originalPath = ''; |
|
| 77 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | - if (substr($originalPath, -1) === '/') { |
|
| 81 | - $originalPath = substr($originalPath, 0, -1); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | - $i = array( |
|
| 86 | - 'name' => $name, |
|
| 87 | - 'mtime' => $timestamp, |
|
| 88 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | - 'type' => $type, |
|
| 90 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | - 'size' => $entry->getSize(), |
|
| 92 | - 'etag' => '', |
|
| 93 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | - 'fileid' => $entry->getId(), |
|
| 95 | - ); |
|
| 96 | - if ($originalPath) { |
|
| 97 | - if ($originalPath !== '.') { |
|
| 98 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | - } else { |
|
| 100 | - $i['extraData'] = $originalName; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | - } |
|
| 71 | + } else if ($timestamp === null) { |
|
| 72 | + // for subfolders we need to calculate the timestamp only once |
|
| 73 | + $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | + } |
|
| 76 | + $originalPath = ''; |
|
| 77 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | + if (substr($originalPath, -1) === '/') { |
|
| 81 | + $originalPath = substr($originalPath, 0, -1); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | + $i = array( |
|
| 86 | + 'name' => $name, |
|
| 87 | + 'mtime' => $timestamp, |
|
| 88 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | + 'type' => $type, |
|
| 90 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | + 'size' => $entry->getSize(), |
|
| 92 | + 'etag' => '', |
|
| 93 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | + 'fileid' => $entry->getId(), |
|
| 95 | + ); |
|
| 96 | + if ($originalPath) { |
|
| 97 | + if ($originalPath !== '.') { |
|
| 98 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | + } else { |
|
| 100 | + $i['extraData'] = $originalName; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if ($sortAttribute !== '') { |
|
| 107 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | - } |
|
| 109 | - return $result; |
|
| 110 | - } |
|
| 106 | + if ($sortAttribute !== '') { |
|
| 107 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | + } |
|
| 109 | + return $result; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Format file infos for JSON |
|
| 114 | - * |
|
| 115 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | - */ |
|
| 117 | - public static function formatFileInfos($fileInfos) { |
|
| 118 | - $files = array(); |
|
| 119 | - foreach ($fileInfos as $i) { |
|
| 120 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 121 | - $entry['id'] = $i->getId(); |
|
| 122 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 123 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 124 | - $files[] = $entry; |
|
| 125 | - } |
|
| 126 | - return $files; |
|
| 127 | - } |
|
| 112 | + /** |
|
| 113 | + * Format file infos for JSON |
|
| 114 | + * |
|
| 115 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | + */ |
|
| 117 | + public static function formatFileInfos($fileInfos) { |
|
| 118 | + $files = array(); |
|
| 119 | + foreach ($fileInfos as $i) { |
|
| 120 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 121 | + $entry['id'] = $i->getId(); |
|
| 122 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 123 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 124 | + $files[] = $entry; |
|
| 125 | + } |
|
| 126 | + return $files; |
|
| 127 | + } |
|
| 128 | 128 | } |