@@ -29,16 +29,16 @@ |
||
| 29 | 29 | use OCP\Accounts\IAccountManager; |
| 30 | 30 | |
| 31 | 31 | trait TAccountsHelper { |
| 32 | - /** |
|
| 33 | - * returns whether the property is a collection |
|
| 34 | - */ |
|
| 35 | - protected function isCollection(string $propertyName): bool { |
|
| 36 | - return in_array( |
|
| 37 | - $propertyName, |
|
| 38 | - [ |
|
| 39 | - IAccountManager::COLLECTION_EMAIL, |
|
| 40 | - ], |
|
| 41 | - true |
|
| 42 | - ); |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * returns whether the property is a collection |
|
| 34 | + */ |
|
| 35 | + protected function isCollection(string $propertyName): bool { |
|
| 36 | + return in_array( |
|
| 37 | + $propertyName, |
|
| 38 | + [ |
|
| 39 | + IAccountManager::COLLECTION_EMAIL, |
|
| 40 | + ], |
|
| 41 | + true |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | foreach ($releases as $release) { |
| 152 | 152 | $versions[] = $release['version']; |
| 153 | 153 | } |
| 154 | - usort($versions, function ($version1, $version2) { |
|
| 154 | + usort($versions, function($version1, $version2) { |
|
| 155 | 155 | return version_compare($version1, $version2); |
| 156 | 156 | }); |
| 157 | 157 | $versions = array_reverse($versions); |
| 158 | 158 | if (isset($versions[0])) { |
| 159 | 159 | $highestVersion = $versions[0]; |
| 160 | 160 | foreach ($releases as $release) { |
| 161 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
| 161 | + if ((string) $release['version'] === (string) $highestVersion) { |
|
| 162 | 162 | $response['data'][$dataKey]['releases'] = [$release]; |
| 163 | 163 | break; |
| 164 | 164 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // If the admin specified a allow list, filter apps from the appstore |
| 190 | 190 | if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
| 191 | - return array_filter($apps, function ($app) use ($allowList) { |
|
| 191 | + return array_filter($apps, function($app) use ($allowList) { |
|
| 192 | 192 | return in_array($app['id'], $allowList); |
| 193 | 193 | }); |
| 194 | 194 | } |
@@ -16,157 +16,157 @@ |
||
| 16 | 16 | use Psr\Log\LoggerInterface; |
| 17 | 17 | |
| 18 | 18 | class AppFetcher extends Fetcher { |
| 19 | - /** @var bool */ |
|
| 20 | - private $ignoreMaxVersion; |
|
| 21 | - |
|
| 22 | - public function __construct( |
|
| 23 | - Factory $appDataFactory, |
|
| 24 | - IClientService $clientService, |
|
| 25 | - ITimeFactory $timeFactory, |
|
| 26 | - IConfig $config, |
|
| 27 | - private CompareVersion $compareVersion, |
|
| 28 | - LoggerInterface $logger, |
|
| 29 | - protected IRegistry $registry, |
|
| 30 | - ) { |
|
| 31 | - parent::__construct( |
|
| 32 | - $appDataFactory, |
|
| 33 | - $clientService, |
|
| 34 | - $timeFactory, |
|
| 35 | - $config, |
|
| 36 | - $logger, |
|
| 37 | - $registry |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - $this->fileName = 'apps.json'; |
|
| 41 | - $this->endpointName = 'apps.json'; |
|
| 42 | - $this->ignoreMaxVersion = true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Only returns the latest compatible app release in the releases array |
|
| 47 | - * |
|
| 48 | - * @param string $ETag |
|
| 49 | - * @param string $content |
|
| 50 | - * @param bool [$allowUnstable] Allow unstable releases |
|
| 51 | - * |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 54 | - protected function fetch($ETag, $content, $allowUnstable = false) { |
|
| 55 | - /** @var mixed[] $response */ |
|
| 56 | - $response = parent::fetch($ETag, $content); |
|
| 57 | - |
|
| 58 | - if (!isset($response['data']) || $response['data'] === null) { |
|
| 59 | - $this->logger->warning('Response from appstore is invalid, apps could not be retrieved. Try again later.', ['app' => 'appstoreFetcher']); |
|
| 60 | - return []; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 64 | - $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 65 | - |
|
| 66 | - foreach ($response['data'] as $dataKey => $app) { |
|
| 67 | - $releases = []; |
|
| 68 | - |
|
| 69 | - // Filter all compatible releases |
|
| 70 | - foreach ($app['releases'] as $release) { |
|
| 71 | - // Exclude all nightly and pre-releases if required |
|
| 72 | - if (($allowNightly || $release['isNightly'] === false) |
|
| 73 | - && ($allowPreReleases || !str_contains($release['version'], '-'))) { |
|
| 74 | - // Exclude all versions not compatible with the current version |
|
| 75 | - try { |
|
| 76 | - $versionParser = new VersionParser(); |
|
| 77 | - $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 78 | - $ncVersion = $this->getVersion(); |
|
| 79 | - $minServerVersion = $serverVersion->getMinimumVersion(); |
|
| 80 | - $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
| 81 | - $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
| 82 | - $maxFulfilled = $maxServerVersion !== '' |
|
| 83 | - && $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
| 84 | - $isPhpCompatible = true; |
|
| 85 | - if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
| 86 | - $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
| 87 | - $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
| 88 | - $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
| 89 | - $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
| 90 | - PHP_VERSION, |
|
| 91 | - $minPhpVersion, |
|
| 92 | - '>=' |
|
| 93 | - ); |
|
| 94 | - $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
| 95 | - PHP_VERSION, |
|
| 96 | - $maxPhpVersion, |
|
| 97 | - '<=' |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
| 101 | - } |
|
| 102 | - if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
| 103 | - $releases[] = $release; |
|
| 104 | - } |
|
| 105 | - } catch (\InvalidArgumentException $e) { |
|
| 106 | - $this->logger->warning($e->getMessage(), [ |
|
| 107 | - 'exception' => $e, |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if (empty($releases)) { |
|
| 114 | - // Remove apps that don't have a matching release |
|
| 115 | - $response['data'][$dataKey] = []; |
|
| 116 | - continue; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Get the highest version |
|
| 120 | - $versions = []; |
|
| 121 | - foreach ($releases as $release) { |
|
| 122 | - $versions[] = $release['version']; |
|
| 123 | - } |
|
| 124 | - usort($versions, function ($version1, $version2) { |
|
| 125 | - return version_compare($version1, $version2); |
|
| 126 | - }); |
|
| 127 | - $versions = array_reverse($versions); |
|
| 128 | - if (isset($versions[0])) { |
|
| 129 | - $highestVersion = $versions[0]; |
|
| 130 | - foreach ($releases as $release) { |
|
| 131 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
| 132 | - $response['data'][$dataKey]['releases'] = [$release]; |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $response['data'] = array_values(array_filter($response['data'])); |
|
| 140 | - return $response; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param string $version |
|
| 145 | - * @param string $fileName |
|
| 146 | - * @param bool $ignoreMaxVersion |
|
| 147 | - */ |
|
| 148 | - public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
| 149 | - parent::setVersion($version); |
|
| 150 | - $this->fileName = $fileName; |
|
| 151 | - $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function get($allowUnstable = false): array { |
|
| 155 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 156 | - |
|
| 157 | - $apps = parent::get($allowPreReleases); |
|
| 158 | - if (empty($apps)) { |
|
| 159 | - return []; |
|
| 160 | - } |
|
| 161 | - $allowList = $this->config->getSystemValue('appsallowlist'); |
|
| 162 | - |
|
| 163 | - // If the admin specified a allow list, filter apps from the appstore |
|
| 164 | - if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
| 165 | - return array_filter($apps, function ($app) use ($allowList) { |
|
| 166 | - return in_array($app['id'], $allowList); |
|
| 167 | - }); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $apps; |
|
| 171 | - } |
|
| 19 | + /** @var bool */ |
|
| 20 | + private $ignoreMaxVersion; |
|
| 21 | + |
|
| 22 | + public function __construct( |
|
| 23 | + Factory $appDataFactory, |
|
| 24 | + IClientService $clientService, |
|
| 25 | + ITimeFactory $timeFactory, |
|
| 26 | + IConfig $config, |
|
| 27 | + private CompareVersion $compareVersion, |
|
| 28 | + LoggerInterface $logger, |
|
| 29 | + protected IRegistry $registry, |
|
| 30 | + ) { |
|
| 31 | + parent::__construct( |
|
| 32 | + $appDataFactory, |
|
| 33 | + $clientService, |
|
| 34 | + $timeFactory, |
|
| 35 | + $config, |
|
| 36 | + $logger, |
|
| 37 | + $registry |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + $this->fileName = 'apps.json'; |
|
| 41 | + $this->endpointName = 'apps.json'; |
|
| 42 | + $this->ignoreMaxVersion = true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Only returns the latest compatible app release in the releases array |
|
| 47 | + * |
|
| 48 | + * @param string $ETag |
|
| 49 | + * @param string $content |
|
| 50 | + * @param bool [$allowUnstable] Allow unstable releases |
|
| 51 | + * |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | + protected function fetch($ETag, $content, $allowUnstable = false) { |
|
| 55 | + /** @var mixed[] $response */ |
|
| 56 | + $response = parent::fetch($ETag, $content); |
|
| 57 | + |
|
| 58 | + if (!isset($response['data']) || $response['data'] === null) { |
|
| 59 | + $this->logger->warning('Response from appstore is invalid, apps could not be retrieved. Try again later.', ['app' => 'appstoreFetcher']); |
|
| 60 | + return []; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 64 | + $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 65 | + |
|
| 66 | + foreach ($response['data'] as $dataKey => $app) { |
|
| 67 | + $releases = []; |
|
| 68 | + |
|
| 69 | + // Filter all compatible releases |
|
| 70 | + foreach ($app['releases'] as $release) { |
|
| 71 | + // Exclude all nightly and pre-releases if required |
|
| 72 | + if (($allowNightly || $release['isNightly'] === false) |
|
| 73 | + && ($allowPreReleases || !str_contains($release['version'], '-'))) { |
|
| 74 | + // Exclude all versions not compatible with the current version |
|
| 75 | + try { |
|
| 76 | + $versionParser = new VersionParser(); |
|
| 77 | + $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 78 | + $ncVersion = $this->getVersion(); |
|
| 79 | + $minServerVersion = $serverVersion->getMinimumVersion(); |
|
| 80 | + $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
| 81 | + $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
| 82 | + $maxFulfilled = $maxServerVersion !== '' |
|
| 83 | + && $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
| 84 | + $isPhpCompatible = true; |
|
| 85 | + if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
| 86 | + $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
| 87 | + $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
| 88 | + $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
| 89 | + $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
| 90 | + PHP_VERSION, |
|
| 91 | + $minPhpVersion, |
|
| 92 | + '>=' |
|
| 93 | + ); |
|
| 94 | + $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
| 95 | + PHP_VERSION, |
|
| 96 | + $maxPhpVersion, |
|
| 97 | + '<=' |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
| 101 | + } |
|
| 102 | + if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
| 103 | + $releases[] = $release; |
|
| 104 | + } |
|
| 105 | + } catch (\InvalidArgumentException $e) { |
|
| 106 | + $this->logger->warning($e->getMessage(), [ |
|
| 107 | + 'exception' => $e, |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if (empty($releases)) { |
|
| 114 | + // Remove apps that don't have a matching release |
|
| 115 | + $response['data'][$dataKey] = []; |
|
| 116 | + continue; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Get the highest version |
|
| 120 | + $versions = []; |
|
| 121 | + foreach ($releases as $release) { |
|
| 122 | + $versions[] = $release['version']; |
|
| 123 | + } |
|
| 124 | + usort($versions, function ($version1, $version2) { |
|
| 125 | + return version_compare($version1, $version2); |
|
| 126 | + }); |
|
| 127 | + $versions = array_reverse($versions); |
|
| 128 | + if (isset($versions[0])) { |
|
| 129 | + $highestVersion = $versions[0]; |
|
| 130 | + foreach ($releases as $release) { |
|
| 131 | + if ((string)$release['version'] === (string)$highestVersion) { |
|
| 132 | + $response['data'][$dataKey]['releases'] = [$release]; |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $response['data'] = array_values(array_filter($response['data'])); |
|
| 140 | + return $response; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param string $version |
|
| 145 | + * @param string $fileName |
|
| 146 | + * @param bool $ignoreMaxVersion |
|
| 147 | + */ |
|
| 148 | + public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
| 149 | + parent::setVersion($version); |
|
| 150 | + $this->fileName = $fileName; |
|
| 151 | + $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function get($allowUnstable = false): array { |
|
| 155 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
| 156 | + |
|
| 157 | + $apps = parent::get($allowPreReleases); |
|
| 158 | + if (empty($apps)) { |
|
| 159 | + return []; |
|
| 160 | + } |
|
| 161 | + $allowList = $this->config->getSystemValue('appsallowlist'); |
|
| 162 | + |
|
| 163 | + // If the admin specified a allow list, filter apps from the appstore |
|
| 164 | + if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
| 165 | + return array_filter($apps, function ($app) use ($allowList) { |
|
| 166 | + return in_array($app['id'], $allowList); |
|
| 167 | + }); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $apps; |
|
| 171 | + } |
|
| 172 | 172 | } |
@@ -89,6 +89,6 @@ |
||
| 89 | 89 | if (empty($this->value)) { |
| 90 | 90 | return null; |
| 91 | 91 | } |
| 92 | - return 'tel:' . $this->value; |
|
| 92 | + return 'tel:'.$this->value; |
|
| 93 | 93 | } |
| 94 | 94 | } |
@@ -16,48 +16,48 @@ |
||
| 16 | 16 | use OCP\Profile\ILinkAction; |
| 17 | 17 | |
| 18 | 18 | class PhoneAction implements ILinkAction { |
| 19 | - private string $value = ''; |
|
| 20 | - |
|
| 21 | - public function __construct( |
|
| 22 | - private IAccountManager $accountManager, |
|
| 23 | - private IFactory $l10nFactory, |
|
| 24 | - private IURLGenerator $urlGenerator, |
|
| 25 | - ) { |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function preload(IUser $targetUser): void { |
|
| 29 | - $account = $this->accountManager->getAccount($targetUser); |
|
| 30 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function getAppId(): string { |
|
| 34 | - return 'core'; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function getId(): string { |
|
| 38 | - return IAccountManager::PROPERTY_PHONE; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function getDisplayId(): string { |
|
| 42 | - return $this->l10nFactory->get('lib')->t('Phone'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getTitle(): string { |
|
| 46 | - return $this->l10nFactory->get('lib')->t('Call %s', [$this->value]); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getPriority(): int { |
|
| 50 | - return 30; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function getIcon(): string { |
|
| 54 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/phone.svg')); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function getTarget(): ?string { |
|
| 58 | - if (empty($this->value)) { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - return 'tel:' . $this->value; |
|
| 62 | - } |
|
| 19 | + private string $value = ''; |
|
| 20 | + |
|
| 21 | + public function __construct( |
|
| 22 | + private IAccountManager $accountManager, |
|
| 23 | + private IFactory $l10nFactory, |
|
| 24 | + private IURLGenerator $urlGenerator, |
|
| 25 | + ) { |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function preload(IUser $targetUser): void { |
|
| 29 | + $account = $this->accountManager->getAccount($targetUser); |
|
| 30 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function getAppId(): string { |
|
| 34 | + return 'core'; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function getId(): string { |
|
| 38 | + return IAccountManager::PROPERTY_PHONE; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function getDisplayId(): string { |
|
| 42 | + return $this->l10nFactory->get('lib')->t('Phone'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getTitle(): string { |
|
| 46 | + return $this->l10nFactory->get('lib')->t('Call %s', [$this->value]); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getPriority(): int { |
|
| 50 | + return 30; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function getIcon(): string { |
|
| 54 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/phone.svg')); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function getTarget(): ?string { |
|
| 58 | + if (empty($this->value)) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + return 'tel:' . $this->value; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -89,6 +89,6 @@ |
||
| 89 | 89 | if (empty($this->value)) { |
| 90 | 90 | return null; |
| 91 | 91 | } |
| 92 | - return 'mailto:' . $this->value; |
|
| 92 | + return 'mailto:'.$this->value; |
|
| 93 | 93 | } |
| 94 | 94 | } |
@@ -16,48 +16,48 @@ |
||
| 16 | 16 | use OCP\Profile\ILinkAction; |
| 17 | 17 | |
| 18 | 18 | class EmailAction implements ILinkAction { |
| 19 | - private string $value = ''; |
|
| 20 | - |
|
| 21 | - public function __construct( |
|
| 22 | - private IAccountManager $accountManager, |
|
| 23 | - private IFactory $l10nFactory, |
|
| 24 | - private IURLGenerator $urlGenerator, |
|
| 25 | - ) { |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function preload(IUser $targetUser): void { |
|
| 29 | - $account = $this->accountManager->getAccount($targetUser); |
|
| 30 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function getAppId(): string { |
|
| 34 | - return 'core'; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function getId(): string { |
|
| 38 | - return IAccountManager::PROPERTY_EMAIL; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function getDisplayId(): string { |
|
| 42 | - return $this->l10nFactory->get('lib')->t('Email'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getTitle(): string { |
|
| 46 | - return $this->l10nFactory->get('lib')->t('Mail %s', [$this->value]); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getPriority(): int { |
|
| 50 | - return 20; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function getIcon(): string { |
|
| 54 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function getTarget(): ?string { |
|
| 58 | - if (empty($this->value)) { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - return 'mailto:' . $this->value; |
|
| 62 | - } |
|
| 19 | + private string $value = ''; |
|
| 20 | + |
|
| 21 | + public function __construct( |
|
| 22 | + private IAccountManager $accountManager, |
|
| 23 | + private IFactory $l10nFactory, |
|
| 24 | + private IURLGenerator $urlGenerator, |
|
| 25 | + ) { |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function preload(IUser $targetUser): void { |
|
| 29 | + $account = $this->accountManager->getAccount($targetUser); |
|
| 30 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function getAppId(): string { |
|
| 34 | + return 'core'; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function getId(): string { |
|
| 38 | + return IAccountManager::PROPERTY_EMAIL; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function getDisplayId(): string { |
|
| 42 | + return $this->l10nFactory->get('lib')->t('Email'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getTitle(): string { |
|
| 46 | + return $this->l10nFactory->get('lib')->t('Mail %s', [$this->value]); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getPriority(): int { |
|
| 50 | + return 20; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function getIcon(): string { |
|
| 54 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function getTarget(): ?string { |
|
| 58 | + if (empty($this->value)) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + return 'mailto:' . $this->value; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function getTitle(): string { |
| 78 | - $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
| 78 | + $displayUsername = $this->value[0] === '@' ? $this->value : '@'.$this->value; |
|
| 79 | 79 | return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -92,6 +92,6 @@ discard block |
||
| 92 | 92 | return null; |
| 93 | 93 | } |
| 94 | 94 | $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
| 95 | - return 'https://twitter.com/' . $username; |
|
| 95 | + return 'https://twitter.com/'.$username; |
|
| 96 | 96 | } |
| 97 | 97 | } |
@@ -17,50 +17,50 @@ |
||
| 17 | 17 | use function substr; |
| 18 | 18 | |
| 19 | 19 | class TwitterAction implements ILinkAction { |
| 20 | - private string $value = ''; |
|
| 20 | + private string $value = ''; |
|
| 21 | 21 | |
| 22 | - public function __construct( |
|
| 23 | - private IAccountManager $accountManager, |
|
| 24 | - private IFactory $l10nFactory, |
|
| 25 | - private IURLGenerator $urlGenerator, |
|
| 26 | - ) { |
|
| 27 | - } |
|
| 22 | + public function __construct( |
|
| 23 | + private IAccountManager $accountManager, |
|
| 24 | + private IFactory $l10nFactory, |
|
| 25 | + private IURLGenerator $urlGenerator, |
|
| 26 | + ) { |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function preload(IUser $targetUser): void { |
|
| 30 | - $account = $this->accountManager->getAccount($targetUser); |
|
| 31 | - $this->value = $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(); |
|
| 32 | - } |
|
| 29 | + public function preload(IUser $targetUser): void { |
|
| 30 | + $account = $this->accountManager->getAccount($targetUser); |
|
| 31 | + $this->value = $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function getAppId(): string { |
|
| 35 | - return 'core'; |
|
| 36 | - } |
|
| 34 | + public function getAppId(): string { |
|
| 35 | + return 'core'; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function getId(): string { |
|
| 39 | - return IAccountManager::PROPERTY_TWITTER; |
|
| 40 | - } |
|
| 38 | + public function getId(): string { |
|
| 39 | + return IAccountManager::PROPERTY_TWITTER; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function getDisplayId(): string { |
|
| 43 | - return $this->l10nFactory->get('lib')->t('Twitter'); |
|
| 44 | - } |
|
| 42 | + public function getDisplayId(): string { |
|
| 43 | + return $this->l10nFactory->get('lib')->t('Twitter'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getTitle(): string { |
|
| 47 | - $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
| 48 | - return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
|
| 49 | - } |
|
| 46 | + public function getTitle(): string { |
|
| 47 | + $displayUsername = $this->value[0] === '@' ? $this->value : '@' . $this->value; |
|
| 48 | + return $this->l10nFactory->get('lib')->t('View %s on Twitter', [$displayUsername]); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getPriority(): int { |
|
| 52 | - return 50; |
|
| 53 | - } |
|
| 51 | + public function getPriority(): int { |
|
| 52 | + return 50; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function getIcon(): string { |
|
| 56 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/twitter.svg')); |
|
| 57 | - } |
|
| 55 | + public function getIcon(): string { |
|
| 56 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/twitter.svg')); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function getTarget(): ?string { |
|
| 60 | - if (empty($this->value)) { |
|
| 61 | - return null; |
|
| 62 | - } |
|
| 63 | - $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
|
| 64 | - return 'https://twitter.com/' . $username; |
|
| 65 | - } |
|
| 59 | + public function getTarget(): ?string { |
|
| 60 | + if (empty($this->value)) { |
|
| 61 | + return null; |
|
| 62 | + } |
|
| 63 | + $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; |
|
| 64 | + return 'https://twitter.com/' . $username; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | try { |
| 97 | 97 | $provider = $this->container->get($this->providerClass); |
| 98 | 98 | } catch (ContainerExceptionInterface $e) { |
| 99 | - $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
| 99 | + $this->logger->error('Could not load user-status "'.$this->providerClass.'" provider dynamically: '.$e->getMessage(), [ |
|
| 100 | 100 | 'exception' => $e, |
| 101 | 101 | ]); |
| 102 | 102 | return; |
@@ -15,86 +15,86 @@ |
||
| 15 | 15 | use Psr\Log\LoggerInterface; |
| 16 | 16 | |
| 17 | 17 | class Manager implements IManager { |
| 18 | - /** @var ?class-string */ |
|
| 19 | - private ?string $providerClass = null; |
|
| 20 | - private ?IProvider $provider = null; |
|
| 18 | + /** @var ?class-string */ |
|
| 19 | + private ?string $providerClass = null; |
|
| 20 | + private ?IProvider $provider = null; |
|
| 21 | 21 | |
| 22 | - public function __construct( |
|
| 23 | - private ContainerInterface $container, |
|
| 24 | - private LoggerInterface $logger, |
|
| 25 | - ) { |
|
| 26 | - } |
|
| 22 | + public function __construct( |
|
| 23 | + private ContainerInterface $container, |
|
| 24 | + private LoggerInterface $logger, |
|
| 25 | + ) { |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @inheritDoc |
|
| 30 | - */ |
|
| 31 | - public function getUserStatuses(array $userIds): array { |
|
| 32 | - $this->setupProvider(); |
|
| 33 | - if (!$this->provider) { |
|
| 34 | - return []; |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * @inheritDoc |
|
| 30 | + */ |
|
| 31 | + public function getUserStatuses(array $userIds): array { |
|
| 32 | + $this->setupProvider(); |
|
| 33 | + if (!$this->provider) { |
|
| 34 | + return []; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - return $this->provider->getUserStatuses($userIds); |
|
| 38 | - } |
|
| 37 | + return $this->provider->getUserStatuses($userIds); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param string $class |
|
| 42 | - * @since 20.0.0 |
|
| 43 | - * @internal |
|
| 44 | - */ |
|
| 45 | - public function registerProvider(string $class): void { |
|
| 46 | - $this->providerClass = $class; |
|
| 47 | - $this->provider = null; |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * @param string $class |
|
| 42 | + * @since 20.0.0 |
|
| 43 | + * @internal |
|
| 44 | + */ |
|
| 45 | + public function registerProvider(string $class): void { |
|
| 46 | + $this->providerClass = $class; |
|
| 47 | + $this->provider = null; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Lazily set up provider |
|
| 52 | - */ |
|
| 53 | - private function setupProvider(): void { |
|
| 54 | - if ($this->provider !== null) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - if ($this->providerClass === null) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * Lazily set up provider |
|
| 52 | + */ |
|
| 53 | + private function setupProvider(): void { |
|
| 54 | + if ($this->provider !== null) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + if ($this->providerClass === null) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @psalm-suppress InvalidCatch |
|
| 63 | - */ |
|
| 64 | - try { |
|
| 65 | - $provider = $this->container->get($this->providerClass); |
|
| 66 | - } catch (ContainerExceptionInterface $e) { |
|
| 67 | - $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
| 68 | - 'exception' => $e, |
|
| 69 | - ]); |
|
| 70 | - return; |
|
| 71 | - } |
|
| 61 | + /** |
|
| 62 | + * @psalm-suppress InvalidCatch |
|
| 63 | + */ |
|
| 64 | + try { |
|
| 65 | + $provider = $this->container->get($this->providerClass); |
|
| 66 | + } catch (ContainerExceptionInterface $e) { |
|
| 67 | + $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ |
|
| 68 | + 'exception' => $e, |
|
| 69 | + ]); |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $this->provider = $provider; |
|
| 74 | - } |
|
| 73 | + $this->provider = $provider; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { |
|
| 77 | - $this->setupProvider(); |
|
| 78 | - if (!$this->provider instanceof ISettableProvider) { |
|
| 79 | - return; |
|
| 80 | - } |
|
| 76 | + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { |
|
| 77 | + $this->setupProvider(); |
|
| 78 | + if (!$this->provider instanceof ISettableProvider) { |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); |
|
| 83 | - } |
|
| 82 | + $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function revertUserStatus(string $userId, string $messageId, string $status): void { |
|
| 86 | - $this->setupProvider(); |
|
| 87 | - if (!$this->provider instanceof ISettableProvider) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - $this->provider->revertUserStatus($userId, $messageId, $status); |
|
| 91 | - } |
|
| 85 | + public function revertUserStatus(string $userId, string $messageId, string $status): void { |
|
| 86 | + $this->setupProvider(); |
|
| 87 | + if (!$this->provider instanceof ISettableProvider) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + $this->provider->revertUserStatus($userId, $messageId, $status); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void { |
|
| 94 | - $this->setupProvider(); |
|
| 95 | - if (!$this->provider instanceof ISettableProvider) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - $this->provider->revertMultipleUserStatus($userIds, $messageId, $status); |
|
| 99 | - } |
|
| 93 | + public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void { |
|
| 94 | + $this->setupProvider(); |
|
| 95 | + if (!$this->provider instanceof ISettableProvider) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + $this->provider->revertMultipleUserStatus($userIds, $messageId, $status); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | throw new \RuntimeException('no instance id!'); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return 'appdata_' . $instanceId; |
|
| 79 | + return 'appdata_'.$instanceId; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | protected function getAppDataRootFolder(): Folder { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $name = $this->getAppDataFolderName(); |
| 105 | 105 | |
| 106 | 106 | try { |
| 107 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
| 107 | + $this->folder = $this->rootFolder->get($name.'/'.$this->appId); |
|
| 108 | 108 | } catch (NotFoundException $e) { |
| 109 | 109 | $appDataRootFolder = $this->getAppDataRootFolder(); |
| 110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | try { |
| 115 | 115 | $this->folder = $appDataRootFolder->newFolder($this->appId); |
| 116 | 116 | } catch (NotPermittedException $e) { |
| 117 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
| 117 | + throw new \RuntimeException('Could not get appdata folder for '.$this->appId); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | public function getFolder(string $name): ISimpleFolder { |
| 127 | - $key = $this->appId . '/' . $name; |
|
| 127 | + $key = $this->appId.'/'.$name; |
|
| 128 | 128 | if ($cachedFolder = $this->folders->get($key)) { |
| 129 | 129 | if ($cachedFolder instanceof \Exception) { |
| 130 | 130 | throw $cachedFolder; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | if ($name === '/') { |
| 138 | 138 | $node = $this->getAppDataFolder(); |
| 139 | 139 | } else { |
| 140 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
| 140 | + $path = $this->getAppDataFolderName().'/'.$this->appId.'/'.$name; |
|
| 141 | 141 | $node = $this->rootFolder->get($path); |
| 142 | 142 | } |
| 143 | 143 | } catch (NotFoundException $e) { |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | public function newFolder(string $name): ISimpleFolder { |
| 155 | - $key = $this->appId . '/' . $name; |
|
| 155 | + $key = $this->appId.'/'.$name; |
|
| 156 | 156 | $folder = $this->getAppDataFolder()->newFolder($name); |
| 157 | 157 | |
| 158 | 158 | $simpleFolder = new SimpleFolder($folder); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | public function getDirectoryListing(): array { |
| 164 | 164 | $listing = $this->getAppDataFolder()->getDirectoryListing(); |
| 165 | 165 | |
| 166 | - $fileListing = array_map(function (Node $folder) { |
|
| 166 | + $fileListing = array_map(function(Node $folder) { |
|
| 167 | 167 | if ($folder instanceof Folder) { |
| 168 | 168 | return new SimpleFolder($folder); |
| 169 | 169 | } |
@@ -20,135 +20,135 @@ |
||
| 20 | 20 | use OCP\Files\SimpleFS\ISimpleFolder; |
| 21 | 21 | |
| 22 | 22 | class AppData implements IAppData { |
| 23 | - private IRootFolder $rootFolder; |
|
| 24 | - private SystemConfig $config; |
|
| 25 | - private string $appId; |
|
| 26 | - private ?Folder $folder = null; |
|
| 27 | - /** @var CappedMemoryCache<ISimpleFolder|NotFoundException> */ |
|
| 28 | - private CappedMemoryCache $folders; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * AppData constructor. |
|
| 32 | - * |
|
| 33 | - * @param IRootFolder $rootFolder |
|
| 34 | - * @param SystemConfig $systemConfig |
|
| 35 | - * @param string $appId |
|
| 36 | - */ |
|
| 37 | - public function __construct(IRootFolder $rootFolder, |
|
| 38 | - SystemConfig $systemConfig, |
|
| 39 | - string $appId) { |
|
| 40 | - $this->rootFolder = $rootFolder; |
|
| 41 | - $this->config = $systemConfig; |
|
| 42 | - $this->appId = $appId; |
|
| 43 | - $this->folders = new CappedMemoryCache(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - private function getAppDataFolderName() { |
|
| 47 | - $instanceId = $this->config->getValue('instanceid', null); |
|
| 48 | - if ($instanceId === null) { |
|
| 49 | - throw new \RuntimeException('no instance id!'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - return 'appdata_' . $instanceId; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - protected function getAppDataRootFolder(): Folder { |
|
| 56 | - $name = $this->getAppDataFolderName(); |
|
| 57 | - |
|
| 58 | - try { |
|
| 59 | - /** @var Folder $node */ |
|
| 60 | - $node = $this->rootFolder->get($name); |
|
| 61 | - return $node; |
|
| 62 | - } catch (NotFoundException $e) { |
|
| 63 | - try { |
|
| 64 | - return $this->rootFolder->newFolder($name); |
|
| 65 | - } catch (NotPermittedException $e) { |
|
| 66 | - throw new \RuntimeException('Could not get appdata folder'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return Folder |
|
| 73 | - * @throws \RuntimeException |
|
| 74 | - */ |
|
| 75 | - private function getAppDataFolder(): Folder { |
|
| 76 | - if ($this->folder === null) { |
|
| 77 | - $name = $this->getAppDataFolderName(); |
|
| 78 | - |
|
| 79 | - try { |
|
| 80 | - $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
| 81 | - } catch (NotFoundException $e) { |
|
| 82 | - $appDataRootFolder = $this->getAppDataRootFolder(); |
|
| 83 | - |
|
| 84 | - try { |
|
| 85 | - $this->folder = $appDataRootFolder->get($this->appId); |
|
| 86 | - } catch (NotFoundException $e) { |
|
| 87 | - try { |
|
| 88 | - $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
| 89 | - } catch (NotPermittedException $e) { |
|
| 90 | - throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $this->folder; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function getFolder(string $name): ISimpleFolder { |
|
| 100 | - $key = $this->appId . '/' . $name; |
|
| 101 | - if ($cachedFolder = $this->folders->get($key)) { |
|
| 102 | - if ($cachedFolder instanceof \Exception) { |
|
| 103 | - throw $cachedFolder; |
|
| 104 | - } else { |
|
| 105 | - return $cachedFolder; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - try { |
|
| 109 | - // Hardening if somebody wants to retrieve '/' |
|
| 110 | - if ($name === '/') { |
|
| 111 | - $node = $this->getAppDataFolder(); |
|
| 112 | - } else { |
|
| 113 | - $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
| 114 | - $node = $this->rootFolder->get($path); |
|
| 115 | - } |
|
| 116 | - } catch (NotFoundException $e) { |
|
| 117 | - $this->folders->set($key, $e); |
|
| 118 | - throw $e; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** @var Folder $node */ |
|
| 122 | - $folder = new SimpleFolder($node); |
|
| 123 | - $this->folders->set($key, $folder); |
|
| 124 | - return $folder; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function newFolder(string $name): ISimpleFolder { |
|
| 128 | - $key = $this->appId . '/' . $name; |
|
| 129 | - $folder = $this->getAppDataFolder()->newFolder($name); |
|
| 130 | - |
|
| 131 | - $simpleFolder = new SimpleFolder($folder); |
|
| 132 | - $this->folders->set($key, $simpleFolder); |
|
| 133 | - return $simpleFolder; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getDirectoryListing(): array { |
|
| 137 | - $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
| 138 | - |
|
| 139 | - $fileListing = array_map(function (Node $folder) { |
|
| 140 | - if ($folder instanceof Folder) { |
|
| 141 | - return new SimpleFolder($folder); |
|
| 142 | - } |
|
| 143 | - return null; |
|
| 144 | - }, $listing); |
|
| 145 | - |
|
| 146 | - $fileListing = array_filter($fileListing); |
|
| 147 | - |
|
| 148 | - return array_values($fileListing); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function getId(): int { |
|
| 152 | - return $this->getAppDataFolder()->getId(); |
|
| 153 | - } |
|
| 23 | + private IRootFolder $rootFolder; |
|
| 24 | + private SystemConfig $config; |
|
| 25 | + private string $appId; |
|
| 26 | + private ?Folder $folder = null; |
|
| 27 | + /** @var CappedMemoryCache<ISimpleFolder|NotFoundException> */ |
|
| 28 | + private CappedMemoryCache $folders; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * AppData constructor. |
|
| 32 | + * |
|
| 33 | + * @param IRootFolder $rootFolder |
|
| 34 | + * @param SystemConfig $systemConfig |
|
| 35 | + * @param string $appId |
|
| 36 | + */ |
|
| 37 | + public function __construct(IRootFolder $rootFolder, |
|
| 38 | + SystemConfig $systemConfig, |
|
| 39 | + string $appId) { |
|
| 40 | + $this->rootFolder = $rootFolder; |
|
| 41 | + $this->config = $systemConfig; |
|
| 42 | + $this->appId = $appId; |
|
| 43 | + $this->folders = new CappedMemoryCache(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + private function getAppDataFolderName() { |
|
| 47 | + $instanceId = $this->config->getValue('instanceid', null); |
|
| 48 | + if ($instanceId === null) { |
|
| 49 | + throw new \RuntimeException('no instance id!'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + return 'appdata_' . $instanceId; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + protected function getAppDataRootFolder(): Folder { |
|
| 56 | + $name = $this->getAppDataFolderName(); |
|
| 57 | + |
|
| 58 | + try { |
|
| 59 | + /** @var Folder $node */ |
|
| 60 | + $node = $this->rootFolder->get($name); |
|
| 61 | + return $node; |
|
| 62 | + } catch (NotFoundException $e) { |
|
| 63 | + try { |
|
| 64 | + return $this->rootFolder->newFolder($name); |
|
| 65 | + } catch (NotPermittedException $e) { |
|
| 66 | + throw new \RuntimeException('Could not get appdata folder'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return Folder |
|
| 73 | + * @throws \RuntimeException |
|
| 74 | + */ |
|
| 75 | + private function getAppDataFolder(): Folder { |
|
| 76 | + if ($this->folder === null) { |
|
| 77 | + $name = $this->getAppDataFolderName(); |
|
| 78 | + |
|
| 79 | + try { |
|
| 80 | + $this->folder = $this->rootFolder->get($name . '/' . $this->appId); |
|
| 81 | + } catch (NotFoundException $e) { |
|
| 82 | + $appDataRootFolder = $this->getAppDataRootFolder(); |
|
| 83 | + |
|
| 84 | + try { |
|
| 85 | + $this->folder = $appDataRootFolder->get($this->appId); |
|
| 86 | + } catch (NotFoundException $e) { |
|
| 87 | + try { |
|
| 88 | + $this->folder = $appDataRootFolder->newFolder($this->appId); |
|
| 89 | + } catch (NotPermittedException $e) { |
|
| 90 | + throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $this->folder; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function getFolder(string $name): ISimpleFolder { |
|
| 100 | + $key = $this->appId . '/' . $name; |
|
| 101 | + if ($cachedFolder = $this->folders->get($key)) { |
|
| 102 | + if ($cachedFolder instanceof \Exception) { |
|
| 103 | + throw $cachedFolder; |
|
| 104 | + } else { |
|
| 105 | + return $cachedFolder; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + try { |
|
| 109 | + // Hardening if somebody wants to retrieve '/' |
|
| 110 | + if ($name === '/') { |
|
| 111 | + $node = $this->getAppDataFolder(); |
|
| 112 | + } else { |
|
| 113 | + $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name; |
|
| 114 | + $node = $this->rootFolder->get($path); |
|
| 115 | + } |
|
| 116 | + } catch (NotFoundException $e) { |
|
| 117 | + $this->folders->set($key, $e); |
|
| 118 | + throw $e; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** @var Folder $node */ |
|
| 122 | + $folder = new SimpleFolder($node); |
|
| 123 | + $this->folders->set($key, $folder); |
|
| 124 | + return $folder; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function newFolder(string $name): ISimpleFolder { |
|
| 128 | + $key = $this->appId . '/' . $name; |
|
| 129 | + $folder = $this->getAppDataFolder()->newFolder($name); |
|
| 130 | + |
|
| 131 | + $simpleFolder = new SimpleFolder($folder); |
|
| 132 | + $this->folders->set($key, $simpleFolder); |
|
| 133 | + return $simpleFolder; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getDirectoryListing(): array { |
|
| 137 | + $listing = $this->getAppDataFolder()->getDirectoryListing(); |
|
| 138 | + |
|
| 139 | + $fileListing = array_map(function (Node $folder) { |
|
| 140 | + if ($folder instanceof Folder) { |
|
| 141 | + return new SimpleFolder($folder); |
|
| 142 | + } |
|
| 143 | + return null; |
|
| 144 | + }, $listing); |
|
| 145 | + |
|
| 146 | + $fileListing = array_filter($fileListing); |
|
| 147 | + |
|
| 148 | + return array_values($fileListing); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function getId(): int { |
|
| 152 | + return $this->getAppDataFolder()->getId(); |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -146,12 +146,12 @@ |
||
| 146 | 146 | $xml = @simplexml_load_string($body); |
| 147 | 147 | } |
| 148 | 148 | if ($xml !== false) { |
| 149 | - $data['changelogURL'] = (string)$xml->changelog['href']; |
|
| 149 | + $data['changelogURL'] = (string) $xml->changelog['href']; |
|
| 150 | 150 | $data['whatsNew'] = []; |
| 151 | 151 | foreach ($xml->whatsNew as $infoSet) { |
| 152 | - $data['whatsNew'][(string)$infoSet['lang']] = [ |
|
| 153 | - 'regular' => (array)$infoSet->regular->item, |
|
| 154 | - 'admin' => (array)$infoSet->admin->item, |
|
| 152 | + $data['whatsNew'][(string) $infoSet['lang']] = [ |
|
| 153 | + 'regular' => (array) $infoSet->regular->item, |
|
| 154 | + 'admin' => (array) $infoSet->admin->item, |
|
| 155 | 155 | ]; |
| 156 | 156 | } |
| 157 | 157 | } else { |
@@ -14,145 +14,145 @@ |
||
| 14 | 14 | use Psr\Log\LoggerInterface; |
| 15 | 15 | |
| 16 | 16 | class ChangesCheck { |
| 17 | - /** @var IClientService */ |
|
| 18 | - protected $clientService; |
|
| 19 | - /** @var ChangesMapper */ |
|
| 20 | - private $mapper; |
|
| 21 | - private LoggerInterface $logger; |
|
| 22 | - |
|
| 23 | - public const RESPONSE_NO_CONTENT = 0; |
|
| 24 | - public const RESPONSE_USE_CACHE = 1; |
|
| 25 | - public const RESPONSE_HAS_CONTENT = 2; |
|
| 26 | - |
|
| 27 | - public function __construct(IClientService $clientService, ChangesMapper $mapper, LoggerInterface $logger) { |
|
| 28 | - $this->clientService = $clientService; |
|
| 29 | - $this->mapper = $mapper; |
|
| 30 | - $this->logger = $logger; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @throws DoesNotExistException |
|
| 35 | - * @return array{changelogURL: string, whatsNew: array<string, array{admin: list<string>, regular: list<string>}>} |
|
| 36 | - */ |
|
| 37 | - public function getChangesForVersion(string $version): array { |
|
| 38 | - $version = $this->normalizeVersion($version); |
|
| 39 | - $changesInfo = $this->mapper->getChanges($version); |
|
| 40 | - $changesData = json_decode($changesInfo->getData(), true); |
|
| 41 | - if (empty($changesData)) { |
|
| 42 | - throw new DoesNotExistException('Unable to decode changes info'); |
|
| 43 | - } |
|
| 44 | - return $changesData; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @throws \Exception |
|
| 49 | - */ |
|
| 50 | - public function check(string $uri, string $version): array { |
|
| 51 | - try { |
|
| 52 | - $version = $this->normalizeVersion($version); |
|
| 53 | - $changesInfo = $this->mapper->getChanges($version); |
|
| 54 | - if ($changesInfo->getLastCheck() + 1800 > time()) { |
|
| 55 | - return json_decode($changesInfo->getData(), true); |
|
| 56 | - } |
|
| 57 | - } catch (DoesNotExistException $e) { |
|
| 58 | - $changesInfo = new Changes(); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $response = $this->queryChangesServer($uri, $changesInfo); |
|
| 62 | - |
|
| 63 | - switch ($this->evaluateResponse($response)) { |
|
| 64 | - case self::RESPONSE_NO_CONTENT: |
|
| 65 | - return []; |
|
| 66 | - case self::RESPONSE_USE_CACHE: |
|
| 67 | - return json_decode($changesInfo->getData(), true); |
|
| 68 | - case self::RESPONSE_HAS_CONTENT: |
|
| 69 | - default: |
|
| 70 | - $data = $this->extractData($response->getBody()); |
|
| 71 | - $changesInfo->setData(json_encode($data)); |
|
| 72 | - $changesInfo->setEtag($response->getHeader('Etag')); |
|
| 73 | - $this->cacheResult($changesInfo, $version); |
|
| 74 | - |
|
| 75 | - return $data; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - protected function evaluateResponse(IResponse $response): int { |
|
| 80 | - if ($response->getStatusCode() === 304) { |
|
| 81 | - return self::RESPONSE_USE_CACHE; |
|
| 82 | - } elseif ($response->getStatusCode() === 404) { |
|
| 83 | - return self::RESPONSE_NO_CONTENT; |
|
| 84 | - } elseif ($response->getStatusCode() === 200) { |
|
| 85 | - return self::RESPONSE_HAS_CONTENT; |
|
| 86 | - } |
|
| 87 | - $this->logger->debug('Unexpected return code {code} from changelog server', [ |
|
| 88 | - 'app' => 'core', |
|
| 89 | - 'code' => $response->getStatusCode(), |
|
| 90 | - ]); |
|
| 91 | - return self::RESPONSE_NO_CONTENT; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - protected function cacheResult(Changes $entry, string $version) { |
|
| 95 | - if ($entry->getVersion() === $version) { |
|
| 96 | - $this->mapper->update($entry); |
|
| 97 | - } else { |
|
| 98 | - $entry->setVersion($version); |
|
| 99 | - $this->mapper->insert($entry); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @throws \Exception |
|
| 105 | - */ |
|
| 106 | - protected function queryChangesServer(string $uri, Changes $entry): IResponse { |
|
| 107 | - $headers = []; |
|
| 108 | - if ($entry->getEtag() !== '') { |
|
| 109 | - $headers['If-None-Match'] = [$entry->getEtag()]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $entry->setLastCheck(time()); |
|
| 113 | - $client = $this->clientService->newClient(); |
|
| 114 | - return $client->get($uri, [ |
|
| 115 | - 'headers' => $headers, |
|
| 116 | - ]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - protected function extractData($body):array { |
|
| 120 | - $data = []; |
|
| 121 | - if ($body) { |
|
| 122 | - if (\LIBXML_VERSION < 20900) { |
|
| 123 | - $loadEntities = libxml_disable_entity_loader(true); |
|
| 124 | - $xml = @simplexml_load_string($body); |
|
| 125 | - libxml_disable_entity_loader($loadEntities); |
|
| 126 | - } else { |
|
| 127 | - $xml = @simplexml_load_string($body); |
|
| 128 | - } |
|
| 129 | - if ($xml !== false) { |
|
| 130 | - $data['changelogURL'] = (string)$xml->changelog['href']; |
|
| 131 | - $data['whatsNew'] = []; |
|
| 132 | - foreach ($xml->whatsNew as $infoSet) { |
|
| 133 | - $data['whatsNew'][(string)$infoSet['lang']] = [ |
|
| 134 | - 'regular' => (array)$infoSet->regular->item, |
|
| 135 | - 'admin' => (array)$infoSet->admin->item, |
|
| 136 | - ]; |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - libxml_clear_errors(); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - return $data; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * returns a x.y.z form of the provided version. Extra numbers will be |
|
| 147 | - * omitted, missing ones added as zeros. |
|
| 148 | - */ |
|
| 149 | - public function normalizeVersion(string $version): string { |
|
| 150 | - $versionNumbers = array_slice(explode('.', $version), 0, 3); |
|
| 151 | - $versionNumbers[0] = $versionNumbers[0] ?: '0'; // deal with empty input |
|
| 152 | - while (count($versionNumbers) < 3) { |
|
| 153 | - // changelog server expects x.y.z, pad 0 if it is too short |
|
| 154 | - $versionNumbers[] = 0; |
|
| 155 | - } |
|
| 156 | - return implode('.', $versionNumbers); |
|
| 157 | - } |
|
| 17 | + /** @var IClientService */ |
|
| 18 | + protected $clientService; |
|
| 19 | + /** @var ChangesMapper */ |
|
| 20 | + private $mapper; |
|
| 21 | + private LoggerInterface $logger; |
|
| 22 | + |
|
| 23 | + public const RESPONSE_NO_CONTENT = 0; |
|
| 24 | + public const RESPONSE_USE_CACHE = 1; |
|
| 25 | + public const RESPONSE_HAS_CONTENT = 2; |
|
| 26 | + |
|
| 27 | + public function __construct(IClientService $clientService, ChangesMapper $mapper, LoggerInterface $logger) { |
|
| 28 | + $this->clientService = $clientService; |
|
| 29 | + $this->mapper = $mapper; |
|
| 30 | + $this->logger = $logger; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @throws DoesNotExistException |
|
| 35 | + * @return array{changelogURL: string, whatsNew: array<string, array{admin: list<string>, regular: list<string>}>} |
|
| 36 | + */ |
|
| 37 | + public function getChangesForVersion(string $version): array { |
|
| 38 | + $version = $this->normalizeVersion($version); |
|
| 39 | + $changesInfo = $this->mapper->getChanges($version); |
|
| 40 | + $changesData = json_decode($changesInfo->getData(), true); |
|
| 41 | + if (empty($changesData)) { |
|
| 42 | + throw new DoesNotExistException('Unable to decode changes info'); |
|
| 43 | + } |
|
| 44 | + return $changesData; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @throws \Exception |
|
| 49 | + */ |
|
| 50 | + public function check(string $uri, string $version): array { |
|
| 51 | + try { |
|
| 52 | + $version = $this->normalizeVersion($version); |
|
| 53 | + $changesInfo = $this->mapper->getChanges($version); |
|
| 54 | + if ($changesInfo->getLastCheck() + 1800 > time()) { |
|
| 55 | + return json_decode($changesInfo->getData(), true); |
|
| 56 | + } |
|
| 57 | + } catch (DoesNotExistException $e) { |
|
| 58 | + $changesInfo = new Changes(); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $response = $this->queryChangesServer($uri, $changesInfo); |
|
| 62 | + |
|
| 63 | + switch ($this->evaluateResponse($response)) { |
|
| 64 | + case self::RESPONSE_NO_CONTENT: |
|
| 65 | + return []; |
|
| 66 | + case self::RESPONSE_USE_CACHE: |
|
| 67 | + return json_decode($changesInfo->getData(), true); |
|
| 68 | + case self::RESPONSE_HAS_CONTENT: |
|
| 69 | + default: |
|
| 70 | + $data = $this->extractData($response->getBody()); |
|
| 71 | + $changesInfo->setData(json_encode($data)); |
|
| 72 | + $changesInfo->setEtag($response->getHeader('Etag')); |
|
| 73 | + $this->cacheResult($changesInfo, $version); |
|
| 74 | + |
|
| 75 | + return $data; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + protected function evaluateResponse(IResponse $response): int { |
|
| 80 | + if ($response->getStatusCode() === 304) { |
|
| 81 | + return self::RESPONSE_USE_CACHE; |
|
| 82 | + } elseif ($response->getStatusCode() === 404) { |
|
| 83 | + return self::RESPONSE_NO_CONTENT; |
|
| 84 | + } elseif ($response->getStatusCode() === 200) { |
|
| 85 | + return self::RESPONSE_HAS_CONTENT; |
|
| 86 | + } |
|
| 87 | + $this->logger->debug('Unexpected return code {code} from changelog server', [ |
|
| 88 | + 'app' => 'core', |
|
| 89 | + 'code' => $response->getStatusCode(), |
|
| 90 | + ]); |
|
| 91 | + return self::RESPONSE_NO_CONTENT; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + protected function cacheResult(Changes $entry, string $version) { |
|
| 95 | + if ($entry->getVersion() === $version) { |
|
| 96 | + $this->mapper->update($entry); |
|
| 97 | + } else { |
|
| 98 | + $entry->setVersion($version); |
|
| 99 | + $this->mapper->insert($entry); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @throws \Exception |
|
| 105 | + */ |
|
| 106 | + protected function queryChangesServer(string $uri, Changes $entry): IResponse { |
|
| 107 | + $headers = []; |
|
| 108 | + if ($entry->getEtag() !== '') { |
|
| 109 | + $headers['If-None-Match'] = [$entry->getEtag()]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $entry->setLastCheck(time()); |
|
| 113 | + $client = $this->clientService->newClient(); |
|
| 114 | + return $client->get($uri, [ |
|
| 115 | + 'headers' => $headers, |
|
| 116 | + ]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + protected function extractData($body):array { |
|
| 120 | + $data = []; |
|
| 121 | + if ($body) { |
|
| 122 | + if (\LIBXML_VERSION < 20900) { |
|
| 123 | + $loadEntities = libxml_disable_entity_loader(true); |
|
| 124 | + $xml = @simplexml_load_string($body); |
|
| 125 | + libxml_disable_entity_loader($loadEntities); |
|
| 126 | + } else { |
|
| 127 | + $xml = @simplexml_load_string($body); |
|
| 128 | + } |
|
| 129 | + if ($xml !== false) { |
|
| 130 | + $data['changelogURL'] = (string)$xml->changelog['href']; |
|
| 131 | + $data['whatsNew'] = []; |
|
| 132 | + foreach ($xml->whatsNew as $infoSet) { |
|
| 133 | + $data['whatsNew'][(string)$infoSet['lang']] = [ |
|
| 134 | + 'regular' => (array)$infoSet->regular->item, |
|
| 135 | + 'admin' => (array)$infoSet->admin->item, |
|
| 136 | + ]; |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + libxml_clear_errors(); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + return $data; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * returns a x.y.z form of the provided version. Extra numbers will be |
|
| 147 | + * omitted, missing ones added as zeros. |
|
| 148 | + */ |
|
| 149 | + public function normalizeVersion(string $version): string { |
|
| 150 | + $versionNumbers = array_slice(explode('.', $version), 0, 3); |
|
| 151 | + $versionNumbers[0] = $versionNumbers[0] ?: '0'; // deal with empty input |
|
| 152 | + while (count($versionNumbers) < 3) { |
|
| 153 | + // changelog server expects x.y.z, pad 0 if it is too short |
|
| 154 | + $versionNumbers[] = 0; |
|
| 155 | + } |
|
| 156 | + return implode('.', $versionNumbers); |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | |
| 53 | 53 | $result = $qb->select('class') |
| 54 | 54 | ->from($this->getTableName(), 'auth') |
| 55 | - ->where($qb->expr()->in('group_id', array_map(function (IGroup $group) use ($qb) { |
|
| 55 | + ->where($qb->expr()->in('group_id', array_map(function(IGroup $group) use ($qb) { |
|
| 56 | 56 | return $qb->createNamedParameter($group->getGID()); |
| 57 | 57 | }, $groups), IQueryBuilder::PARAM_STR)) |
| 58 | 58 | ->executeQuery(); |
@@ -36,93 +36,93 @@ |
||
| 36 | 36 | * @template-extends QBMapper<AuthorizedGroup> |
| 37 | 37 | */ |
| 38 | 38 | class AuthorizedGroupMapper extends QBMapper { |
| 39 | - public function __construct(IDBConnection $db) { |
|
| 40 | - parent::__construct($db, 'authorized_groups', AuthorizedGroup::class); |
|
| 41 | - } |
|
| 39 | + public function __construct(IDBConnection $db) { |
|
| 40 | + parent::__construct($db, 'authorized_groups', AuthorizedGroup::class); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @throws Exception |
|
| 45 | - */ |
|
| 46 | - public function findAllClassesForUser(IUser $user): array { |
|
| 47 | - $qb = $this->db->getQueryBuilder(); |
|
| 43 | + /** |
|
| 44 | + * @throws Exception |
|
| 45 | + */ |
|
| 46 | + public function findAllClassesForUser(IUser $user): array { |
|
| 47 | + $qb = $this->db->getQueryBuilder(); |
|
| 48 | 48 | |
| 49 | - /** @var IGroupManager $groupManager */ |
|
| 50 | - $groupManager = \OC::$server->get(IGroupManager::class); |
|
| 51 | - $groups = $groupManager->getUserGroups($user); |
|
| 52 | - if (count($groups) === 0) { |
|
| 53 | - return []; |
|
| 54 | - } |
|
| 49 | + /** @var IGroupManager $groupManager */ |
|
| 50 | + $groupManager = \OC::$server->get(IGroupManager::class); |
|
| 51 | + $groups = $groupManager->getUserGroups($user); |
|
| 52 | + if (count($groups) === 0) { |
|
| 53 | + return []; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $result = $qb->select('class') |
|
| 57 | - ->from($this->getTableName(), 'auth') |
|
| 58 | - ->where($qb->expr()->in('group_id', array_map(function (IGroup $group) use ($qb) { |
|
| 59 | - return $qb->createNamedParameter($group->getGID()); |
|
| 60 | - }, $groups), IQueryBuilder::PARAM_STR)) |
|
| 61 | - ->executeQuery(); |
|
| 56 | + $result = $qb->select('class') |
|
| 57 | + ->from($this->getTableName(), 'auth') |
|
| 58 | + ->where($qb->expr()->in('group_id', array_map(function (IGroup $group) use ($qb) { |
|
| 59 | + return $qb->createNamedParameter($group->getGID()); |
|
| 60 | + }, $groups), IQueryBuilder::PARAM_STR)) |
|
| 61 | + ->executeQuery(); |
|
| 62 | 62 | |
| 63 | - $classes = []; |
|
| 64 | - while ($row = $result->fetch()) { |
|
| 65 | - $classes[] = $row['class']; |
|
| 66 | - } |
|
| 67 | - $result->closeCursor(); |
|
| 68 | - return $classes; |
|
| 69 | - } |
|
| 63 | + $classes = []; |
|
| 64 | + while ($row = $result->fetch()) { |
|
| 65 | + $classes[] = $row['class']; |
|
| 66 | + } |
|
| 67 | + $result->closeCursor(); |
|
| 68 | + return $classes; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @throws \OCP\AppFramework\Db\DoesNotExistException |
|
| 73 | - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
|
| 74 | - * @throws \OCP\DB\Exception |
|
| 75 | - */ |
|
| 76 | - public function find(int $id): AuthorizedGroup { |
|
| 77 | - $queryBuilder = $this->db->getQueryBuilder(); |
|
| 78 | - $queryBuilder->select('*') |
|
| 79 | - ->from($this->getTableName()) |
|
| 80 | - ->where($queryBuilder->expr()->eq('id', $queryBuilder->createNamedParameter($id))); |
|
| 81 | - /** @var AuthorizedGroup $authorizedGroup */ |
|
| 82 | - $authorizedGroup = $this->findEntity($queryBuilder); |
|
| 83 | - return $authorizedGroup; |
|
| 84 | - } |
|
| 71 | + /** |
|
| 72 | + * @throws \OCP\AppFramework\Db\DoesNotExistException |
|
| 73 | + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
|
| 74 | + * @throws \OCP\DB\Exception |
|
| 75 | + */ |
|
| 76 | + public function find(int $id): AuthorizedGroup { |
|
| 77 | + $queryBuilder = $this->db->getQueryBuilder(); |
|
| 78 | + $queryBuilder->select('*') |
|
| 79 | + ->from($this->getTableName()) |
|
| 80 | + ->where($queryBuilder->expr()->eq('id', $queryBuilder->createNamedParameter($id))); |
|
| 81 | + /** @var AuthorizedGroup $authorizedGroup */ |
|
| 82 | + $authorizedGroup = $this->findEntity($queryBuilder); |
|
| 83 | + return $authorizedGroup; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get all the authorizations stored in the database. |
|
| 88 | - * |
|
| 89 | - * @return AuthorizedGroup[] |
|
| 90 | - * @throws \OCP\DB\Exception |
|
| 91 | - */ |
|
| 92 | - public function findAll(): array { |
|
| 93 | - $qb = $this->db->getQueryBuilder(); |
|
| 94 | - $qb->select('*')->from($this->getTableName()); |
|
| 95 | - return $this->findEntities($qb); |
|
| 96 | - } |
|
| 86 | + /** |
|
| 87 | + * Get all the authorizations stored in the database. |
|
| 88 | + * |
|
| 89 | + * @return AuthorizedGroup[] |
|
| 90 | + * @throws \OCP\DB\Exception |
|
| 91 | + */ |
|
| 92 | + public function findAll(): array { |
|
| 93 | + $qb = $this->db->getQueryBuilder(); |
|
| 94 | + $qb->select('*')->from($this->getTableName()); |
|
| 95 | + return $this->findEntities($qb); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function findByGroupIdAndClass(string $groupId, string $class) { |
|
| 99 | - $qb = $this->db->getQueryBuilder(); |
|
| 100 | - $qb->select('*') |
|
| 101 | - ->from($this->getTableName()) |
|
| 102 | - ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($groupId))) |
|
| 103 | - ->andWhere($qb->expr()->eq('class', $qb->createNamedParameter($class))); |
|
| 104 | - return $this->findEntity($qb); |
|
| 105 | - } |
|
| 98 | + public function findByGroupIdAndClass(string $groupId, string $class) { |
|
| 99 | + $qb = $this->db->getQueryBuilder(); |
|
| 100 | + $qb->select('*') |
|
| 101 | + ->from($this->getTableName()) |
|
| 102 | + ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($groupId))) |
|
| 103 | + ->andWhere($qb->expr()->eq('class', $qb->createNamedParameter($class))); |
|
| 104 | + return $this->findEntity($qb); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return Entity[] |
|
| 109 | - * @throws \OCP\DB\Exception |
|
| 110 | - */ |
|
| 111 | - public function findExistingGroupsForClass(string $class): array { |
|
| 112 | - $qb = $this->db->getQueryBuilder(); |
|
| 113 | - $qb->select('*') |
|
| 114 | - ->from($this->getTableName()) |
|
| 115 | - ->where($qb->expr()->eq('class', $qb->createNamedParameter($class))); |
|
| 116 | - return $this->findEntities($qb); |
|
| 117 | - } |
|
| 107 | + /** |
|
| 108 | + * @return Entity[] |
|
| 109 | + * @throws \OCP\DB\Exception |
|
| 110 | + */ |
|
| 111 | + public function findExistingGroupsForClass(string $class): array { |
|
| 112 | + $qb = $this->db->getQueryBuilder(); |
|
| 113 | + $qb->select('*') |
|
| 114 | + ->from($this->getTableName()) |
|
| 115 | + ->where($qb->expr()->eq('class', $qb->createNamedParameter($class))); |
|
| 116 | + return $this->findEntities($qb); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @throws Exception |
|
| 121 | - */ |
|
| 122 | - public function removeGroup(string $gid) { |
|
| 123 | - $qb = $this->db->getQueryBuilder(); |
|
| 124 | - $qb->delete($this->getTableName()) |
|
| 125 | - ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($gid))) |
|
| 126 | - ->executeStatement(); |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * @throws Exception |
|
| 121 | + */ |
|
| 122 | + public function removeGroup(string $gid) { |
|
| 123 | + $qb = $this->db->getQueryBuilder(); |
|
| 124 | + $qb->delete($this->getTableName()) |
|
| 125 | + ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($gid))) |
|
| 126 | + ->executeStatement(); |
|
| 127 | + } |
|
| 128 | 128 | } |