From a999420c7561791a30ac05ac389876f45aa6c11b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 9 Aug 2016 15:52:13 +0200 Subject: [PATCH] get shared storage storage id without setting up the storage --- apps/files_sharing/lib/SharedMount.php | 13 +++++++++++++ lib/private/Files/Config/LazyStorageMountInfo.php | 6 +----- lib/private/Files/Mount/MountPoint.php | 7 +++++++ lib/public/Files/Mount/IMountPoint.php | 8 ++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 57610db907..d160eb2422 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -235,4 +235,17 @@ class SharedMount extends MountPoint implements MoveableMount { public function getStorageRootId() { return $this->getShare()->getNodeId(); } + + /** + * @return int + */ + public function getNumericStorageId() { + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + + $query = $builder->select('storage') + ->from('filecache') + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getShare()->getNodeId()))); + + return $query->execute()->fetchColumn(); + } } diff --git a/lib/private/Files/Config/LazyStorageMountInfo.php b/lib/private/Files/Config/LazyStorageMountInfo.php index 2e9639f5f0..4df813d57d 100644 --- a/lib/private/Files/Config/LazyStorageMountInfo.php +++ b/lib/private/Files/Config/LazyStorageMountInfo.php @@ -48,11 +48,7 @@ class LazyStorageMountInfo extends CachedMountInfo { */ public function getStorageId() { if (!$this->storageId) { - $storage = $this->mount->getStorage(); - if (!$storage) { - return -1; - } - $this->storageId = $storage->getStorageCache()->getNumericId(); + $this->storageId = $this->mount->getNumericStorageId(); } return parent::getStorageId(); } diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index d6a6a5565a..8b8f0574ae 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -191,6 +191,13 @@ class MountPoint implements IMountPoint { return $this->storageId; } + /** + * @return int + */ + public function getNumericStorageId() { + return $this->getStorage()->getStorageCache()->getNumericId(); + } + /** * @param string $path * @return string diff --git a/lib/public/Files/Mount/IMountPoint.php b/lib/public/Files/Mount/IMountPoint.php index f9a00af7cb..0876d8b11d 100644 --- a/lib/public/Files/Mount/IMountPoint.php +++ b/lib/public/Files/Mount/IMountPoint.php @@ -61,6 +61,14 @@ interface IMountPoint { */ public function getStorageId(); + /** + * Get the id of the storages + * + * @return int + * @since 9.1.0 + */ + public function getNumericStorageId(); + /** * Get the path relative to the mountpoint *