diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-10-06 16:47:59 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-10-06 17:33:16 +0200 |
commit | bbebffb60cef91553a7d73d7059c1e9278b1c3cb (patch) | |
tree | 43316afc4c589e3fb3251bad7ca85e01ad3d0947 /apps/files_external/service | |
parent | 3413b766311c1936097d260544a5181695cd7822 (diff) | |
download | nextcloud-server-bbebffb60cef91553a7d73d7059c1e9278b1c3cb.tar.gz nextcloud-server-bbebffb60cef91553a7d73d7059c1e9278b1c3cb.zip |
Remove oc_storages entries after removing ext storages
When removing external storages, either system-wide or user-wide,
automatically remove the matching oc_storages and oc_filecache entries.
This can only work if the backend configuration doesn't contain any
substitution variable $user in which case the storage id cannot be
computed, so this case is ignored for now.
Diffstat (limited to 'apps/files_external/service')
-rw-r--r-- | apps/files_external/service/storagesservice.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php index d5260a066cd..41bb0ca9b80 100644 --- a/apps/files_external/service/storagesservice.php +++ b/apps/files_external/service/storagesservice.php @@ -550,6 +550,21 @@ abstract class StoragesService { $this->writeConfig($allStorages); $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); + + // delete oc_storages entries and oc_filecache + try { + $rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage); + \OC\Files\Cache\Storage::remove($rustyStorageId); + } catch (\Exception $e) { + // can happen either for invalid configs where the storage could not + // be instantiated or whenever $user vars where used, in which case + // the storage id could not be computed + \OCP\Util::writeLog( + 'files_external', + 'Exception: "' . $e->getMessage() . '"', + \OCP\Util::ERROR + ); + } } /** @@ -570,4 +585,30 @@ abstract class StoragesService { return (max(array_keys($allStorages)) + 1); } + /** + * Returns the rusty storage id from oc_storages from the given storage config. + * + * @param StorageConfig $storageConfig + * @return string rusty storage id + */ + private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) { + // if any of the storage options contains $user, it is not possible + // to compute the possible storage id as we don't know which users + // mounted it already (and we certainly don't want to iterate over ALL users) + foreach ($storageConfig->getBackendOptions() as $value) { + if (strpos($value, '$user') !== false) { + throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration'); + } + } + + // note: similar to ConfigAdapter->prepateStorageConfig() + $storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig); + $storageConfig->getBackend()->manipulateStorageConfig($storageConfig); + + $class = $storageConfig->getBackend()->getStorageClass(); + $storageImpl = new $class($storageConfig->getBackendOptions()); + + return $storageImpl->getId(); + } + } |