@@ -37,14 +37,14 @@ |
||
| 37 | 37 | $appContainer = \OCA\Files_External\MountConfig::$app->getContainer(); |
| 38 | 38 | |
| 39 | 39 | \OCA\Files\App::getNavigationManager()->add(function () { |
| 40 | - $l = \OC::$server->getL10N('files_external'); |
|
| 41 | - return [ |
|
| 42 | - 'id' => 'extstoragemounts', |
|
| 43 | - 'appname' => 'files_external', |
|
| 44 | - 'script' => 'list.php', |
|
| 45 | - 'order' => 30, |
|
| 46 | - 'name' => $l->t('External storage'), |
|
| 47 | - ]; |
|
| 40 | + $l = \OC::$server->getL10N('files_external'); |
|
| 41 | + return [ |
|
| 42 | + 'id' => 'extstoragemounts', |
|
| 43 | + 'appname' => 'files_external', |
|
| 44 | + 'script' => 'list.php', |
|
| 45 | + 'order' => 30, |
|
| 46 | + 'name' => $l->t('External storage'), |
|
| 47 | + ]; |
|
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | $mountProvider = $appContainer->query(ConfigAdapter::class); |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | <h2><?php p($l->t('No external storage configured or you don\'t have the permission to configure them')); ?></h2> |
| 101 | 101 | </div> |
| 102 | 102 | |
| 103 | -<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
| 103 | +<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>"> |
|
| 104 | 104 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2> |
| 105 | - <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
| 105 | + <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation')); ?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
| 106 | 106 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
| 107 | 107 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
| 108 | 108 | print_unescaped(''.$_['dependencies'].''); |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | <?php p($l->t('Add storage')); ?> |
| 143 | 143 | </option> |
| 144 | 144 | <?php |
| 145 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
| 145 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
| 146 | 146 | return $backend->isVisibleFor($_['visibilityType']); |
| 147 | 147 | }); |
| 148 | - uasort($sortedBackends, function ($a, $b) { |
|
| 148 | + uasort($sortedBackends, function($a, $b) { |
|
| 149 | 149 | return strcasecmp($a->getText(), $b->getText()); |
| 150 | 150 | }); |
| 151 | 151 | ?> |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
| 186 | 186 | <?php |
| 187 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
| 187 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
| 188 | 188 | return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
| 189 | 189 | }); |
| 190 | 190 | ?> |
@@ -29,55 +29,55 @@ |
||
| 29 | 29 | use OCP\Settings\IIconSection; |
| 30 | 30 | |
| 31 | 31 | class Section implements IIconSection { |
| 32 | - /** @var IL10N */ |
|
| 33 | - private $l; |
|
| 34 | - /** @var IURLGenerator */ |
|
| 35 | - private $url; |
|
| 32 | + /** @var IL10N */ |
|
| 33 | + private $l; |
|
| 34 | + /** @var IURLGenerator */ |
|
| 35 | + private $url; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param IURLGenerator $url |
|
| 39 | - * @param IL10N $l |
|
| 40 | - */ |
|
| 41 | - public function __construct(IURLGenerator $url, IL10N $l) { |
|
| 42 | - $this->url = $url; |
|
| 43 | - $this->l = $l; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @param IURLGenerator $url |
|
| 39 | + * @param IL10N $l |
|
| 40 | + */ |
|
| 41 | + public function __construct(IURLGenerator $url, IL10N $l) { |
|
| 42 | + $this->url = $url; |
|
| 43 | + $this->l = $l; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * returns the ID of the section. It is supposed to be a lower case string, |
|
| 48 | - * e.g. 'ldap' |
|
| 49 | - * |
|
| 50 | - * @returns string |
|
| 51 | - */ |
|
| 52 | - public function getID() { |
|
| 53 | - return 'externalstorages'; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * returns the ID of the section. It is supposed to be a lower case string, |
|
| 48 | + * e.g. 'ldap' |
|
| 49 | + * |
|
| 50 | + * @returns string |
|
| 51 | + */ |
|
| 52 | + public function getID() { |
|
| 53 | + return 'externalstorages'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 58 | - * integration'. Use the L10N service to translate it. |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function getName() { |
|
| 63 | - return $this->l->t('External storage'); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 58 | + * integration'. Use the L10N service to translate it. |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function getName() { |
|
| 63 | + return $this->l->t('External storage'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return int whether the form should be rather on the top or bottom of |
|
| 68 | - * the settings navigation. The sections are arranged in ascending order of |
|
| 69 | - * the priority values. It is required to return a value between 0 and 99. |
|
| 70 | - * |
|
| 71 | - * E.g.: 70 |
|
| 72 | - */ |
|
| 73 | - public function getPriority() { |
|
| 74 | - return 10; |
|
| 75 | - } |
|
| 66 | + /** |
|
| 67 | + * @return int whether the form should be rather on the top or bottom of |
|
| 68 | + * the settings navigation. The sections are arranged in ascending order of |
|
| 69 | + * the priority values. It is required to return a value between 0 and 99. |
|
| 70 | + * |
|
| 71 | + * E.g.: 70 |
|
| 72 | + */ |
|
| 73 | + public function getPriority() { |
|
| 74 | + return 10; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - */ |
|
| 80 | - public function getIcon() { |
|
| 81 | - return $this->url->imagePath('files_external', 'app-dark.svg'); |
|
| 82 | - } |
|
| 77 | + /** |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + */ |
|
| 80 | + public function getIcon() { |
|
| 81 | + return $this->url->imagePath('files_external', 'app-dark.svg'); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -33,179 +33,179 @@ |
||
| 33 | 33 | * Read mount config from legacy mount.json |
| 34 | 34 | */ |
| 35 | 35 | abstract class LegacyStoragesService { |
| 36 | - /** @var BackendService */ |
|
| 37 | - protected $backendService; |
|
| 36 | + /** @var BackendService */ |
|
| 37 | + protected $backendService; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Read legacy config data |
|
| 41 | - * |
|
| 42 | - * @return array list of mount configs |
|
| 43 | - */ |
|
| 44 | - abstract protected function readLegacyConfig(); |
|
| 39 | + /** |
|
| 40 | + * Read legacy config data |
|
| 41 | + * |
|
| 42 | + * @return array list of mount configs |
|
| 43 | + */ |
|
| 44 | + abstract protected function readLegacyConfig(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Copy legacy storage options into the given storage config object. |
|
| 48 | - * |
|
| 49 | - * @param StorageConfig $storageConfig storage config to populate |
|
| 50 | - * @param string $mountType mount type |
|
| 51 | - * @param string $applicable applicable user or group |
|
| 52 | - * @param array $storageOptions legacy storage options |
|
| 53 | - * |
|
| 54 | - * @return StorageConfig populated storage config |
|
| 55 | - */ |
|
| 56 | - protected function populateStorageConfigWithLegacyOptions( |
|
| 57 | - &$storageConfig, |
|
| 58 | - $mountType, |
|
| 59 | - $applicable, |
|
| 60 | - $storageOptions |
|
| 61 | - ) { |
|
| 62 | - $backend = $this->backendService->getBackend($storageOptions['backend']); |
|
| 63 | - if (!$backend) { |
|
| 64 | - throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']); |
|
| 65 | - } |
|
| 66 | - $storageConfig->setBackend($backend); |
|
| 67 | - if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { |
|
| 68 | - $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); |
|
| 69 | - } else { |
|
| 70 | - $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); |
|
| 71 | - $storageOptions['authMechanism'] = 'null'; // to make error handling easier |
|
| 72 | - } |
|
| 73 | - if (!$authMechanism) { |
|
| 74 | - throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']); |
|
| 75 | - } |
|
| 76 | - $storageConfig->setAuthMechanism($authMechanism); |
|
| 77 | - $storageConfig->setBackendOptions($storageOptions['options']); |
|
| 78 | - if (isset($storageOptions['mountOptions'])) { |
|
| 79 | - $storageConfig->setMountOptions($storageOptions['mountOptions']); |
|
| 80 | - } |
|
| 81 | - if (!isset($storageOptions['priority'])) { |
|
| 82 | - $storageOptions['priority'] = $backend->getPriority(); |
|
| 83 | - } |
|
| 84 | - $storageConfig->setPriority($storageOptions['priority']); |
|
| 85 | - if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) { |
|
| 86 | - $applicableUsers = $storageConfig->getApplicableUsers(); |
|
| 87 | - if ($applicable !== 'all') { |
|
| 88 | - $applicableUsers[] = $applicable; |
|
| 89 | - $storageConfig->setApplicableUsers($applicableUsers); |
|
| 90 | - } |
|
| 91 | - } elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) { |
|
| 92 | - $applicableGroups = $storageConfig->getApplicableGroups(); |
|
| 93 | - $applicableGroups[] = $applicable; |
|
| 94 | - $storageConfig->setApplicableGroups($applicableGroups); |
|
| 95 | - } |
|
| 96 | - return $storageConfig; |
|
| 97 | - } |
|
| 46 | + /** |
|
| 47 | + * Copy legacy storage options into the given storage config object. |
|
| 48 | + * |
|
| 49 | + * @param StorageConfig $storageConfig storage config to populate |
|
| 50 | + * @param string $mountType mount type |
|
| 51 | + * @param string $applicable applicable user or group |
|
| 52 | + * @param array $storageOptions legacy storage options |
|
| 53 | + * |
|
| 54 | + * @return StorageConfig populated storage config |
|
| 55 | + */ |
|
| 56 | + protected function populateStorageConfigWithLegacyOptions( |
|
| 57 | + &$storageConfig, |
|
| 58 | + $mountType, |
|
| 59 | + $applicable, |
|
| 60 | + $storageOptions |
|
| 61 | + ) { |
|
| 62 | + $backend = $this->backendService->getBackend($storageOptions['backend']); |
|
| 63 | + if (!$backend) { |
|
| 64 | + throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']); |
|
| 65 | + } |
|
| 66 | + $storageConfig->setBackend($backend); |
|
| 67 | + if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { |
|
| 68 | + $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); |
|
| 69 | + } else { |
|
| 70 | + $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); |
|
| 71 | + $storageOptions['authMechanism'] = 'null'; // to make error handling easier |
|
| 72 | + } |
|
| 73 | + if (!$authMechanism) { |
|
| 74 | + throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']); |
|
| 75 | + } |
|
| 76 | + $storageConfig->setAuthMechanism($authMechanism); |
|
| 77 | + $storageConfig->setBackendOptions($storageOptions['options']); |
|
| 78 | + if (isset($storageOptions['mountOptions'])) { |
|
| 79 | + $storageConfig->setMountOptions($storageOptions['mountOptions']); |
|
| 80 | + } |
|
| 81 | + if (!isset($storageOptions['priority'])) { |
|
| 82 | + $storageOptions['priority'] = $backend->getPriority(); |
|
| 83 | + } |
|
| 84 | + $storageConfig->setPriority($storageOptions['priority']); |
|
| 85 | + if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) { |
|
| 86 | + $applicableUsers = $storageConfig->getApplicableUsers(); |
|
| 87 | + if ($applicable !== 'all') { |
|
| 88 | + $applicableUsers[] = $applicable; |
|
| 89 | + $storageConfig->setApplicableUsers($applicableUsers); |
|
| 90 | + } |
|
| 91 | + } elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) { |
|
| 92 | + $applicableGroups = $storageConfig->getApplicableGroups(); |
|
| 93 | + $applicableGroups[] = $applicable; |
|
| 94 | + $storageConfig->setApplicableGroups($applicableGroups); |
|
| 95 | + } |
|
| 96 | + return $storageConfig; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Read the external storage config |
|
| 101 | - * |
|
| 102 | - * @return StorageConfig[] map of storage id to storage config |
|
| 103 | - */ |
|
| 104 | - public function getAllStorages() { |
|
| 105 | - $mountPoints = $this->readLegacyConfig(); |
|
| 106 | - /** |
|
| 107 | - * Here is the how the horribly messy mount point array looks like |
|
| 108 | - * from the mount.json file: |
|
| 109 | - * |
|
| 110 | - * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath] |
|
| 111 | - * |
|
| 112 | - * - $mountType is either "user" or "group" |
|
| 113 | - * - $applicable is the name of a user or group (or the current user for personal mounts) |
|
| 114 | - * - $mountPath is the mount point path (where the storage must be mounted) |
|
| 115 | - * - $storageOptions is a map of storage options: |
|
| 116 | - * - "priority": storage priority |
|
| 117 | - * - "backend": backend identifier |
|
| 118 | - * - "class": LEGACY backend class name |
|
| 119 | - * - "options": backend-specific options |
|
| 120 | - * - "authMechanism": authentication mechanism identifier |
|
| 121 | - * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) |
|
| 122 | - */ |
|
| 123 | - // group by storage id |
|
| 124 | - /** @var StorageConfig[] $storages */ |
|
| 125 | - $storages = []; |
|
| 126 | - // for storages without id (legacy), group by config hash for |
|
| 127 | - // later processing |
|
| 128 | - $storagesWithConfigHash = []; |
|
| 129 | - foreach ($mountPoints as $mountType => $applicables) { |
|
| 130 | - foreach ($applicables as $applicable => $mountPaths) { |
|
| 131 | - foreach ($mountPaths as $rootMountPath => $storageOptions) { |
|
| 132 | - $currentStorage = null; |
|
| 133 | - /** |
|
| 134 | - * Flag whether the config that was read already has an id. |
|
| 135 | - * If not, it will use a config hash instead and generate |
|
| 136 | - * a proper id later |
|
| 137 | - * |
|
| 138 | - * @var boolean |
|
| 139 | - */ |
|
| 140 | - $hasId = false; |
|
| 141 | - // the root mount point is in the format "/$user/files/the/mount/point" |
|
| 142 | - // we remove the "/$user/files" prefix |
|
| 143 | - $parts = explode('/', ltrim($rootMountPath, '/'), 3); |
|
| 144 | - if (count($parts) < 3) { |
|
| 145 | - // something went wrong, skip |
|
| 146 | - \OC::$server->getLogger()->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']); |
|
| 147 | - continue; |
|
| 148 | - } |
|
| 149 | - $relativeMountPath = rtrim($parts[2], '/'); |
|
| 150 | - // note: we cannot do this after the loop because the decrypted config |
|
| 151 | - // options might be needed for the config hash |
|
| 152 | - $storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']); |
|
| 153 | - if (!isset($storageOptions['backend'])) { |
|
| 154 | - $storageOptions['backend'] = $storageOptions['class']; // legacy compat |
|
| 155 | - } |
|
| 156 | - if (!isset($storageOptions['authMechanism'])) { |
|
| 157 | - $storageOptions['authMechanism'] = null; // ensure config hash works |
|
| 158 | - } |
|
| 159 | - if (isset($storageOptions['id'])) { |
|
| 160 | - $configId = (int)$storageOptions['id']; |
|
| 161 | - if (isset($storages[$configId])) { |
|
| 162 | - $currentStorage = $storages[$configId]; |
|
| 163 | - } |
|
| 164 | - $hasId = true; |
|
| 165 | - } else { |
|
| 166 | - // missing id in legacy config, need to generate |
|
| 167 | - // but at this point we don't know the max-id, so use |
|
| 168 | - // first group it by config hash |
|
| 169 | - $storageOptions['mountpoint'] = $rootMountPath; |
|
| 170 | - $configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions); |
|
| 171 | - if (isset($storagesWithConfigHash[$configId])) { |
|
| 172 | - $currentStorage = $storagesWithConfigHash[$configId]; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - if (is_null($currentStorage)) { |
|
| 176 | - // create new |
|
| 177 | - $currentStorage = new StorageConfig($configId); |
|
| 178 | - $currentStorage->setMountPoint($relativeMountPath); |
|
| 179 | - } |
|
| 180 | - try { |
|
| 181 | - $this->populateStorageConfigWithLegacyOptions( |
|
| 182 | - $currentStorage, |
|
| 183 | - $mountType, |
|
| 184 | - $applicable, |
|
| 185 | - $storageOptions |
|
| 186 | - ); |
|
| 187 | - if ($hasId) { |
|
| 188 | - $storages[$configId] = $currentStorage; |
|
| 189 | - } else { |
|
| 190 | - $storagesWithConfigHash[$configId] = $currentStorage; |
|
| 191 | - } |
|
| 192 | - } catch (\UnexpectedValueException $e) { |
|
| 193 | - // don't die if a storage backend doesn't exist |
|
| 194 | - \OC::$server->getLogger()->logException($e, [ |
|
| 195 | - 'message' => 'Could not load storage.', |
|
| 196 | - 'level' => ILogger::ERROR, |
|
| 197 | - 'app' => 'files_external', |
|
| 198 | - ]); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 99 | + /** |
|
| 100 | + * Read the external storage config |
|
| 101 | + * |
|
| 102 | + * @return StorageConfig[] map of storage id to storage config |
|
| 103 | + */ |
|
| 104 | + public function getAllStorages() { |
|
| 105 | + $mountPoints = $this->readLegacyConfig(); |
|
| 106 | + /** |
|
| 107 | + * Here is the how the horribly messy mount point array looks like |
|
| 108 | + * from the mount.json file: |
|
| 109 | + * |
|
| 110 | + * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath] |
|
| 111 | + * |
|
| 112 | + * - $mountType is either "user" or "group" |
|
| 113 | + * - $applicable is the name of a user or group (or the current user for personal mounts) |
|
| 114 | + * - $mountPath is the mount point path (where the storage must be mounted) |
|
| 115 | + * - $storageOptions is a map of storage options: |
|
| 116 | + * - "priority": storage priority |
|
| 117 | + * - "backend": backend identifier |
|
| 118 | + * - "class": LEGACY backend class name |
|
| 119 | + * - "options": backend-specific options |
|
| 120 | + * - "authMechanism": authentication mechanism identifier |
|
| 121 | + * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) |
|
| 122 | + */ |
|
| 123 | + // group by storage id |
|
| 124 | + /** @var StorageConfig[] $storages */ |
|
| 125 | + $storages = []; |
|
| 126 | + // for storages without id (legacy), group by config hash for |
|
| 127 | + // later processing |
|
| 128 | + $storagesWithConfigHash = []; |
|
| 129 | + foreach ($mountPoints as $mountType => $applicables) { |
|
| 130 | + foreach ($applicables as $applicable => $mountPaths) { |
|
| 131 | + foreach ($mountPaths as $rootMountPath => $storageOptions) { |
|
| 132 | + $currentStorage = null; |
|
| 133 | + /** |
|
| 134 | + * Flag whether the config that was read already has an id. |
|
| 135 | + * If not, it will use a config hash instead and generate |
|
| 136 | + * a proper id later |
|
| 137 | + * |
|
| 138 | + * @var boolean |
|
| 139 | + */ |
|
| 140 | + $hasId = false; |
|
| 141 | + // the root mount point is in the format "/$user/files/the/mount/point" |
|
| 142 | + // we remove the "/$user/files" prefix |
|
| 143 | + $parts = explode('/', ltrim($rootMountPath, '/'), 3); |
|
| 144 | + if (count($parts) < 3) { |
|
| 145 | + // something went wrong, skip |
|
| 146 | + \OC::$server->getLogger()->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']); |
|
| 147 | + continue; |
|
| 148 | + } |
|
| 149 | + $relativeMountPath = rtrim($parts[2], '/'); |
|
| 150 | + // note: we cannot do this after the loop because the decrypted config |
|
| 151 | + // options might be needed for the config hash |
|
| 152 | + $storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']); |
|
| 153 | + if (!isset($storageOptions['backend'])) { |
|
| 154 | + $storageOptions['backend'] = $storageOptions['class']; // legacy compat |
|
| 155 | + } |
|
| 156 | + if (!isset($storageOptions['authMechanism'])) { |
|
| 157 | + $storageOptions['authMechanism'] = null; // ensure config hash works |
|
| 158 | + } |
|
| 159 | + if (isset($storageOptions['id'])) { |
|
| 160 | + $configId = (int)$storageOptions['id']; |
|
| 161 | + if (isset($storages[$configId])) { |
|
| 162 | + $currentStorage = $storages[$configId]; |
|
| 163 | + } |
|
| 164 | + $hasId = true; |
|
| 165 | + } else { |
|
| 166 | + // missing id in legacy config, need to generate |
|
| 167 | + // but at this point we don't know the max-id, so use |
|
| 168 | + // first group it by config hash |
|
| 169 | + $storageOptions['mountpoint'] = $rootMountPath; |
|
| 170 | + $configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions); |
|
| 171 | + if (isset($storagesWithConfigHash[$configId])) { |
|
| 172 | + $currentStorage = $storagesWithConfigHash[$configId]; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + if (is_null($currentStorage)) { |
|
| 176 | + // create new |
|
| 177 | + $currentStorage = new StorageConfig($configId); |
|
| 178 | + $currentStorage->setMountPoint($relativeMountPath); |
|
| 179 | + } |
|
| 180 | + try { |
|
| 181 | + $this->populateStorageConfigWithLegacyOptions( |
|
| 182 | + $currentStorage, |
|
| 183 | + $mountType, |
|
| 184 | + $applicable, |
|
| 185 | + $storageOptions |
|
| 186 | + ); |
|
| 187 | + if ($hasId) { |
|
| 188 | + $storages[$configId] = $currentStorage; |
|
| 189 | + } else { |
|
| 190 | + $storagesWithConfigHash[$configId] = $currentStorage; |
|
| 191 | + } |
|
| 192 | + } catch (\UnexpectedValueException $e) { |
|
| 193 | + // don't die if a storage backend doesn't exist |
|
| 194 | + \OC::$server->getLogger()->logException($e, [ |
|
| 195 | + 'message' => 'Could not load storage.', |
|
| 196 | + 'level' => ILogger::ERROR, |
|
| 197 | + 'app' => 'files_external', |
|
| 198 | + ]); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // convert parameter values |
|
| 205 | - foreach ($storages as $storage) { |
|
| 206 | - $storage->getBackend()->validateStorageDefinition($storage); |
|
| 207 | - $storage->getAuthMechanism()->validateStorageDefinition($storage); |
|
| 208 | - } |
|
| 209 | - return $storages; |
|
| 210 | - } |
|
| 204 | + // convert parameter values |
|
| 205 | + foreach ($storages as $storage) { |
|
| 206 | + $storage->getBackend()->validateStorageDefinition($storage); |
|
| 207 | + $storage->getAuthMechanism()->validateStorageDefinition($storage); |
|
| 208 | + } |
|
| 209 | + return $storages; |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -49,458 +49,458 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | abstract class StoragesService { |
| 51 | 51 | |
| 52 | - /** @var BackendService */ |
|
| 53 | - protected $backendService; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var DBConfigService |
|
| 57 | - */ |
|
| 58 | - protected $dbConfig; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var IUserMountCache |
|
| 62 | - */ |
|
| 63 | - protected $userMountCache; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param BackendService $backendService |
|
| 67 | - * @param DBConfigService $dbConfigService |
|
| 68 | - * @param IUserMountCache $userMountCache |
|
| 69 | - */ |
|
| 70 | - public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { |
|
| 71 | - $this->backendService = $backendService; |
|
| 72 | - $this->dbConfig = $dbConfigService; |
|
| 73 | - $this->userMountCache = $userMountCache; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - protected function readDBConfig() { |
|
| 77 | - return $this->dbConfig->getAdminMounts(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected function getStorageConfigFromDBMount(array $mount) { |
|
| 81 | - $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
| 82 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
| 83 | - }); |
|
| 84 | - $applicableUsers = array_map(function ($applicable) { |
|
| 85 | - return $applicable['value']; |
|
| 86 | - }, $applicableUsers); |
|
| 87 | - |
|
| 88 | - $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
| 89 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
| 90 | - }); |
|
| 91 | - $applicableGroups = array_map(function ($applicable) { |
|
| 92 | - return $applicable['value']; |
|
| 93 | - }, $applicableGroups); |
|
| 94 | - |
|
| 95 | - try { |
|
| 96 | - $config = $this->createStorage( |
|
| 97 | - $mount['mount_point'], |
|
| 98 | - $mount['storage_backend'], |
|
| 99 | - $mount['auth_backend'], |
|
| 100 | - $mount['config'], |
|
| 101 | - $mount['options'], |
|
| 102 | - array_values($applicableUsers), |
|
| 103 | - array_values($applicableGroups), |
|
| 104 | - $mount['priority'] |
|
| 105 | - ); |
|
| 106 | - $config->setType($mount['type']); |
|
| 107 | - $config->setId((int)$mount['mount_id']); |
|
| 108 | - return $config; |
|
| 109 | - } catch (\UnexpectedValueException $e) { |
|
| 110 | - // don't die if a storage backend doesn't exist |
|
| 111 | - \OC::$server->getLogger()->logException($e, [ |
|
| 112 | - 'message' => 'Could not load storage.', |
|
| 113 | - 'level' => ILogger::ERROR, |
|
| 114 | - 'app' => 'files_external', |
|
| 115 | - ]); |
|
| 116 | - return null; |
|
| 117 | - } catch (\InvalidArgumentException $e) { |
|
| 118 | - \OC::$server->getLogger()->logException($e, [ |
|
| 119 | - 'message' => 'Could not load storage.', |
|
| 120 | - 'level' => ILogger::ERROR, |
|
| 121 | - 'app' => 'files_external', |
|
| 122 | - ]); |
|
| 123 | - return null; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Read the external storage config |
|
| 129 | - * |
|
| 130 | - * @return array map of storage id to storage config |
|
| 131 | - */ |
|
| 132 | - protected function readConfig() { |
|
| 133 | - $mounts = $this->readDBConfig(); |
|
| 134 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 135 | - $configs = array_filter($configs, function ($config) { |
|
| 136 | - return $config instanceof StorageConfig; |
|
| 137 | - }); |
|
| 138 | - |
|
| 139 | - $keys = array_map(function (StorageConfig $config) { |
|
| 140 | - return $config->getId(); |
|
| 141 | - }, $configs); |
|
| 142 | - |
|
| 143 | - return array_combine($keys, $configs); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get a storage with status |
|
| 148 | - * |
|
| 149 | - * @param int $id storage id |
|
| 150 | - * |
|
| 151 | - * @return StorageConfig |
|
| 152 | - * @throws NotFoundException if the storage with the given id was not found |
|
| 153 | - */ |
|
| 154 | - public function getStorage($id) { |
|
| 155 | - $mount = $this->dbConfig->getMountById($id); |
|
| 156 | - |
|
| 157 | - if (!is_array($mount)) { |
|
| 158 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $config = $this->getStorageConfigFromDBMount($mount); |
|
| 162 | - if ($this->isApplicable($config)) { |
|
| 163 | - return $config; |
|
| 164 | - } else { |
|
| 165 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Check whether this storage service should provide access to a storage |
|
| 171 | - * |
|
| 172 | - * @param StorageConfig $config |
|
| 173 | - * @return bool |
|
| 174 | - */ |
|
| 175 | - abstract protected function isApplicable(StorageConfig $config); |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Gets all storages, valid or not |
|
| 179 | - * |
|
| 180 | - * @return StorageConfig[] array of storage configs |
|
| 181 | - */ |
|
| 182 | - public function getAllStorages() { |
|
| 183 | - return $this->readConfig(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Gets all valid storages |
|
| 188 | - * |
|
| 189 | - * @return StorageConfig[] |
|
| 190 | - */ |
|
| 191 | - public function getStorages() { |
|
| 192 | - return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Validate storage |
|
| 197 | - * FIXME: De-duplicate with StoragesController::validate() |
|
| 198 | - * |
|
| 199 | - * @param StorageConfig $storage |
|
| 200 | - * @return bool |
|
| 201 | - */ |
|
| 202 | - protected function validateStorage(StorageConfig $storage) { |
|
| 203 | - /** @var Backend */ |
|
| 204 | - $backend = $storage->getBackend(); |
|
| 205 | - /** @var AuthMechanism */ |
|
| 206 | - $authMechanism = $storage->getAuthMechanism(); |
|
| 207 | - |
|
| 208 | - if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
| 209 | - // not permitted to use backend |
|
| 210 | - return false; |
|
| 211 | - } |
|
| 212 | - if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
| 213 | - // not permitted to use auth mechanism |
|
| 214 | - return false; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Get the visibility type for this controller, used in validation |
|
| 222 | - * |
|
| 223 | - * @return string BackendService::VISIBILITY_* constants |
|
| 224 | - */ |
|
| 225 | - abstract public function getVisibilityType(); |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return integer |
|
| 229 | - */ |
|
| 230 | - protected function getType() { |
|
| 231 | - return DBConfigService::MOUNT_TYPE_ADMIN; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Add new storage to the configuration |
|
| 236 | - * |
|
| 237 | - * @param StorageConfig $newStorage storage attributes |
|
| 238 | - * |
|
| 239 | - * @return StorageConfig storage config, with added id |
|
| 240 | - */ |
|
| 241 | - public function addStorage(StorageConfig $newStorage) { |
|
| 242 | - $allStorages = $this->readConfig(); |
|
| 243 | - |
|
| 244 | - $configId = $this->dbConfig->addMount( |
|
| 245 | - $newStorage->getMountPoint(), |
|
| 246 | - $newStorage->getBackend()->getIdentifier(), |
|
| 247 | - $newStorage->getAuthMechanism()->getIdentifier(), |
|
| 248 | - $newStorage->getPriority(), |
|
| 249 | - $this->getType() |
|
| 250 | - ); |
|
| 251 | - |
|
| 252 | - $newStorage->setId($configId); |
|
| 253 | - |
|
| 254 | - foreach ($newStorage->getApplicableUsers() as $user) { |
|
| 255 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 256 | - } |
|
| 257 | - foreach ($newStorage->getApplicableGroups() as $group) { |
|
| 258 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 259 | - } |
|
| 260 | - foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
| 261 | - $this->dbConfig->setConfig($configId, $key, $value); |
|
| 262 | - } |
|
| 263 | - foreach ($newStorage->getMountOptions() as $key => $value) { |
|
| 264 | - $this->dbConfig->setOption($configId, $key, $value); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
| 268 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // add new storage |
|
| 272 | - $allStorages[$configId] = $newStorage; |
|
| 273 | - |
|
| 274 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 275 | - |
|
| 276 | - $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
| 277 | - return $newStorage; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Create a storage from its parameters |
|
| 282 | - * |
|
| 283 | - * @param string $mountPoint storage mount point |
|
| 284 | - * @param string $backendIdentifier backend identifier |
|
| 285 | - * @param string $authMechanismIdentifier authentication mechanism identifier |
|
| 286 | - * @param array $backendOptions backend-specific options |
|
| 287 | - * @param array|null $mountOptions mount-specific options |
|
| 288 | - * @param array|null $applicableUsers users for which to mount the storage |
|
| 289 | - * @param array|null $applicableGroups groups for which to mount the storage |
|
| 290 | - * @param int|null $priority priority |
|
| 291 | - * |
|
| 292 | - * @return StorageConfig |
|
| 293 | - */ |
|
| 294 | - public function createStorage( |
|
| 295 | - $mountPoint, |
|
| 296 | - $backendIdentifier, |
|
| 297 | - $authMechanismIdentifier, |
|
| 298 | - $backendOptions, |
|
| 299 | - $mountOptions = null, |
|
| 300 | - $applicableUsers = null, |
|
| 301 | - $applicableGroups = null, |
|
| 302 | - $priority = null |
|
| 303 | - ) { |
|
| 304 | - $backend = $this->backendService->getBackend($backendIdentifier); |
|
| 305 | - if (!$backend) { |
|
| 306 | - $backend = new InvalidBackend($backendIdentifier); |
|
| 307 | - } |
|
| 308 | - $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
| 309 | - if (!$authMechanism) { |
|
| 310 | - $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
| 311 | - } |
|
| 312 | - $newStorage = new StorageConfig(); |
|
| 313 | - $newStorage->setMountPoint($mountPoint); |
|
| 314 | - $newStorage->setBackend($backend); |
|
| 315 | - $newStorage->setAuthMechanism($authMechanism); |
|
| 316 | - $newStorage->setBackendOptions($backendOptions); |
|
| 317 | - if (isset($mountOptions)) { |
|
| 318 | - $newStorage->setMountOptions($mountOptions); |
|
| 319 | - } |
|
| 320 | - if (isset($applicableUsers)) { |
|
| 321 | - $newStorage->setApplicableUsers($applicableUsers); |
|
| 322 | - } |
|
| 323 | - if (isset($applicableGroups)) { |
|
| 324 | - $newStorage->setApplicableGroups($applicableGroups); |
|
| 325 | - } |
|
| 326 | - if (isset($priority)) { |
|
| 327 | - $newStorage->setPriority($priority); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - return $newStorage; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Triggers the given hook signal for all the applicables given |
|
| 335 | - * |
|
| 336 | - * @param string $signal signal |
|
| 337 | - * @param string $mountPoint hook mount pount param |
|
| 338 | - * @param string $mountType hook mount type param |
|
| 339 | - * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
| 340 | - */ |
|
| 341 | - protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { |
|
| 342 | - foreach ($applicableArray as $applicable) { |
|
| 343 | - \OCP\Util::emitHook( |
|
| 344 | - Filesystem::CLASSNAME, |
|
| 345 | - $signal, |
|
| 346 | - [ |
|
| 347 | - Filesystem::signal_param_path => $mountPoint, |
|
| 348 | - Filesystem::signal_param_mount_type => $mountType, |
|
| 349 | - Filesystem::signal_param_users => $applicable, |
|
| 350 | - ] |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Triggers $signal for all applicable users of the given |
|
| 357 | - * storage |
|
| 358 | - * |
|
| 359 | - * @param StorageConfig $storage storage data |
|
| 360 | - * @param string $signal signal to trigger |
|
| 361 | - */ |
|
| 362 | - abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Triggers signal_create_mount or signal_delete_mount to |
|
| 366 | - * accommodate for additions/deletions in applicableUsers |
|
| 367 | - * and applicableGroups fields. |
|
| 368 | - * |
|
| 369 | - * @param StorageConfig $oldStorage old storage data |
|
| 370 | - * @param StorageConfig $newStorage new storage data |
|
| 371 | - */ |
|
| 372 | - abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Update storage to the configuration |
|
| 376 | - * |
|
| 377 | - * @param StorageConfig $updatedStorage storage attributes |
|
| 378 | - * |
|
| 379 | - * @return StorageConfig storage config |
|
| 380 | - * @throws NotFoundException if the given storage does not exist in the config |
|
| 381 | - */ |
|
| 382 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
| 383 | - $id = $updatedStorage->getId(); |
|
| 384 | - |
|
| 385 | - $existingMount = $this->dbConfig->getMountById($id); |
|
| 386 | - |
|
| 387 | - if (!is_array($existingMount)) { |
|
| 388 | - throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
| 392 | - |
|
| 393 | - if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
| 394 | - throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
| 398 | - $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
| 399 | - $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 400 | - $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 401 | - |
|
| 402 | - $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
| 403 | - $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
| 404 | - $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
| 405 | - $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
| 406 | - $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
| 407 | - $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
| 408 | - |
|
| 409 | - foreach ($removedUsers as $user) { |
|
| 410 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 411 | - } |
|
| 412 | - foreach ($removedGroups as $group) { |
|
| 413 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 414 | - } |
|
| 415 | - foreach ($addedUsers as $user) { |
|
| 416 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 417 | - } |
|
| 418 | - foreach ($addedGroups as $group) { |
|
| 419 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - if ($wasGlobal && !$isGlobal) { |
|
| 423 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 424 | - } elseif (!$wasGlobal && $isGlobal) { |
|
| 425 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
| 429 | - $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
| 430 | - |
|
| 431 | - foreach ($changedConfig as $key => $value) { |
|
| 432 | - if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
| 433 | - $this->dbConfig->setConfig($id, $key, $value); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - foreach ($changedOptions as $key => $value) { |
|
| 437 | - $this->dbConfig->setOption($id, $key, $value); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
| 441 | - $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
| 445 | - $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
| 449 | - |
|
| 450 | - if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
| 451 | - $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
| 452 | - } else { |
|
| 453 | - $storageId = $this->getStorageId($updatedStorage); |
|
| 454 | - foreach ($removedUsers as $userId) { |
|
| 455 | - $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return $this->getStorage($id); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Delete the storage with the given id. |
|
| 464 | - * |
|
| 465 | - * @param int $id storage id |
|
| 466 | - * |
|
| 467 | - * @throws NotFoundException if no storage was found with the given id |
|
| 468 | - */ |
|
| 469 | - public function removeStorage($id) { |
|
| 470 | - $existingMount = $this->dbConfig->getMountById($id); |
|
| 471 | - |
|
| 472 | - if (!is_array($existingMount)) { |
|
| 473 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - $this->dbConfig->removeMount($id); |
|
| 477 | - |
|
| 478 | - $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
| 479 | - $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
| 480 | - |
|
| 481 | - // delete oc_storages entries and oc_filecache |
|
| 482 | - \OC\Files\Cache\Storage::cleanByMountId($id); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Construct the storage implementation |
|
| 487 | - * |
|
| 488 | - * @param StorageConfig $storageConfig |
|
| 489 | - * @return int |
|
| 490 | - */ |
|
| 491 | - private function getStorageId(StorageConfig $storageConfig) { |
|
| 492 | - try { |
|
| 493 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
| 494 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
| 495 | - $storage = new $class($storageConfig->getBackendOptions()); |
|
| 496 | - |
|
| 497 | - // auth mechanism should fire first |
|
| 498 | - $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
| 499 | - $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
| 500 | - |
|
| 501 | - return $storage->getStorageCache()->getNumericId(); |
|
| 502 | - } catch (\Exception $e) { |
|
| 503 | - return -1; |
|
| 504 | - } |
|
| 505 | - } |
|
| 52 | + /** @var BackendService */ |
|
| 53 | + protected $backendService; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var DBConfigService |
|
| 57 | + */ |
|
| 58 | + protected $dbConfig; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var IUserMountCache |
|
| 62 | + */ |
|
| 63 | + protected $userMountCache; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param BackendService $backendService |
|
| 67 | + * @param DBConfigService $dbConfigService |
|
| 68 | + * @param IUserMountCache $userMountCache |
|
| 69 | + */ |
|
| 70 | + public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { |
|
| 71 | + $this->backendService = $backendService; |
|
| 72 | + $this->dbConfig = $dbConfigService; |
|
| 73 | + $this->userMountCache = $userMountCache; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + protected function readDBConfig() { |
|
| 77 | + return $this->dbConfig->getAdminMounts(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected function getStorageConfigFromDBMount(array $mount) { |
|
| 81 | + $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
| 82 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
| 83 | + }); |
|
| 84 | + $applicableUsers = array_map(function ($applicable) { |
|
| 85 | + return $applicable['value']; |
|
| 86 | + }, $applicableUsers); |
|
| 87 | + |
|
| 88 | + $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
| 89 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
| 90 | + }); |
|
| 91 | + $applicableGroups = array_map(function ($applicable) { |
|
| 92 | + return $applicable['value']; |
|
| 93 | + }, $applicableGroups); |
|
| 94 | + |
|
| 95 | + try { |
|
| 96 | + $config = $this->createStorage( |
|
| 97 | + $mount['mount_point'], |
|
| 98 | + $mount['storage_backend'], |
|
| 99 | + $mount['auth_backend'], |
|
| 100 | + $mount['config'], |
|
| 101 | + $mount['options'], |
|
| 102 | + array_values($applicableUsers), |
|
| 103 | + array_values($applicableGroups), |
|
| 104 | + $mount['priority'] |
|
| 105 | + ); |
|
| 106 | + $config->setType($mount['type']); |
|
| 107 | + $config->setId((int)$mount['mount_id']); |
|
| 108 | + return $config; |
|
| 109 | + } catch (\UnexpectedValueException $e) { |
|
| 110 | + // don't die if a storage backend doesn't exist |
|
| 111 | + \OC::$server->getLogger()->logException($e, [ |
|
| 112 | + 'message' => 'Could not load storage.', |
|
| 113 | + 'level' => ILogger::ERROR, |
|
| 114 | + 'app' => 'files_external', |
|
| 115 | + ]); |
|
| 116 | + return null; |
|
| 117 | + } catch (\InvalidArgumentException $e) { |
|
| 118 | + \OC::$server->getLogger()->logException($e, [ |
|
| 119 | + 'message' => 'Could not load storage.', |
|
| 120 | + 'level' => ILogger::ERROR, |
|
| 121 | + 'app' => 'files_external', |
|
| 122 | + ]); |
|
| 123 | + return null; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Read the external storage config |
|
| 129 | + * |
|
| 130 | + * @return array map of storage id to storage config |
|
| 131 | + */ |
|
| 132 | + protected function readConfig() { |
|
| 133 | + $mounts = $this->readDBConfig(); |
|
| 134 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 135 | + $configs = array_filter($configs, function ($config) { |
|
| 136 | + return $config instanceof StorageConfig; |
|
| 137 | + }); |
|
| 138 | + |
|
| 139 | + $keys = array_map(function (StorageConfig $config) { |
|
| 140 | + return $config->getId(); |
|
| 141 | + }, $configs); |
|
| 142 | + |
|
| 143 | + return array_combine($keys, $configs); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get a storage with status |
|
| 148 | + * |
|
| 149 | + * @param int $id storage id |
|
| 150 | + * |
|
| 151 | + * @return StorageConfig |
|
| 152 | + * @throws NotFoundException if the storage with the given id was not found |
|
| 153 | + */ |
|
| 154 | + public function getStorage($id) { |
|
| 155 | + $mount = $this->dbConfig->getMountById($id); |
|
| 156 | + |
|
| 157 | + if (!is_array($mount)) { |
|
| 158 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $config = $this->getStorageConfigFromDBMount($mount); |
|
| 162 | + if ($this->isApplicable($config)) { |
|
| 163 | + return $config; |
|
| 164 | + } else { |
|
| 165 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Check whether this storage service should provide access to a storage |
|
| 171 | + * |
|
| 172 | + * @param StorageConfig $config |
|
| 173 | + * @return bool |
|
| 174 | + */ |
|
| 175 | + abstract protected function isApplicable(StorageConfig $config); |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Gets all storages, valid or not |
|
| 179 | + * |
|
| 180 | + * @return StorageConfig[] array of storage configs |
|
| 181 | + */ |
|
| 182 | + public function getAllStorages() { |
|
| 183 | + return $this->readConfig(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Gets all valid storages |
|
| 188 | + * |
|
| 189 | + * @return StorageConfig[] |
|
| 190 | + */ |
|
| 191 | + public function getStorages() { |
|
| 192 | + return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Validate storage |
|
| 197 | + * FIXME: De-duplicate with StoragesController::validate() |
|
| 198 | + * |
|
| 199 | + * @param StorageConfig $storage |
|
| 200 | + * @return bool |
|
| 201 | + */ |
|
| 202 | + protected function validateStorage(StorageConfig $storage) { |
|
| 203 | + /** @var Backend */ |
|
| 204 | + $backend = $storage->getBackend(); |
|
| 205 | + /** @var AuthMechanism */ |
|
| 206 | + $authMechanism = $storage->getAuthMechanism(); |
|
| 207 | + |
|
| 208 | + if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
| 209 | + // not permitted to use backend |
|
| 210 | + return false; |
|
| 211 | + } |
|
| 212 | + if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
| 213 | + // not permitted to use auth mechanism |
|
| 214 | + return false; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Get the visibility type for this controller, used in validation |
|
| 222 | + * |
|
| 223 | + * @return string BackendService::VISIBILITY_* constants |
|
| 224 | + */ |
|
| 225 | + abstract public function getVisibilityType(); |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return integer |
|
| 229 | + */ |
|
| 230 | + protected function getType() { |
|
| 231 | + return DBConfigService::MOUNT_TYPE_ADMIN; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Add new storage to the configuration |
|
| 236 | + * |
|
| 237 | + * @param StorageConfig $newStorage storage attributes |
|
| 238 | + * |
|
| 239 | + * @return StorageConfig storage config, with added id |
|
| 240 | + */ |
|
| 241 | + public function addStorage(StorageConfig $newStorage) { |
|
| 242 | + $allStorages = $this->readConfig(); |
|
| 243 | + |
|
| 244 | + $configId = $this->dbConfig->addMount( |
|
| 245 | + $newStorage->getMountPoint(), |
|
| 246 | + $newStorage->getBackend()->getIdentifier(), |
|
| 247 | + $newStorage->getAuthMechanism()->getIdentifier(), |
|
| 248 | + $newStorage->getPriority(), |
|
| 249 | + $this->getType() |
|
| 250 | + ); |
|
| 251 | + |
|
| 252 | + $newStorage->setId($configId); |
|
| 253 | + |
|
| 254 | + foreach ($newStorage->getApplicableUsers() as $user) { |
|
| 255 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 256 | + } |
|
| 257 | + foreach ($newStorage->getApplicableGroups() as $group) { |
|
| 258 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 259 | + } |
|
| 260 | + foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
| 261 | + $this->dbConfig->setConfig($configId, $key, $value); |
|
| 262 | + } |
|
| 263 | + foreach ($newStorage->getMountOptions() as $key => $value) { |
|
| 264 | + $this->dbConfig->setOption($configId, $key, $value); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
| 268 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // add new storage |
|
| 272 | + $allStorages[$configId] = $newStorage; |
|
| 273 | + |
|
| 274 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 275 | + |
|
| 276 | + $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
| 277 | + return $newStorage; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Create a storage from its parameters |
|
| 282 | + * |
|
| 283 | + * @param string $mountPoint storage mount point |
|
| 284 | + * @param string $backendIdentifier backend identifier |
|
| 285 | + * @param string $authMechanismIdentifier authentication mechanism identifier |
|
| 286 | + * @param array $backendOptions backend-specific options |
|
| 287 | + * @param array|null $mountOptions mount-specific options |
|
| 288 | + * @param array|null $applicableUsers users for which to mount the storage |
|
| 289 | + * @param array|null $applicableGroups groups for which to mount the storage |
|
| 290 | + * @param int|null $priority priority |
|
| 291 | + * |
|
| 292 | + * @return StorageConfig |
|
| 293 | + */ |
|
| 294 | + public function createStorage( |
|
| 295 | + $mountPoint, |
|
| 296 | + $backendIdentifier, |
|
| 297 | + $authMechanismIdentifier, |
|
| 298 | + $backendOptions, |
|
| 299 | + $mountOptions = null, |
|
| 300 | + $applicableUsers = null, |
|
| 301 | + $applicableGroups = null, |
|
| 302 | + $priority = null |
|
| 303 | + ) { |
|
| 304 | + $backend = $this->backendService->getBackend($backendIdentifier); |
|
| 305 | + if (!$backend) { |
|
| 306 | + $backend = new InvalidBackend($backendIdentifier); |
|
| 307 | + } |
|
| 308 | + $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
| 309 | + if (!$authMechanism) { |
|
| 310 | + $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
| 311 | + } |
|
| 312 | + $newStorage = new StorageConfig(); |
|
| 313 | + $newStorage->setMountPoint($mountPoint); |
|
| 314 | + $newStorage->setBackend($backend); |
|
| 315 | + $newStorage->setAuthMechanism($authMechanism); |
|
| 316 | + $newStorage->setBackendOptions($backendOptions); |
|
| 317 | + if (isset($mountOptions)) { |
|
| 318 | + $newStorage->setMountOptions($mountOptions); |
|
| 319 | + } |
|
| 320 | + if (isset($applicableUsers)) { |
|
| 321 | + $newStorage->setApplicableUsers($applicableUsers); |
|
| 322 | + } |
|
| 323 | + if (isset($applicableGroups)) { |
|
| 324 | + $newStorage->setApplicableGroups($applicableGroups); |
|
| 325 | + } |
|
| 326 | + if (isset($priority)) { |
|
| 327 | + $newStorage->setPriority($priority); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + return $newStorage; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Triggers the given hook signal for all the applicables given |
|
| 335 | + * |
|
| 336 | + * @param string $signal signal |
|
| 337 | + * @param string $mountPoint hook mount pount param |
|
| 338 | + * @param string $mountType hook mount type param |
|
| 339 | + * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
| 340 | + */ |
|
| 341 | + protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { |
|
| 342 | + foreach ($applicableArray as $applicable) { |
|
| 343 | + \OCP\Util::emitHook( |
|
| 344 | + Filesystem::CLASSNAME, |
|
| 345 | + $signal, |
|
| 346 | + [ |
|
| 347 | + Filesystem::signal_param_path => $mountPoint, |
|
| 348 | + Filesystem::signal_param_mount_type => $mountType, |
|
| 349 | + Filesystem::signal_param_users => $applicable, |
|
| 350 | + ] |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Triggers $signal for all applicable users of the given |
|
| 357 | + * storage |
|
| 358 | + * |
|
| 359 | + * @param StorageConfig $storage storage data |
|
| 360 | + * @param string $signal signal to trigger |
|
| 361 | + */ |
|
| 362 | + abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Triggers signal_create_mount or signal_delete_mount to |
|
| 366 | + * accommodate for additions/deletions in applicableUsers |
|
| 367 | + * and applicableGroups fields. |
|
| 368 | + * |
|
| 369 | + * @param StorageConfig $oldStorage old storage data |
|
| 370 | + * @param StorageConfig $newStorage new storage data |
|
| 371 | + */ |
|
| 372 | + abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Update storage to the configuration |
|
| 376 | + * |
|
| 377 | + * @param StorageConfig $updatedStorage storage attributes |
|
| 378 | + * |
|
| 379 | + * @return StorageConfig storage config |
|
| 380 | + * @throws NotFoundException if the given storage does not exist in the config |
|
| 381 | + */ |
|
| 382 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
| 383 | + $id = $updatedStorage->getId(); |
|
| 384 | + |
|
| 385 | + $existingMount = $this->dbConfig->getMountById($id); |
|
| 386 | + |
|
| 387 | + if (!is_array($existingMount)) { |
|
| 388 | + throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
| 392 | + |
|
| 393 | + if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
| 394 | + throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
| 398 | + $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
| 399 | + $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 400 | + $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 401 | + |
|
| 402 | + $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
| 403 | + $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
| 404 | + $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
| 405 | + $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
| 406 | + $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
| 407 | + $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
| 408 | + |
|
| 409 | + foreach ($removedUsers as $user) { |
|
| 410 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 411 | + } |
|
| 412 | + foreach ($removedGroups as $group) { |
|
| 413 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 414 | + } |
|
| 415 | + foreach ($addedUsers as $user) { |
|
| 416 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
| 417 | + } |
|
| 418 | + foreach ($addedGroups as $group) { |
|
| 419 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + if ($wasGlobal && !$isGlobal) { |
|
| 423 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 424 | + } elseif (!$wasGlobal && $isGlobal) { |
|
| 425 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
| 429 | + $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
| 430 | + |
|
| 431 | + foreach ($changedConfig as $key => $value) { |
|
| 432 | + if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
| 433 | + $this->dbConfig->setConfig($id, $key, $value); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + foreach ($changedOptions as $key => $value) { |
|
| 437 | + $this->dbConfig->setOption($id, $key, $value); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
| 441 | + $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
| 445 | + $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
| 449 | + |
|
| 450 | + if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
| 451 | + $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
| 452 | + } else { |
|
| 453 | + $storageId = $this->getStorageId($updatedStorage); |
|
| 454 | + foreach ($removedUsers as $userId) { |
|
| 455 | + $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $this->getStorage($id); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Delete the storage with the given id. |
|
| 464 | + * |
|
| 465 | + * @param int $id storage id |
|
| 466 | + * |
|
| 467 | + * @throws NotFoundException if no storage was found with the given id |
|
| 468 | + */ |
|
| 469 | + public function removeStorage($id) { |
|
| 470 | + $existingMount = $this->dbConfig->getMountById($id); |
|
| 471 | + |
|
| 472 | + if (!is_array($existingMount)) { |
|
| 473 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + $this->dbConfig->removeMount($id); |
|
| 477 | + |
|
| 478 | + $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
| 479 | + $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
| 480 | + |
|
| 481 | + // delete oc_storages entries and oc_filecache |
|
| 482 | + \OC\Files\Cache\Storage::cleanByMountId($id); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Construct the storage implementation |
|
| 487 | + * |
|
| 488 | + * @param StorageConfig $storageConfig |
|
| 489 | + * @return int |
|
| 490 | + */ |
|
| 491 | + private function getStorageId(StorageConfig $storageConfig) { |
|
| 492 | + try { |
|
| 493 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
| 494 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
| 495 | + $storage = new $class($storageConfig->getBackendOptions()); |
|
| 496 | + |
|
| 497 | + // auth mechanism should fire first |
|
| 498 | + $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
| 499 | + $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
| 500 | + |
|
| 501 | + return $storage->getStorageCache()->getNumericId(); |
|
| 502 | + } catch (\Exception $e) { |
|
| 503 | + return -1; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | 506 | } |
@@ -36,151 +36,151 @@ |
||
| 36 | 36 | * Service class to manage global external storage |
| 37 | 37 | */ |
| 38 | 38 | class GlobalStoragesService extends StoragesService { |
| 39 | - /** |
|
| 40 | - * Triggers $signal for all applicable users of the given |
|
| 41 | - * storage |
|
| 42 | - * |
|
| 43 | - * @param StorageConfig $storage storage data |
|
| 44 | - * @param string $signal signal to trigger |
|
| 45 | - */ |
|
| 46 | - protected function triggerHooks(StorageConfig $storage, $signal) { |
|
| 47 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 48 | - $applicableUsers = $storage->getApplicableUsers(); |
|
| 49 | - $applicableGroups = $storage->getApplicableGroups(); |
|
| 50 | - if (empty($applicableUsers) && empty($applicableGroups)) { |
|
| 51 | - // raise for user "all" |
|
| 52 | - $this->triggerApplicableHooks( |
|
| 53 | - $signal, |
|
| 54 | - $storage->getMountPoint(), |
|
| 55 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 56 | - ['all'] |
|
| 57 | - ); |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $this->triggerApplicableHooks( |
|
| 62 | - $signal, |
|
| 63 | - $storage->getMountPoint(), |
|
| 64 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 65 | - $applicableUsers |
|
| 66 | - ); |
|
| 67 | - $this->triggerApplicableHooks( |
|
| 68 | - $signal, |
|
| 69 | - $storage->getMountPoint(), |
|
| 70 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 71 | - $applicableGroups |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Triggers signal_create_mount or signal_delete_mount to |
|
| 77 | - * accommodate for additions/deletions in applicableUsers |
|
| 78 | - * and applicableGroups fields. |
|
| 79 | - * |
|
| 80 | - * @param StorageConfig $oldStorage old storage config |
|
| 81 | - * @param StorageConfig $newStorage new storage config |
|
| 82 | - */ |
|
| 83 | - protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
| 84 | - // if mount point changed, it's like a deletion + creation |
|
| 85 | - if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
| 86 | - $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
| 87 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 92 | - $userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
| 93 | - $groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 94 | - $groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
| 95 | - |
|
| 96 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 97 | - // if no applicable were set, raise a signal for "all" |
|
| 98 | - $oldApplicableUsers = $oldStorage->getApplicableUsers(); |
|
| 99 | - $oldApplicableGroups = $oldStorage->getApplicableGroups(); |
|
| 100 | - if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) { |
|
| 101 | - $this->triggerApplicableHooks( |
|
| 102 | - Filesystem::signal_delete_mount, |
|
| 103 | - $oldStorage->getMountPoint(), |
|
| 104 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 105 | - ['all'] |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // trigger delete for removed users |
|
| 110 | - $this->triggerApplicableHooks( |
|
| 111 | - Filesystem::signal_delete_mount, |
|
| 112 | - $oldStorage->getMountPoint(), |
|
| 113 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 114 | - $userDeletions |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - // trigger delete for removed groups |
|
| 118 | - $this->triggerApplicableHooks( |
|
| 119 | - Filesystem::signal_delete_mount, |
|
| 120 | - $oldStorage->getMountPoint(), |
|
| 121 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 122 | - $groupDeletions |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - // and now add the new users |
|
| 126 | - $this->triggerApplicableHooks( |
|
| 127 | - Filesystem::signal_create_mount, |
|
| 128 | - $newStorage->getMountPoint(), |
|
| 129 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 130 | - $userAdditions |
|
| 131 | - ); |
|
| 132 | - |
|
| 133 | - // and now add the new groups |
|
| 134 | - $this->triggerApplicableHooks( |
|
| 135 | - Filesystem::signal_create_mount, |
|
| 136 | - $newStorage->getMountPoint(), |
|
| 137 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 138 | - $groupAdditions |
|
| 139 | - ); |
|
| 140 | - |
|
| 141 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 142 | - // if no applicable, raise a signal for "all" |
|
| 143 | - $newApplicableUsers = $newStorage->getApplicableUsers(); |
|
| 144 | - $newApplicableGroups = $newStorage->getApplicableGroups(); |
|
| 145 | - if (empty($newApplicableUsers) && empty($newApplicableGroups)) { |
|
| 146 | - $this->triggerApplicableHooks( |
|
| 147 | - Filesystem::signal_create_mount, |
|
| 148 | - $newStorage->getMountPoint(), |
|
| 149 | - \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 150 | - ['all'] |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the visibility type for this controller, used in validation |
|
| 157 | - * |
|
| 158 | - * @return string BackendService::VISIBILITY_* constants |
|
| 159 | - */ |
|
| 160 | - public function getVisibilityType() { |
|
| 161 | - return BackendService::VISIBILITY_ADMIN; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - protected function isApplicable(StorageConfig $config) { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Get all configured admin and personal mounts |
|
| 170 | - * |
|
| 171 | - * @return StorageConfig[] map of storage id to storage config |
|
| 172 | - */ |
|
| 173 | - public function getStorageForAllUsers() { |
|
| 174 | - $mounts = $this->dbConfig->getAllMounts(); |
|
| 175 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 176 | - $configs = array_filter($configs, function ($config) { |
|
| 177 | - return $config instanceof StorageConfig; |
|
| 178 | - }); |
|
| 179 | - |
|
| 180 | - $keys = array_map(function (StorageConfig $config) { |
|
| 181 | - return $config->getId(); |
|
| 182 | - }, $configs); |
|
| 183 | - |
|
| 184 | - return array_combine($keys, $configs); |
|
| 185 | - } |
|
| 39 | + /** |
|
| 40 | + * Triggers $signal for all applicable users of the given |
|
| 41 | + * storage |
|
| 42 | + * |
|
| 43 | + * @param StorageConfig $storage storage data |
|
| 44 | + * @param string $signal signal to trigger |
|
| 45 | + */ |
|
| 46 | + protected function triggerHooks(StorageConfig $storage, $signal) { |
|
| 47 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 48 | + $applicableUsers = $storage->getApplicableUsers(); |
|
| 49 | + $applicableGroups = $storage->getApplicableGroups(); |
|
| 50 | + if (empty($applicableUsers) && empty($applicableGroups)) { |
|
| 51 | + // raise for user "all" |
|
| 52 | + $this->triggerApplicableHooks( |
|
| 53 | + $signal, |
|
| 54 | + $storage->getMountPoint(), |
|
| 55 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 56 | + ['all'] |
|
| 57 | + ); |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $this->triggerApplicableHooks( |
|
| 62 | + $signal, |
|
| 63 | + $storage->getMountPoint(), |
|
| 64 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 65 | + $applicableUsers |
|
| 66 | + ); |
|
| 67 | + $this->triggerApplicableHooks( |
|
| 68 | + $signal, |
|
| 69 | + $storage->getMountPoint(), |
|
| 70 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 71 | + $applicableGroups |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Triggers signal_create_mount or signal_delete_mount to |
|
| 77 | + * accommodate for additions/deletions in applicableUsers |
|
| 78 | + * and applicableGroups fields. |
|
| 79 | + * |
|
| 80 | + * @param StorageConfig $oldStorage old storage config |
|
| 81 | + * @param StorageConfig $newStorage new storage config |
|
| 82 | + */ |
|
| 83 | + protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
| 84 | + // if mount point changed, it's like a deletion + creation |
|
| 85 | + if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
| 86 | + $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
| 87 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 92 | + $userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
| 93 | + $groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 94 | + $groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
| 95 | + |
|
| 96 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 97 | + // if no applicable were set, raise a signal for "all" |
|
| 98 | + $oldApplicableUsers = $oldStorage->getApplicableUsers(); |
|
| 99 | + $oldApplicableGroups = $oldStorage->getApplicableGroups(); |
|
| 100 | + if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) { |
|
| 101 | + $this->triggerApplicableHooks( |
|
| 102 | + Filesystem::signal_delete_mount, |
|
| 103 | + $oldStorage->getMountPoint(), |
|
| 104 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 105 | + ['all'] |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // trigger delete for removed users |
|
| 110 | + $this->triggerApplicableHooks( |
|
| 111 | + Filesystem::signal_delete_mount, |
|
| 112 | + $oldStorage->getMountPoint(), |
|
| 113 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 114 | + $userDeletions |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + // trigger delete for removed groups |
|
| 118 | + $this->triggerApplicableHooks( |
|
| 119 | + Filesystem::signal_delete_mount, |
|
| 120 | + $oldStorage->getMountPoint(), |
|
| 121 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 122 | + $groupDeletions |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + // and now add the new users |
|
| 126 | + $this->triggerApplicableHooks( |
|
| 127 | + Filesystem::signal_create_mount, |
|
| 128 | + $newStorage->getMountPoint(), |
|
| 129 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 130 | + $userAdditions |
|
| 131 | + ); |
|
| 132 | + |
|
| 133 | + // and now add the new groups |
|
| 134 | + $this->triggerApplicableHooks( |
|
| 135 | + Filesystem::signal_create_mount, |
|
| 136 | + $newStorage->getMountPoint(), |
|
| 137 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP, |
|
| 138 | + $groupAdditions |
|
| 139 | + ); |
|
| 140 | + |
|
| 141 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 142 | + // if no applicable, raise a signal for "all" |
|
| 143 | + $newApplicableUsers = $newStorage->getApplicableUsers(); |
|
| 144 | + $newApplicableGroups = $newStorage->getApplicableGroups(); |
|
| 145 | + if (empty($newApplicableUsers) && empty($newApplicableGroups)) { |
|
| 146 | + $this->triggerApplicableHooks( |
|
| 147 | + Filesystem::signal_create_mount, |
|
| 148 | + $newStorage->getMountPoint(), |
|
| 149 | + \OCA\Files_External\MountConfig::MOUNT_TYPE_USER, |
|
| 150 | + ['all'] |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the visibility type for this controller, used in validation |
|
| 157 | + * |
|
| 158 | + * @return string BackendService::VISIBILITY_* constants |
|
| 159 | + */ |
|
| 160 | + public function getVisibilityType() { |
|
| 161 | + return BackendService::VISIBILITY_ADMIN; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + protected function isApplicable(StorageConfig $config) { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Get all configured admin and personal mounts |
|
| 170 | + * |
|
| 171 | + * @return StorageConfig[] map of storage id to storage config |
|
| 172 | + */ |
|
| 173 | + public function getStorageForAllUsers() { |
|
| 174 | + $mounts = $this->dbConfig->getAllMounts(); |
|
| 175 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 176 | + $configs = array_filter($configs, function ($config) { |
|
| 177 | + return $config instanceof StorageConfig; |
|
| 178 | + }); |
|
| 179 | + |
|
| 180 | + $keys = array_map(function (StorageConfig $config) { |
|
| 181 | + return $config->getId(); |
|
| 182 | + }, $configs); |
|
| 183 | + |
|
| 184 | + return array_combine($keys, $configs); |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -31,63 +31,63 @@ |
||
| 31 | 31 | use OCP\WorkflowEngine\IFileCheck; |
| 32 | 32 | |
| 33 | 33 | class FileName extends AbstractStringCheck implements IFileCheck { |
| 34 | - use TFileCheck; |
|
| 34 | + use TFileCheck; |
|
| 35 | 35 | |
| 36 | - /** @var IRequest */ |
|
| 37 | - protected $request; |
|
| 38 | - /** @var IMountManager */ |
|
| 39 | - private $mountManager; |
|
| 36 | + /** @var IRequest */ |
|
| 37 | + protected $request; |
|
| 38 | + /** @var IMountManager */ |
|
| 39 | + private $mountManager; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param IL10N $l |
|
| 43 | - * @param IRequest $request |
|
| 44 | - */ |
|
| 45 | - public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) { |
|
| 46 | - parent::__construct($l); |
|
| 47 | - $this->request = $request; |
|
| 48 | - $this->mountManager = $mountManager; |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * @param IL10N $l |
|
| 43 | + * @param IRequest $request |
|
| 44 | + */ |
|
| 45 | + public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) { |
|
| 46 | + parent::__construct($l); |
|
| 47 | + $this->request = $request; |
|
| 48 | + $this->mountManager = $mountManager; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - protected function getActualValue(): string { |
|
| 55 | - $fileName = $this->path === null ? '' : basename($this->path); |
|
| 56 | - if ($fileName === '' && (!$this->storage->isLocal() || $this->storage->instanceOfStorage(Local::class))) { |
|
| 57 | - // Return the mountpoint name of external storage that are not mounted as user home |
|
| 58 | - $mountPoints = $this->mountManager->findByStorageId($this->storage->getId()); |
|
| 59 | - if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') { |
|
| 60 | - return $fileName; |
|
| 61 | - } |
|
| 62 | - $mountPointPath = rtrim($mountPoints[0]->getMountPoint(), '/'); |
|
| 63 | - $mountPointPieces = explode('/', $mountPointPath); |
|
| 64 | - $mountPointName = array_pop($mountPointPieces); |
|
| 65 | - if (!empty($mountPointName) && $mountPointName !== 'files' && count($mountPointPieces) !== 2) { |
|
| 66 | - return $mountPointName; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - return $fileName; |
|
| 70 | - } |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + protected function getActualValue(): string { |
|
| 55 | + $fileName = $this->path === null ? '' : basename($this->path); |
|
| 56 | + if ($fileName === '' && (!$this->storage->isLocal() || $this->storage->instanceOfStorage(Local::class))) { |
|
| 57 | + // Return the mountpoint name of external storage that are not mounted as user home |
|
| 58 | + $mountPoints = $this->mountManager->findByStorageId($this->storage->getId()); |
|
| 59 | + if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') { |
|
| 60 | + return $fileName; |
|
| 61 | + } |
|
| 62 | + $mountPointPath = rtrim($mountPoints[0]->getMountPoint(), '/'); |
|
| 63 | + $mountPointPieces = explode('/', $mountPointPath); |
|
| 64 | + $mountPointName = array_pop($mountPointPieces); |
|
| 65 | + if (!empty($mountPointName) && $mountPointName !== 'files' && count($mountPointPieces) !== 2) { |
|
| 66 | + return $mountPointName; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + return $fileName; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param string $operator |
|
| 74 | - * @param string $checkValue |
|
| 75 | - * @param string $actualValue |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - protected function executeStringCheck($operator, $checkValue, $actualValue): bool { |
|
| 79 | - if ($operator === 'is' || $operator === '!is') { |
|
| 80 | - $checkValue = mb_strtolower($checkValue); |
|
| 81 | - $actualValue = mb_strtolower($actualValue); |
|
| 82 | - } |
|
| 83 | - return parent::executeStringCheck($operator, $checkValue, $actualValue); |
|
| 84 | - } |
|
| 72 | + /** |
|
| 73 | + * @param string $operator |
|
| 74 | + * @param string $checkValue |
|
| 75 | + * @param string $actualValue |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + protected function executeStringCheck($operator, $checkValue, $actualValue): bool { |
|
| 79 | + if ($operator === 'is' || $operator === '!is') { |
|
| 80 | + $checkValue = mb_strtolower($checkValue); |
|
| 81 | + $actualValue = mb_strtolower($actualValue); |
|
| 82 | + } |
|
| 83 | + return parent::executeStringCheck($operator, $checkValue, $actualValue); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function supportedEntities(): array { |
|
| 87 | - return [ File::class ]; |
|
| 88 | - } |
|
| 86 | + public function supportedEntities(): array { |
|
| 87 | + return [ File::class ]; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function isAvailableForScope(int $scope): bool { |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 90 | + public function isAvailableForScope(int $scope): bool { |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -30,53 +30,53 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Mount extends MountPoint implements MoveableMount { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var \OCA\Files_Sharing\External\Manager |
|
| 35 | - */ |
|
| 36 | - protected $manager; |
|
| 33 | + /** |
|
| 34 | + * @var \OCA\Files_Sharing\External\Manager |
|
| 35 | + */ |
|
| 36 | + protected $manager; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string|\OC\Files\Storage\Storage $storage |
|
| 40 | - * @param string $mountpoint |
|
| 41 | - * @param array $options |
|
| 42 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 43 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
| 44 | - */ |
|
| 45 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 46 | - parent::__construct($storage, $mountpoint, $options, $loader); |
|
| 47 | - $this->manager = $manager; |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * @param string|\OC\Files\Storage\Storage $storage |
|
| 40 | + * @param string $mountpoint |
|
| 41 | + * @param array $options |
|
| 42 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 43 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
| 44 | + */ |
|
| 45 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 46 | + parent::__construct($storage, $mountpoint, $options, $loader); |
|
| 47 | + $this->manager = $manager; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Move the mount point to $target |
|
| 52 | - * |
|
| 53 | - * @param string $target the target mount point |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function moveMount($target) { |
|
| 57 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 58 | - $this->setMountPoint($target); |
|
| 50 | + /** |
|
| 51 | + * Move the mount point to $target |
|
| 52 | + * |
|
| 53 | + * @param string $target the target mount point |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function moveMount($target) { |
|
| 57 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 58 | + $this->setMountPoint($target); |
|
| 59 | 59 | |
| 60 | - return $result; |
|
| 61 | - } |
|
| 60 | + return $result; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Remove the mount points |
|
| 65 | - * |
|
| 66 | - * @return mixed |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function removeMount() { |
|
| 70 | - return $this->manager->removeShare($this->mountPoint); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * Remove the mount points |
|
| 65 | + * |
|
| 66 | + * @return mixed |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function removeMount() { |
|
| 70 | + return $this->manager->removeShare($this->mountPoint); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 75 | - * in the web interface |
|
| 76 | - * |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function getMountType() { |
|
| 80 | - return 'shared'; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 75 | + * in the web interface |
|
| 76 | + * |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function getMountType() { |
|
| 80 | + return 'shared'; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -29,103 +29,103 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IMountPoint { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * get complete path to the mount point |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - * @since 8.0.0 |
|
| 37 | - */ |
|
| 38 | - public function getMountPoint(); |
|
| 32 | + /** |
|
| 33 | + * get complete path to the mount point |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + * @since 8.0.0 |
|
| 37 | + */ |
|
| 38 | + public function getMountPoint(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the mountpoint |
|
| 42 | - * |
|
| 43 | - * @param string $mountPoint new mount point |
|
| 44 | - * @since 8.0.0 |
|
| 45 | - */ |
|
| 46 | - public function setMountPoint($mountPoint); |
|
| 40 | + /** |
|
| 41 | + * Set the mountpoint |
|
| 42 | + * |
|
| 43 | + * @param string $mountPoint new mount point |
|
| 44 | + * @since 8.0.0 |
|
| 45 | + */ |
|
| 46 | + public function setMountPoint($mountPoint); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Get the storage that is mounted |
|
| 50 | - * |
|
| 51 | - * @return \OC\Files\Storage\Storage|null |
|
| 52 | - * @since 8.0.0 |
|
| 53 | - */ |
|
| 54 | - public function getStorage(); |
|
| 48 | + /** |
|
| 49 | + * Get the storage that is mounted |
|
| 50 | + * |
|
| 51 | + * @return \OC\Files\Storage\Storage|null |
|
| 52 | + * @since 8.0.0 |
|
| 53 | + */ |
|
| 54 | + public function getStorage(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the id of the storages |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - * @since 8.0.0 |
|
| 61 | - */ |
|
| 62 | - public function getStorageId(); |
|
| 56 | + /** |
|
| 57 | + * Get the id of the storages |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + * @since 8.0.0 |
|
| 61 | + */ |
|
| 62 | + public function getStorageId(); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Get the id of the storages |
|
| 66 | - * |
|
| 67 | - * @return int |
|
| 68 | - * @since 9.1.0 |
|
| 69 | - */ |
|
| 70 | - public function getNumericStorageId(); |
|
| 64 | + /** |
|
| 65 | + * Get the id of the storages |
|
| 66 | + * |
|
| 67 | + * @return int |
|
| 68 | + * @since 9.1.0 |
|
| 69 | + */ |
|
| 70 | + public function getNumericStorageId(); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get the path relative to the mountpoint |
|
| 74 | - * |
|
| 75 | - * @param string $path absolute path to a file or folder |
|
| 76 | - * @return string |
|
| 77 | - * @since 8.0.0 |
|
| 78 | - */ |
|
| 79 | - public function getInternalPath($path); |
|
| 72 | + /** |
|
| 73 | + * Get the path relative to the mountpoint |
|
| 74 | + * |
|
| 75 | + * @param string $path absolute path to a file or folder |
|
| 76 | + * @return string |
|
| 77 | + * @since 8.0.0 |
|
| 78 | + */ |
|
| 79 | + public function getInternalPath($path); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Apply a storage wrapper to the mounted storage |
|
| 83 | - * |
|
| 84 | - * @param callable $wrapper |
|
| 85 | - * @since 8.0.0 |
|
| 86 | - */ |
|
| 87 | - public function wrapStorage($wrapper); |
|
| 81 | + /** |
|
| 82 | + * Apply a storage wrapper to the mounted storage |
|
| 83 | + * |
|
| 84 | + * @param callable $wrapper |
|
| 85 | + * @since 8.0.0 |
|
| 86 | + */ |
|
| 87 | + public function wrapStorage($wrapper); |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get a mount option |
|
| 91 | - * |
|
| 92 | - * @param string $name Name of the mount option to get |
|
| 93 | - * @param mixed $default Default value for the mount option |
|
| 94 | - * @return mixed |
|
| 95 | - * @since 8.0.0 |
|
| 96 | - */ |
|
| 97 | - public function getOption($name, $default); |
|
| 89 | + /** |
|
| 90 | + * Get a mount option |
|
| 91 | + * |
|
| 92 | + * @param string $name Name of the mount option to get |
|
| 93 | + * @param mixed $default Default value for the mount option |
|
| 94 | + * @return mixed |
|
| 95 | + * @since 8.0.0 |
|
| 96 | + */ |
|
| 97 | + public function getOption($name, $default); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get all options for the mount |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - * @since 8.1.0 |
|
| 104 | - */ |
|
| 105 | - public function getOptions(); |
|
| 99 | + /** |
|
| 100 | + * Get all options for the mount |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + * @since 8.1.0 |
|
| 104 | + */ |
|
| 105 | + public function getOptions(); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Get the file id of the root of the storage |
|
| 109 | - * |
|
| 110 | - * @return int |
|
| 111 | - * @since 9.1.0 |
|
| 112 | - */ |
|
| 113 | - public function getStorageRootId(); |
|
| 107 | + /** |
|
| 108 | + * Get the file id of the root of the storage |
|
| 109 | + * |
|
| 110 | + * @return int |
|
| 111 | + * @since 9.1.0 |
|
| 112 | + */ |
|
| 113 | + public function getStorageRootId(); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Get the id of the configured mount |
|
| 117 | - * |
|
| 118 | - * @return int|null mount id or null if not applicable |
|
| 119 | - * @since 9.1.0 |
|
| 120 | - */ |
|
| 121 | - public function getMountId(); |
|
| 115 | + /** |
|
| 116 | + * Get the id of the configured mount |
|
| 117 | + * |
|
| 118 | + * @return int|null mount id or null if not applicable |
|
| 119 | + * @since 9.1.0 |
|
| 120 | + */ |
|
| 121 | + public function getMountId(); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 125 | - * in the web interface |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - * @since 12.0.0 |
|
| 129 | - */ |
|
| 130 | - public function getMountType(); |
|
| 123 | + /** |
|
| 124 | + * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 125 | + * in the web interface |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + * @since 12.0.0 |
|
| 129 | + */ |
|
| 130 | + public function getMountType(); |
|
| 131 | 131 | } |