@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $result = []; |
| 117 | 117 | foreach ($storagesByMountpoint as $storageList) { |
| 118 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 118 | + $storage = array_reduce($storageList, function($carry, $item) { |
|
| 119 | 119 | if (isset($carry)) { |
| 120 | 120 | $carryPriorityType = $this->getPriorityType($carry); |
| 121 | 121 | $itemPriorityType = $this->getPriorityType($item); |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | $groupIds = $this->groupManager->getUserGroupIds($user); |
| 192 | 192 | $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
| 193 | 193 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
| 194 | - $configs = array_filter($configs, function ($config) { |
|
| 194 | + $configs = array_filter($configs, function($config) { |
|
| 195 | 195 | return $config instanceof StorageConfig; |
| 196 | 196 | }); |
| 197 | 197 | |
| 198 | - $keys = array_map(function (StorageConfig $config) { |
|
| 198 | + $keys = array_map(function(StorageConfig $config) { |
|
| 199 | 199 | return $config->getId(); |
| 200 | 200 | }, $configs); |
| 201 | 201 | |
@@ -20,162 +20,162 @@ |
||
| 20 | 20 | * Read-only access available, attempting to write will throw DomainException |
| 21 | 21 | */ |
| 22 | 22 | class UserGlobalStoragesService extends GlobalStoragesService { |
| 23 | - use UserTrait; |
|
| 24 | - |
|
| 25 | - public function __construct( |
|
| 26 | - BackendService $backendService, |
|
| 27 | - DBConfigService $dbConfig, |
|
| 28 | - IUserSession $userSession, |
|
| 29 | - protected IGroupManager $groupManager, |
|
| 30 | - IUserMountCache $userMountCache, |
|
| 31 | - IEventDispatcher $eventDispatcher, |
|
| 32 | - IAppConfig $appConfig, |
|
| 33 | - ) { |
|
| 34 | - parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig); |
|
| 35 | - $this->userSession = $userSession; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 40 | - * |
|
| 41 | - * @param StorageConfig[] $storages Storages with real IDs |
|
| 42 | - * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 43 | - */ |
|
| 44 | - protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 45 | - // as a read-only view, storage IDs don't need to be real |
|
| 46 | - foreach ($storagesWithConfigHash as $storage) { |
|
| 47 | - $storages[$storage->getId()] = $storage; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - protected function readDBConfig() { |
|
| 52 | - $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 53 | - $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 54 | - $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 55 | - if (count($groups) !== 0) { |
|
| 56 | - $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 57 | - } else { |
|
| 58 | - $groupMounts = []; |
|
| 59 | - } |
|
| 60 | - return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function addStorage(StorageConfig $newStorage) { |
|
| 64 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
| 68 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param integer $id |
|
| 73 | - */ |
|
| 74 | - public function removeStorage($id) { |
|
| 75 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Get unique storages, in case two are defined with the same mountpoint |
|
| 80 | - * Higher priority storages take precedence |
|
| 81 | - * |
|
| 82 | - * @return StorageConfig[] |
|
| 83 | - */ |
|
| 84 | - public function getUniqueStorages() { |
|
| 85 | - $storages = $this->getStorages(); |
|
| 86 | - |
|
| 87 | - $storagesByMountpoint = []; |
|
| 88 | - foreach ($storages as $storage) { |
|
| 89 | - $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $result = []; |
|
| 93 | - foreach ($storagesByMountpoint as $storageList) { |
|
| 94 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 95 | - if (isset($carry)) { |
|
| 96 | - $carryPriorityType = $this->getPriorityType($carry); |
|
| 97 | - $itemPriorityType = $this->getPriorityType($item); |
|
| 98 | - if ($carryPriorityType > $itemPriorityType) { |
|
| 99 | - return $carry; |
|
| 100 | - } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 101 | - if ($carry->getPriority() > $item->getPriority()) { |
|
| 102 | - return $carry; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - return $item; |
|
| 107 | - }); |
|
| 108 | - $result[$storage->getID()] = $storage; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $result; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Get a priority 'type', where a bigger number means higher priority |
|
| 116 | - * user applicable > group applicable > 'all' |
|
| 117 | - * |
|
| 118 | - * @param StorageConfig $storage |
|
| 119 | - * @return int |
|
| 120 | - */ |
|
| 121 | - protected function getPriorityType(StorageConfig $storage) { |
|
| 122 | - $applicableUsers = $storage->getApplicableUsers(); |
|
| 123 | - $applicableGroups = $storage->getApplicableGroups(); |
|
| 124 | - |
|
| 125 | - if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 126 | - return 2; |
|
| 127 | - } |
|
| 128 | - if ($applicableGroups) { |
|
| 129 | - return 1; |
|
| 130 | - } |
|
| 131 | - return 0; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - protected function isApplicable(StorageConfig $config) { |
|
| 135 | - $applicableUsers = $config->getApplicableUsers(); |
|
| 136 | - $applicableGroups = $config->getApplicableGroups(); |
|
| 137 | - |
|
| 138 | - if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 142 | - return true; |
|
| 143 | - } |
|
| 144 | - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 145 | - foreach ($groupIds as $groupId) { |
|
| 146 | - if (in_array($groupId, $applicableGroups, true)) { |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Gets all storages for the user, admin, personal, global, etc |
|
| 156 | - * |
|
| 157 | - * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
| 158 | - * @return StorageConfig[] array of storage configs |
|
| 159 | - */ |
|
| 160 | - public function getAllStoragesForUser(?IUser $user = null) { |
|
| 161 | - if (is_null($user)) { |
|
| 162 | - $user = $this->getUser(); |
|
| 163 | - } |
|
| 164 | - if (is_null($user)) { |
|
| 165 | - return []; |
|
| 166 | - } |
|
| 167 | - $groupIds = $this->groupManager->getUserGroupIds($user); |
|
| 168 | - $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
| 169 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 170 | - $configs = array_filter($configs, function ($config) { |
|
| 171 | - return $config instanceof StorageConfig; |
|
| 172 | - }); |
|
| 173 | - |
|
| 174 | - $keys = array_map(function (StorageConfig $config) { |
|
| 175 | - return $config->getId(); |
|
| 176 | - }, $configs); |
|
| 177 | - |
|
| 178 | - $storages = array_combine($keys, $configs); |
|
| 179 | - return array_filter($storages, [$this, 'validateStorage']); |
|
| 180 | - } |
|
| 23 | + use UserTrait; |
|
| 24 | + |
|
| 25 | + public function __construct( |
|
| 26 | + BackendService $backendService, |
|
| 27 | + DBConfigService $dbConfig, |
|
| 28 | + IUserSession $userSession, |
|
| 29 | + protected IGroupManager $groupManager, |
|
| 30 | + IUserMountCache $userMountCache, |
|
| 31 | + IEventDispatcher $eventDispatcher, |
|
| 32 | + IAppConfig $appConfig, |
|
| 33 | + ) { |
|
| 34 | + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig); |
|
| 35 | + $this->userSession = $userSession; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 40 | + * |
|
| 41 | + * @param StorageConfig[] $storages Storages with real IDs |
|
| 42 | + * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 43 | + */ |
|
| 44 | + protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 45 | + // as a read-only view, storage IDs don't need to be real |
|
| 46 | + foreach ($storagesWithConfigHash as $storage) { |
|
| 47 | + $storages[$storage->getId()] = $storage; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + protected function readDBConfig() { |
|
| 52 | + $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 53 | + $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 54 | + $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 55 | + if (count($groups) !== 0) { |
|
| 56 | + $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 57 | + } else { |
|
| 58 | + $groupMounts = []; |
|
| 59 | + } |
|
| 60 | + return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function addStorage(StorageConfig $newStorage) { |
|
| 64 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
| 68 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param integer $id |
|
| 73 | + */ |
|
| 74 | + public function removeStorage($id) { |
|
| 75 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Get unique storages, in case two are defined with the same mountpoint |
|
| 80 | + * Higher priority storages take precedence |
|
| 81 | + * |
|
| 82 | + * @return StorageConfig[] |
|
| 83 | + */ |
|
| 84 | + public function getUniqueStorages() { |
|
| 85 | + $storages = $this->getStorages(); |
|
| 86 | + |
|
| 87 | + $storagesByMountpoint = []; |
|
| 88 | + foreach ($storages as $storage) { |
|
| 89 | + $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $result = []; |
|
| 93 | + foreach ($storagesByMountpoint as $storageList) { |
|
| 94 | + $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 95 | + if (isset($carry)) { |
|
| 96 | + $carryPriorityType = $this->getPriorityType($carry); |
|
| 97 | + $itemPriorityType = $this->getPriorityType($item); |
|
| 98 | + if ($carryPriorityType > $itemPriorityType) { |
|
| 99 | + return $carry; |
|
| 100 | + } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 101 | + if ($carry->getPriority() > $item->getPriority()) { |
|
| 102 | + return $carry; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + return $item; |
|
| 107 | + }); |
|
| 108 | + $result[$storage->getID()] = $storage; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $result; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Get a priority 'type', where a bigger number means higher priority |
|
| 116 | + * user applicable > group applicable > 'all' |
|
| 117 | + * |
|
| 118 | + * @param StorageConfig $storage |
|
| 119 | + * @return int |
|
| 120 | + */ |
|
| 121 | + protected function getPriorityType(StorageConfig $storage) { |
|
| 122 | + $applicableUsers = $storage->getApplicableUsers(); |
|
| 123 | + $applicableGroups = $storage->getApplicableGroups(); |
|
| 124 | + |
|
| 125 | + if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 126 | + return 2; |
|
| 127 | + } |
|
| 128 | + if ($applicableGroups) { |
|
| 129 | + return 1; |
|
| 130 | + } |
|
| 131 | + return 0; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + protected function isApplicable(StorageConfig $config) { |
|
| 135 | + $applicableUsers = $config->getApplicableUsers(); |
|
| 136 | + $applicableGroups = $config->getApplicableGroups(); |
|
| 137 | + |
|
| 138 | + if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | + if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 142 | + return true; |
|
| 143 | + } |
|
| 144 | + $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 145 | + foreach ($groupIds as $groupId) { |
|
| 146 | + if (in_array($groupId, $applicableGroups, true)) { |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Gets all storages for the user, admin, personal, global, etc |
|
| 156 | + * |
|
| 157 | + * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
| 158 | + * @return StorageConfig[] array of storage configs |
|
| 159 | + */ |
|
| 160 | + public function getAllStoragesForUser(?IUser $user = null) { |
|
| 161 | + if (is_null($user)) { |
|
| 162 | + $user = $this->getUser(); |
|
| 163 | + } |
|
| 164 | + if (is_null($user)) { |
|
| 165 | + return []; |
|
| 166 | + } |
|
| 167 | + $groupIds = $this->groupManager->getUserGroupIds($user); |
|
| 168 | + $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
| 169 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 170 | + $configs = array_filter($configs, function ($config) { |
|
| 171 | + return $config instanceof StorageConfig; |
|
| 172 | + }); |
|
| 173 | + |
|
| 174 | + $keys = array_map(function (StorageConfig $config) { |
|
| 175 | + return $config->getId(); |
|
| 176 | + }, $configs); |
|
| 177 | + |
|
| 178 | + $storages = array_combine($keys, $configs); |
|
| 179 | + return array_filter($storages, [$this, 'validateStorage']); |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -31,11 +31,11 @@ |
||
| 31 | 31 | * @since 20.0.0 |
| 32 | 32 | */ |
| 33 | 33 | interface IRootMountProvider { |
| 34 | - /** |
|
| 35 | - * Get all root mountpoints of this provider |
|
| 36 | - * |
|
| 37 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 38 | - * @since 20.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getRootMounts(IStorageFactory $loader): array; |
|
| 34 | + /** |
|
| 35 | + * Get all root mountpoints of this provider |
|
| 36 | + * |
|
| 37 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 38 | + * @since 20.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getRootMounts(IStorageFactory $loader): array; |
|
| 41 | 41 | } |
@@ -36,56 +36,56 @@ |
||
| 36 | 36 | * @since 18.0.0 |
| 37 | 37 | */ |
| 38 | 38 | interface IRuleMatcher extends IFileCheck { |
| 39 | - /** |
|
| 40 | - * This method is left for backwards compatibility and easier porting of |
|
| 41 | - * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
| 42 | - * an IComplexOperation). |
|
| 43 | - * |
|
| 44 | - * @since 18.0.0 |
|
| 45 | - * @deprecated 18.0.0 |
|
| 46 | - */ |
|
| 47 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
| 39 | + /** |
|
| 40 | + * This method is left for backwards compatibility and easier porting of |
|
| 41 | + * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
| 42 | + * an IComplexOperation). |
|
| 43 | + * |
|
| 44 | + * @since 18.0.0 |
|
| 45 | + * @deprecated 18.0.0 |
|
| 46 | + */ |
|
| 47 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @throws RuntimeException |
|
| 51 | - * @since 18.0.0 |
|
| 52 | - */ |
|
| 53 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
| 49 | + /** |
|
| 50 | + * @throws RuntimeException |
|
| 51 | + * @since 18.0.0 |
|
| 52 | + */ |
|
| 53 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * this method can only be called once and is typically called by the |
|
| 57 | - * Flow engine, unless for IComplexOperations. |
|
| 58 | - * |
|
| 59 | - * @throws RuntimeException |
|
| 60 | - * @since 18.0.0 |
|
| 61 | - */ |
|
| 62 | - public function setOperation(IOperation $operation): void; |
|
| 55 | + /** |
|
| 56 | + * this method can only be called once and is typically called by the |
|
| 57 | + * Flow engine, unless for IComplexOperations. |
|
| 58 | + * |
|
| 59 | + * @throws RuntimeException |
|
| 60 | + * @since 18.0.0 |
|
| 61 | + */ |
|
| 62 | + public function setOperation(IOperation $operation): void; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * this method can only be called once and is typically called by the |
|
| 66 | - * Flow engine, unless for IComplexOperations. |
|
| 67 | - * |
|
| 68 | - * @throws RuntimeException |
|
| 69 | - * @since 18.0.0 |
|
| 70 | - */ |
|
| 71 | - public function setEntity(IEntity $entity): void; |
|
| 64 | + /** |
|
| 65 | + * this method can only be called once and is typically called by the |
|
| 66 | + * Flow engine, unless for IComplexOperations. |
|
| 67 | + * |
|
| 68 | + * @throws RuntimeException |
|
| 69 | + * @since 18.0.0 |
|
| 70 | + */ |
|
| 71 | + public function setEntity(IEntity $entity): void; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * returns the entity which might provide more information, depending on |
|
| 75 | - * the interfaces it implements |
|
| 76 | - * |
|
| 77 | - * @return IEntity |
|
| 78 | - * @since 18.0.0 |
|
| 79 | - */ |
|
| 80 | - public function getEntity(): IEntity; |
|
| 73 | + /** |
|
| 74 | + * returns the entity which might provide more information, depending on |
|
| 75 | + * the interfaces it implements |
|
| 76 | + * |
|
| 77 | + * @return IEntity |
|
| 78 | + * @since 18.0.0 |
|
| 79 | + */ |
|
| 80 | + public function getEntity(): IEntity; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * this method can be called once to set the event name that is currently |
|
| 84 | - * being processed. The workflow engine takes care of this usually, only an |
|
| 85 | - * IComplexOperation might want to make use of it. |
|
| 86 | - * |
|
| 87 | - * @throws RuntimeException |
|
| 88 | - * @since 20.0.0 |
|
| 89 | - */ |
|
| 90 | - public function setEventName(string $eventName): void; |
|
| 82 | + /** |
|
| 83 | + * this method can be called once to set the event name that is currently |
|
| 84 | + * being processed. The workflow engine takes care of this usually, only an |
|
| 85 | + * IComplexOperation might want to make use of it. |
|
| 86 | + * |
|
| 87 | + * @throws RuntimeException |
|
| 88 | + * @since 20.0.0 |
|
| 89 | + */ |
|
| 90 | + public function setEventName(string $eventName): void; |
|
| 91 | 91 | } |
@@ -36,22 +36,22 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Version0002Date20200902144824 extends SimpleMigrationStep { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param IOutput $output |
|
| 41 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | - * @param array $options |
|
| 43 | - * @return null|ISchemaWrapper |
|
| 44 | - * @since 20.0.0 |
|
| 45 | - */ |
|
| 46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | - /** @var ISchemaWrapper $schema */ |
|
| 48 | - $schema = $schemaClosure(); |
|
| 49 | - |
|
| 50 | - $statusTable = $schema->getTable('user_status'); |
|
| 51 | - |
|
| 52 | - $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
| 53 | - $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
| 54 | - |
|
| 55 | - return $schema; |
|
| 56 | - } |
|
| 39 | + /** |
|
| 40 | + * @param IOutput $output |
|
| 41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | + * @param array $options |
|
| 43 | + * @return null|ISchemaWrapper |
|
| 44 | + * @since 20.0.0 |
|
| 45 | + */ |
|
| 46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | + /** @var ISchemaWrapper $schema */ |
|
| 48 | + $schema = $schemaClosure(); |
|
| 49 | + |
|
| 50 | + $statusTable = $schema->getTable('user_status'); |
|
| 51 | + |
|
| 52 | + $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
| 53 | + $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
| 54 | + |
|
| 55 | + return $schema; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -24,30 +24,30 @@ |
||
| 24 | 24 | namespace OC\Files\Cache; |
| 25 | 25 | |
| 26 | 26 | class NullWatcher extends Watcher { |
| 27 | - private $policy; |
|
| 27 | + private $policy; |
|
| 28 | 28 | |
| 29 | - public function __construct() { |
|
| 30 | - } |
|
| 29 | + public function __construct() { |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function setPolicy($policy) { |
|
| 33 | - $this->policy = $policy; |
|
| 34 | - } |
|
| 32 | + public function setPolicy($policy) { |
|
| 33 | + $this->policy = $policy; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function getPolicy() { |
|
| 37 | - return $this->policy; |
|
| 38 | - } |
|
| 36 | + public function getPolicy() { |
|
| 37 | + return $this->policy; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function checkUpdate($path, $cachedEntry = null) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 40 | + public function checkUpdate($path, $cachedEntry = null) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function update($path, $cachedData) { |
|
| 45 | - } |
|
| 44 | + public function update($path, $cachedData) { |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function needsUpdate($path, $cachedData) { |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 47 | + public function needsUpdate($path, $cachedData) { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function cleanFolder($path) { |
|
| 52 | - } |
|
| 51 | + public function cleanFolder($path) { |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -106,7 +106,7 @@ |
||
| 106 | 106 | $jsTrans = []; |
| 107 | 107 | foreach ($translations as $id => $val) { |
| 108 | 108 | if (is_array($val)) { |
| 109 | - $val = '[ ' . implode(',', $val) . ']'; |
|
| 109 | + $val = '[ '.implode(',', $val).']'; |
|
| 110 | 110 | } |
| 111 | 111 | $jsTrans[] = "\"$id\" : \"$val\""; |
| 112 | 112 | } |
@@ -22,141 +22,141 @@ |
||
| 22 | 22 | use UnexpectedValueException; |
| 23 | 23 | |
| 24 | 24 | class CreateJs extends Command implements CompletionAwareInterface { |
| 25 | - public function __construct( |
|
| 26 | - protected IAppManager $appManager, |
|
| 27 | - ) { |
|
| 28 | - parent::__construct(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - protected function configure() { |
|
| 32 | - $this |
|
| 33 | - ->setName('l10n:createjs') |
|
| 34 | - ->setDescription('Create javascript translation files for a given app') |
|
| 35 | - ->addArgument( |
|
| 36 | - 'app', |
|
| 37 | - InputOption::VALUE_REQUIRED, |
|
| 38 | - 'name of the app' |
|
| 39 | - ) |
|
| 40 | - ->addArgument( |
|
| 41 | - 'lang', |
|
| 42 | - InputOption::VALUE_OPTIONAL, |
|
| 43 | - 'name of the language' |
|
| 44 | - ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 48 | - $app = $input->getArgument('app'); |
|
| 49 | - $lang = $input->getArgument('lang'); |
|
| 50 | - |
|
| 51 | - $path = $this->appManager->getAppPath($app); |
|
| 52 | - $languages = $lang; |
|
| 53 | - if (empty($lang)) { |
|
| 54 | - $languages = $this->getAllLanguages($path); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - foreach ($languages as $lang) { |
|
| 58 | - $this->writeFiles($app, $path, $lang, $output); |
|
| 59 | - } |
|
| 60 | - return 0; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - private function getAllLanguages($path) { |
|
| 64 | - $result = []; |
|
| 65 | - foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
| 66 | - if ($fileInfo->isDot()) { |
|
| 67 | - continue; |
|
| 68 | - } |
|
| 69 | - if ($fileInfo->isDir()) { |
|
| 70 | - continue; |
|
| 71 | - } |
|
| 72 | - if ($fileInfo->getExtension() !== 'php') { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 75 | - $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return $result; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
| 82 | - [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
| 83 | - $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
| 84 | - $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
| 88 | - $jsFile = "$path/l10n/$lang.js"; |
|
| 89 | - if (file_exists($jsFile)) { |
|
| 90 | - $output->writeln("File already exists: $jsFile"); |
|
| 91 | - return; |
|
| 92 | - } |
|
| 93 | - $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
| 94 | - $jsTrans = []; |
|
| 95 | - foreach ($translations as $id => $val) { |
|
| 96 | - if (is_array($val)) { |
|
| 97 | - $val = '[ ' . implode(',', $val) . ']'; |
|
| 98 | - } |
|
| 99 | - $jsTrans[] = "\"$id\" : \"$val\""; |
|
| 100 | - } |
|
| 101 | - $content .= implode(",\n ", $jsTrans); |
|
| 102 | - $content .= "\n},\n\"$plurals\");\n"; |
|
| 103 | - |
|
| 104 | - file_put_contents($jsFile, $content); |
|
| 105 | - $output->writeln("Javascript translation file generated: $jsFile"); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
| 109 | - $jsFile = "$path/l10n/$lang.json"; |
|
| 110 | - if (file_exists($jsFile)) { |
|
| 111 | - $output->writeln("File already exists: $jsFile"); |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
| 115 | - file_put_contents($jsFile, json_encode($content)); |
|
| 116 | - $output->writeln("Json translation file generated: $jsFile"); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - private function loadTranslations($path, $lang) { |
|
| 120 | - $phpFile = "$path/l10n/$lang.php"; |
|
| 121 | - $TRANSLATIONS = []; |
|
| 122 | - $PLURAL_FORMS = ''; |
|
| 123 | - if (!file_exists($phpFile)) { |
|
| 124 | - throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
| 125 | - } |
|
| 126 | - require $phpFile; |
|
| 127 | - |
|
| 128 | - return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Return possible values for the named option |
|
| 133 | - * |
|
| 134 | - * @param string $optionName |
|
| 135 | - * @param CompletionContext $context |
|
| 136 | - * @return string[] |
|
| 137 | - */ |
|
| 138 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 139 | - return []; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Return possible values for the named argument |
|
| 144 | - * |
|
| 145 | - * @param string $argumentName |
|
| 146 | - * @param CompletionContext $context |
|
| 147 | - * @return string[] |
|
| 148 | - */ |
|
| 149 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 150 | - if ($argumentName === 'app') { |
|
| 151 | - return $this->appManager->getAllAppsInAppsFolders(); |
|
| 152 | - } elseif ($argumentName === 'lang') { |
|
| 153 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
| 154 | - try { |
|
| 155 | - return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
| 156 | - } catch (AppPathNotFoundException) { |
|
| 157 | - return []; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return []; |
|
| 161 | - } |
|
| 25 | + public function __construct( |
|
| 26 | + protected IAppManager $appManager, |
|
| 27 | + ) { |
|
| 28 | + parent::__construct(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + protected function configure() { |
|
| 32 | + $this |
|
| 33 | + ->setName('l10n:createjs') |
|
| 34 | + ->setDescription('Create javascript translation files for a given app') |
|
| 35 | + ->addArgument( |
|
| 36 | + 'app', |
|
| 37 | + InputOption::VALUE_REQUIRED, |
|
| 38 | + 'name of the app' |
|
| 39 | + ) |
|
| 40 | + ->addArgument( |
|
| 41 | + 'lang', |
|
| 42 | + InputOption::VALUE_OPTIONAL, |
|
| 43 | + 'name of the language' |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 48 | + $app = $input->getArgument('app'); |
|
| 49 | + $lang = $input->getArgument('lang'); |
|
| 50 | + |
|
| 51 | + $path = $this->appManager->getAppPath($app); |
|
| 52 | + $languages = $lang; |
|
| 53 | + if (empty($lang)) { |
|
| 54 | + $languages = $this->getAllLanguages($path); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + foreach ($languages as $lang) { |
|
| 58 | + $this->writeFiles($app, $path, $lang, $output); |
|
| 59 | + } |
|
| 60 | + return 0; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + private function getAllLanguages($path) { |
|
| 64 | + $result = []; |
|
| 65 | + foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
| 66 | + if ($fileInfo->isDot()) { |
|
| 67 | + continue; |
|
| 68 | + } |
|
| 69 | + if ($fileInfo->isDir()) { |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 72 | + if ($fileInfo->getExtension() !== 'php') { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | + $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return $result; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
| 82 | + [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
| 83 | + $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
| 84 | + $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
| 88 | + $jsFile = "$path/l10n/$lang.js"; |
|
| 89 | + if (file_exists($jsFile)) { |
|
| 90 | + $output->writeln("File already exists: $jsFile"); |
|
| 91 | + return; |
|
| 92 | + } |
|
| 93 | + $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
| 94 | + $jsTrans = []; |
|
| 95 | + foreach ($translations as $id => $val) { |
|
| 96 | + if (is_array($val)) { |
|
| 97 | + $val = '[ ' . implode(',', $val) . ']'; |
|
| 98 | + } |
|
| 99 | + $jsTrans[] = "\"$id\" : \"$val\""; |
|
| 100 | + } |
|
| 101 | + $content .= implode(",\n ", $jsTrans); |
|
| 102 | + $content .= "\n},\n\"$plurals\");\n"; |
|
| 103 | + |
|
| 104 | + file_put_contents($jsFile, $content); |
|
| 105 | + $output->writeln("Javascript translation file generated: $jsFile"); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
| 109 | + $jsFile = "$path/l10n/$lang.json"; |
|
| 110 | + if (file_exists($jsFile)) { |
|
| 111 | + $output->writeln("File already exists: $jsFile"); |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
| 115 | + file_put_contents($jsFile, json_encode($content)); |
|
| 116 | + $output->writeln("Json translation file generated: $jsFile"); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + private function loadTranslations($path, $lang) { |
|
| 120 | + $phpFile = "$path/l10n/$lang.php"; |
|
| 121 | + $TRANSLATIONS = []; |
|
| 122 | + $PLURAL_FORMS = ''; |
|
| 123 | + if (!file_exists($phpFile)) { |
|
| 124 | + throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
| 125 | + } |
|
| 126 | + require $phpFile; |
|
| 127 | + |
|
| 128 | + return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Return possible values for the named option |
|
| 133 | + * |
|
| 134 | + * @param string $optionName |
|
| 135 | + * @param CompletionContext $context |
|
| 136 | + * @return string[] |
|
| 137 | + */ |
|
| 138 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 139 | + return []; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Return possible values for the named argument |
|
| 144 | + * |
|
| 145 | + * @param string $argumentName |
|
| 146 | + * @param CompletionContext $context |
|
| 147 | + * @return string[] |
|
| 148 | + */ |
|
| 149 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 150 | + if ($argumentName === 'app') { |
|
| 151 | + return $this->appManager->getAllAppsInAppsFolders(); |
|
| 152 | + } elseif ($argumentName === 'lang') { |
|
| 153 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
| 154 | + try { |
|
| 155 | + return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
| 156 | + } catch (AppPathNotFoundException) { |
|
| 157 | + return []; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return []; |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $providers = $this->registry->getProviderStates($user); |
| 76 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
| 76 | + $state2fa = array_reduce($providers, function(bool $carry, bool $state) { |
|
| 77 | 77 | return $carry || $state; |
| 78 | 78 | }, false); |
| 79 | 79 | |
@@ -17,61 +17,61 @@ |
||
| 17 | 17 | |
| 18 | 18 | class RememberBackupCodesJob extends TimedJob { |
| 19 | 19 | |
| 20 | - public function __construct( |
|
| 21 | - private IRegistry $registry, |
|
| 22 | - private IUserManager $userManager, |
|
| 23 | - ITimeFactory $timeFactory, |
|
| 24 | - private IManager $notificationManager, |
|
| 25 | - private IJobList $jobList, |
|
| 26 | - ) { |
|
| 27 | - parent::__construct($timeFactory); |
|
| 28 | - $this->time = $timeFactory; |
|
| 20 | + public function __construct( |
|
| 21 | + private IRegistry $registry, |
|
| 22 | + private IUserManager $userManager, |
|
| 23 | + ITimeFactory $timeFactory, |
|
| 24 | + private IManager $notificationManager, |
|
| 25 | + private IJobList $jobList, |
|
| 26 | + ) { |
|
| 27 | + parent::__construct($timeFactory); |
|
| 28 | + $this->time = $timeFactory; |
|
| 29 | 29 | |
| 30 | - $this->setInterval(60 * 60 * 24 * 14); |
|
| 31 | - $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
| 32 | - } |
|
| 30 | + $this->setInterval(60 * 60 * 24 * 14); |
|
| 31 | + $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - protected function run($argument) { |
|
| 35 | - $uid = $argument['uid']; |
|
| 36 | - $user = $this->userManager->get($uid); |
|
| 34 | + protected function run($argument) { |
|
| 35 | + $uid = $argument['uid']; |
|
| 36 | + $user = $this->userManager->get($uid); |
|
| 37 | 37 | |
| 38 | - if ($user === null) { |
|
| 39 | - // We can't run with an invalid user |
|
| 40 | - $this->jobList->remove(self::class, $argument); |
|
| 41 | - return; |
|
| 42 | - } |
|
| 38 | + if ($user === null) { |
|
| 39 | + // We can't run with an invalid user |
|
| 40 | + $this->jobList->remove(self::class, $argument); |
|
| 41 | + return; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $providers = $this->registry->getProviderStates($user); |
|
| 45 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
| 46 | - return $carry || $state; |
|
| 47 | - }, false); |
|
| 44 | + $providers = $this->registry->getProviderStates($user); |
|
| 45 | + $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
| 46 | + return $carry || $state; |
|
| 47 | + }, false); |
|
| 48 | 48 | |
| 49 | - /* |
|
| 49 | + /* |
|
| 50 | 50 | * If no provider is active or if the backup codes are already generate |
| 51 | 51 | * we can remove the job |
| 52 | 52 | */ |
| 53 | - if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
| 54 | - // Backup codes already generated lets remove this job |
|
| 55 | - $this->jobList->remove(self::class, $argument); |
|
| 56 | - return; |
|
| 57 | - } |
|
| 53 | + if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
| 54 | + // Backup codes already generated lets remove this job |
|
| 55 | + $this->jobList->remove(self::class, $argument); |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $date = new \DateTime(); |
|
| 60 | - $date->setTimestamp($this->time->getTime()); |
|
| 59 | + $date = new \DateTime(); |
|
| 60 | + $date->setTimestamp($this->time->getTime()); |
|
| 61 | 61 | |
| 62 | - $notification = $this->notificationManager->createNotification(); |
|
| 63 | - $notification->setApp('twofactor_backupcodes') |
|
| 64 | - ->setUser($user->getUID()) |
|
| 65 | - ->setObject('create', 'codes') |
|
| 66 | - ->setSubject('create_backupcodes'); |
|
| 67 | - $this->notificationManager->markProcessed($notification); |
|
| 62 | + $notification = $this->notificationManager->createNotification(); |
|
| 63 | + $notification->setApp('twofactor_backupcodes') |
|
| 64 | + ->setUser($user->getUID()) |
|
| 65 | + ->setObject('create', 'codes') |
|
| 66 | + ->setSubject('create_backupcodes'); |
|
| 67 | + $this->notificationManager->markProcessed($notification); |
|
| 68 | 68 | |
| 69 | - if (!$user->isEnabled()) { |
|
| 70 | - // Don't recreate a notification for a user that can not read it |
|
| 71 | - $this->jobList->remove(self::class, $argument); |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - $notification->setDateTime($date); |
|
| 75 | - $this->notificationManager->notify($notification); |
|
| 76 | - } |
|
| 69 | + if (!$user->isEnabled()) { |
|
| 70 | + // Don't recreate a notification for a user that can not read it |
|
| 71 | + $this->jobList->remove(self::class, $argument); |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + $notification->setDateTime($date); |
|
| 75 | + $this->notificationManager->notify($notification); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function discover(string $remote, string $service, bool $skipCache = false): array { |
| 70 | 70 | // Check the cache first |
| 71 | 71 | if ($skipCache === false) { |
| 72 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
| 72 | + $cacheData = $this->cache->get($remote.'#'.$service); |
|
| 73 | 73 | if ($cacheData) { |
| 74 | 74 | $data = json_decode($cacheData, true); |
| 75 | 75 | if (\is_array($data)) { |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | // query the remote server for available services |
| 84 | 84 | try { |
| 85 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
| 85 | + $response = $this->client->get($remote.'/ocs-provider/', [ |
|
| 86 | 86 | 'timeout' => 10, |
| 87 | 87 | 'connect_timeout' => 10, |
| 88 | 88 | ]); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Write into cache |
| 100 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
| 100 | + $this->cache->set($remote.'#'.$service, json_encode($discoveredServices), 60 * 60 * 24); |
|
| 101 | 101 | return $discoveredServices; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -130,6 +130,6 @@ discard block |
||
| 130 | 130 | * @return bool |
| 131 | 131 | */ |
| 132 | 132 | protected function isSafeUrl(string $url): bool { |
| 133 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
| 133 | + return (bool) preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
| 134 | 134 | } |
| 135 | 135 | } |
@@ -16,98 +16,98 @@ |
||
| 16 | 16 | use OCP\OCS\IDiscoveryService; |
| 17 | 17 | |
| 18 | 18 | class DiscoveryService implements IDiscoveryService { |
| 19 | - /** @var ICache */ |
|
| 20 | - private ICache $cache; |
|
| 19 | + /** @var ICache */ |
|
| 20 | + private ICache $cache; |
|
| 21 | 21 | |
| 22 | - /** @var IClient */ |
|
| 23 | - private IClient $client; |
|
| 22 | + /** @var IClient */ |
|
| 23 | + private IClient $client; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param ICacheFactory $cacheFactory |
|
| 27 | - * @param IClientService $clientService |
|
| 28 | - */ |
|
| 29 | - public function __construct(ICacheFactory $cacheFactory, |
|
| 30 | - IClientService $clientService, |
|
| 31 | - ) { |
|
| 32 | - $this->cache = $cacheFactory->createDistributed('ocs-discovery'); |
|
| 33 | - $this->client = $clientService->newClient(); |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * @param ICacheFactory $cacheFactory |
|
| 27 | + * @param IClientService $clientService |
|
| 28 | + */ |
|
| 29 | + public function __construct(ICacheFactory $cacheFactory, |
|
| 30 | + IClientService $clientService, |
|
| 31 | + ) { |
|
| 32 | + $this->cache = $cacheFactory->createDistributed('ocs-discovery'); |
|
| 33 | + $this->client = $clientService->newClient(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Discover OCS end-points |
|
| 39 | - * |
|
| 40 | - * If no valid discovery data is found the defaults are returned |
|
| 41 | - * |
|
| 42 | - * @param string $remote |
|
| 43 | - * @param string $service the service you want to discover |
|
| 44 | - * @param bool $skipCache We won't check if the data is in the cache. This is useful if a background job is updating the status |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function discover(string $remote, string $service, bool $skipCache = false): array { |
|
| 48 | - // Check the cache first |
|
| 49 | - if ($skipCache === false) { |
|
| 50 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
| 51 | - if ($cacheData) { |
|
| 52 | - $data = json_decode($cacheData, true); |
|
| 53 | - if (\is_array($data)) { |
|
| 54 | - return $data; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 37 | + /** |
|
| 38 | + * Discover OCS end-points |
|
| 39 | + * |
|
| 40 | + * If no valid discovery data is found the defaults are returned |
|
| 41 | + * |
|
| 42 | + * @param string $remote |
|
| 43 | + * @param string $service the service you want to discover |
|
| 44 | + * @param bool $skipCache We won't check if the data is in the cache. This is useful if a background job is updating the status |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function discover(string $remote, string $service, bool $skipCache = false): array { |
|
| 48 | + // Check the cache first |
|
| 49 | + if ($skipCache === false) { |
|
| 50 | + $cacheData = $this->cache->get($remote . '#' . $service); |
|
| 51 | + if ($cacheData) { |
|
| 52 | + $data = json_decode($cacheData, true); |
|
| 53 | + if (\is_array($data)) { |
|
| 54 | + return $data; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $discoveredServices = []; |
|
| 59 | + $discoveredServices = []; |
|
| 60 | 60 | |
| 61 | - // query the remote server for available services |
|
| 62 | - try { |
|
| 63 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
| 64 | - 'timeout' => 10, |
|
| 65 | - 'connect_timeout' => 10, |
|
| 66 | - ]); |
|
| 67 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 68 | - $decodedServices = json_decode($response->getBody(), true); |
|
| 69 | - if (\is_array($decodedServices)) { |
|
| 70 | - $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } catch (\Exception $e) { |
|
| 74 | - // if we couldn't discover the service or any end-points we return a empty array |
|
| 75 | - } |
|
| 61 | + // query the remote server for available services |
|
| 62 | + try { |
|
| 63 | + $response = $this->client->get($remote . '/ocs-provider/', [ |
|
| 64 | + 'timeout' => 10, |
|
| 65 | + 'connect_timeout' => 10, |
|
| 66 | + ]); |
|
| 67 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 68 | + $decodedServices = json_decode($response->getBody(), true); |
|
| 69 | + if (\is_array($decodedServices)) { |
|
| 70 | + $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } catch (\Exception $e) { |
|
| 74 | + // if we couldn't discover the service or any end-points we return a empty array |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - // Write into cache |
|
| 78 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
| 79 | - return $discoveredServices; |
|
| 80 | - } |
|
| 77 | + // Write into cache |
|
| 78 | + $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
| 79 | + return $discoveredServices; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * get requested end-points from the requested service |
|
| 84 | - * |
|
| 85 | - * @param array $decodedServices |
|
| 86 | - * @param string $service |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - protected function getEndpoints(array $decodedServices, string $service): array { |
|
| 90 | - $discoveredServices = []; |
|
| 82 | + /** |
|
| 83 | + * get requested end-points from the requested service |
|
| 84 | + * |
|
| 85 | + * @param array $decodedServices |
|
| 86 | + * @param string $service |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + protected function getEndpoints(array $decodedServices, string $service): array { |
|
| 90 | + $discoveredServices = []; |
|
| 91 | 91 | |
| 92 | - if (isset($decodedServices['services'][$service]['endpoints'])) { |
|
| 93 | - foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
| 94 | - if ($this->isSafeUrl($url)) { |
|
| 95 | - $discoveredServices[$endpoint] = $url; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 92 | + if (isset($decodedServices['services'][$service]['endpoints'])) { |
|
| 93 | + foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
| 94 | + if ($this->isSafeUrl($url)) { |
|
| 95 | + $discoveredServices[$endpoint] = $url; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $discoveredServices; |
|
| 101 | - } |
|
| 100 | + return $discoveredServices; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Returns whether the specified URL includes only safe characters, if not |
|
| 105 | - * returns false |
|
| 106 | - * |
|
| 107 | - * @param string $url |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - protected function isSafeUrl(string $url): bool { |
|
| 111 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
| 112 | - } |
|
| 103 | + /** |
|
| 104 | + * Returns whether the specified URL includes only safe characters, if not |
|
| 105 | + * returns false |
|
| 106 | + * |
|
| 107 | + * @param string $url |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + protected function isSafeUrl(string $url): bool { |
|
| 111 | + return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * actions that user backends can define |
| 41 | 41 | */ |
| 42 | - public const CREATE_USER = 1; // 1 << 0 |
|
| 43 | - public const SET_PASSWORD = 16; // 1 << 4 |
|
| 44 | - public const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 45 | - public const GET_HOME = 4096; // 1 << 12 |
|
| 46 | - public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 47 | - public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 48 | - public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 49 | - public const COUNT_USERS = 268435456; // 1 << 28 |
|
| 42 | + public const CREATE_USER = 1; // 1 << 0 |
|
| 43 | + public const SET_PASSWORD = 16; // 1 << 4 |
|
| 44 | + public const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 45 | + public const GET_HOME = 4096; // 1 << 12 |
|
| 46 | + public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 47 | + public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 48 | + public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 49 | + public const COUNT_USERS = 268435456; // 1 << 28 |
|
| 50 | 50 | |
| 51 | 51 | protected $possibleActions = [ |
| 52 | 52 | self::CREATE_USER => 'createUser', |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * compared with self::CREATE_USER etc. |
| 87 | 87 | */ |
| 88 | 88 | public function implementsActions($actions) { |
| 89 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 89 | + return (bool) ($this->getSupportedActions() & $actions); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -14,136 +14,136 @@ |
||
| 14 | 14 | * capabilities. |
| 15 | 15 | */ |
| 16 | 16 | abstract class Backend implements UserInterface { |
| 17 | - /** |
|
| 18 | - * error code for functions not provided by the user backend |
|
| 19 | - */ |
|
| 20 | - public const NOT_IMPLEMENTED = -501; |
|
| 17 | + /** |
|
| 18 | + * error code for functions not provided by the user backend |
|
| 19 | + */ |
|
| 20 | + public const NOT_IMPLEMENTED = -501; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * actions that user backends can define |
|
| 24 | - */ |
|
| 25 | - public const CREATE_USER = 1; // 1 << 0 |
|
| 26 | - public const SET_PASSWORD = 16; // 1 << 4 |
|
| 27 | - public const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 28 | - public const GET_HOME = 4096; // 1 << 12 |
|
| 29 | - public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 30 | - public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 31 | - public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 32 | - public const COUNT_USERS = 268435456; // 1 << 28 |
|
| 22 | + /** |
|
| 23 | + * actions that user backends can define |
|
| 24 | + */ |
|
| 25 | + public const CREATE_USER = 1; // 1 << 0 |
|
| 26 | + public const SET_PASSWORD = 16; // 1 << 4 |
|
| 27 | + public const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 28 | + public const GET_HOME = 4096; // 1 << 12 |
|
| 29 | + public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 30 | + public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 31 | + public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 32 | + public const COUNT_USERS = 268435456; // 1 << 28 |
|
| 33 | 33 | |
| 34 | - protected $possibleActions = [ |
|
| 35 | - self::CREATE_USER => 'createUser', |
|
| 36 | - self::SET_PASSWORD => 'setPassword', |
|
| 37 | - self::CHECK_PASSWORD => 'checkPassword', |
|
| 38 | - self::GET_HOME => 'getHome', |
|
| 39 | - self::GET_DISPLAYNAME => 'getDisplayName', |
|
| 40 | - self::SET_DISPLAYNAME => 'setDisplayName', |
|
| 41 | - self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
| 42 | - self::COUNT_USERS => 'countUsers', |
|
| 43 | - ]; |
|
| 34 | + protected $possibleActions = [ |
|
| 35 | + self::CREATE_USER => 'createUser', |
|
| 36 | + self::SET_PASSWORD => 'setPassword', |
|
| 37 | + self::CHECK_PASSWORD => 'checkPassword', |
|
| 38 | + self::GET_HOME => 'getHome', |
|
| 39 | + self::GET_DISPLAYNAME => 'getDisplayName', |
|
| 40 | + self::SET_DISPLAYNAME => 'setDisplayName', |
|
| 41 | + self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
| 42 | + self::COUNT_USERS => 'countUsers', |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Get all supported actions |
|
| 47 | - * @return int bitwise-or'ed actions |
|
| 48 | - * |
|
| 49 | - * Returns the supported actions as int to be |
|
| 50 | - * compared with self::CREATE_USER etc. |
|
| 51 | - */ |
|
| 52 | - public function getSupportedActions() { |
|
| 53 | - $actions = 0; |
|
| 54 | - foreach ($this->possibleActions as $action => $methodName) { |
|
| 55 | - if (method_exists($this, $methodName)) { |
|
| 56 | - $actions |= $action; |
|
| 57 | - } |
|
| 58 | - } |
|
| 45 | + /** |
|
| 46 | + * Get all supported actions |
|
| 47 | + * @return int bitwise-or'ed actions |
|
| 48 | + * |
|
| 49 | + * Returns the supported actions as int to be |
|
| 50 | + * compared with self::CREATE_USER etc. |
|
| 51 | + */ |
|
| 52 | + public function getSupportedActions() { |
|
| 53 | + $actions = 0; |
|
| 54 | + foreach ($this->possibleActions as $action => $methodName) { |
|
| 55 | + if (method_exists($this, $methodName)) { |
|
| 56 | + $actions |= $action; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $actions; |
|
| 61 | - } |
|
| 60 | + return $actions; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Check if backend implements actions |
|
| 65 | - * @param int $actions bitwise-or'ed actions |
|
| 66 | - * @return boolean |
|
| 67 | - * |
|
| 68 | - * Returns the supported actions as int to be |
|
| 69 | - * compared with self::CREATE_USER etc. |
|
| 70 | - */ |
|
| 71 | - public function implementsActions($actions) { |
|
| 72 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 73 | - } |
|
| 63 | + /** |
|
| 64 | + * Check if backend implements actions |
|
| 65 | + * @param int $actions bitwise-or'ed actions |
|
| 66 | + * @return boolean |
|
| 67 | + * |
|
| 68 | + * Returns the supported actions as int to be |
|
| 69 | + * compared with self::CREATE_USER etc. |
|
| 70 | + */ |
|
| 71 | + public function implementsActions($actions) { |
|
| 72 | + return (bool)($this->getSupportedActions() & $actions); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * delete a user |
|
| 77 | - * @param string $uid The username of the user to delete |
|
| 78 | - * @return bool |
|
| 79 | - * |
|
| 80 | - * Deletes a user |
|
| 81 | - */ |
|
| 82 | - public function deleteUser($uid) { |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 75 | + /** |
|
| 76 | + * delete a user |
|
| 77 | + * @param string $uid The username of the user to delete |
|
| 78 | + * @return bool |
|
| 79 | + * |
|
| 80 | + * Deletes a user |
|
| 81 | + */ |
|
| 82 | + public function deleteUser($uid) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get a list of all users |
|
| 88 | - * |
|
| 89 | - * @param string $search |
|
| 90 | - * @param null|int $limit |
|
| 91 | - * @param null|int $offset |
|
| 92 | - * @return string[] an array of all uids |
|
| 93 | - */ |
|
| 94 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 95 | - return []; |
|
| 96 | - } |
|
| 86 | + /** |
|
| 87 | + * Get a list of all users |
|
| 88 | + * |
|
| 89 | + * @param string $search |
|
| 90 | + * @param null|int $limit |
|
| 91 | + * @param null|int $offset |
|
| 92 | + * @return string[] an array of all uids |
|
| 93 | + */ |
|
| 94 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 95 | + return []; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * check if a user exists |
|
| 100 | - * @param string $uid the username |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function userExists($uid) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 98 | + /** |
|
| 99 | + * check if a user exists |
|
| 100 | + * @param string $uid the username |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function userExists($uid) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * get the user's home directory |
|
| 109 | - * @param string $uid the username |
|
| 110 | - * @return string|boolean |
|
| 111 | - */ |
|
| 112 | - public function getHome(string $uid) { |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 107 | + /** |
|
| 108 | + * get the user's home directory |
|
| 109 | + * @param string $uid the username |
|
| 110 | + * @return string|boolean |
|
| 111 | + */ |
|
| 112 | + public function getHome(string $uid) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * get display name of the user |
|
| 118 | - * @param string $uid user ID of the user |
|
| 119 | - * @return string display name |
|
| 120 | - */ |
|
| 121 | - public function getDisplayName($uid) { |
|
| 122 | - return $uid; |
|
| 123 | - } |
|
| 116 | + /** |
|
| 117 | + * get display name of the user |
|
| 118 | + * @param string $uid user ID of the user |
|
| 119 | + * @return string display name |
|
| 120 | + */ |
|
| 121 | + public function getDisplayName($uid) { |
|
| 122 | + return $uid; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get a list of all display names and user ids. |
|
| 127 | - * |
|
| 128 | - * @param string $search |
|
| 129 | - * @param int|null $limit |
|
| 130 | - * @param int|null $offset |
|
| 131 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 132 | - */ |
|
| 133 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 134 | - $displayNames = []; |
|
| 135 | - $users = $this->getUsers($search, $limit, $offset); |
|
| 136 | - foreach ($users as $user) { |
|
| 137 | - $displayNames[$user] = $user; |
|
| 138 | - } |
|
| 139 | - return $displayNames; |
|
| 140 | - } |
|
| 125 | + /** |
|
| 126 | + * Get a list of all display names and user ids. |
|
| 127 | + * |
|
| 128 | + * @param string $search |
|
| 129 | + * @param int|null $limit |
|
| 130 | + * @param int|null $offset |
|
| 131 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 132 | + */ |
|
| 133 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 134 | + $displayNames = []; |
|
| 135 | + $users = $this->getUsers($search, $limit, $offset); |
|
| 136 | + foreach ($users as $user) { |
|
| 137 | + $displayNames[$user] = $user; |
|
| 138 | + } |
|
| 139 | + return $displayNames; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Check if a user list is available or not |
|
| 144 | - * @return boolean if users can be listed or not |
|
| 145 | - */ |
|
| 146 | - public function hasUserListings() { |
|
| 147 | - return false; |
|
| 148 | - } |
|
| 142 | + /** |
|
| 143 | + * Check if a user list is available or not |
|
| 144 | + * @return boolean if users can be listed or not |
|
| 145 | + */ |
|
| 146 | + public function hasUserListings() { |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 149 | 149 | } |