From 4c618c4bf14bce6120acd1d05d29772a7746784a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 19 Oct 2023 15:31:44 +0200 Subject: [PATCH 1/3] fix(objectstorage): cleanup HomeObjectStoreStorage Fix invalid signature for getUser() method and change occurences of OC\User\User for OCP\IUser Signed-off-by: Thomas Citharel --- .../Files/ObjectStore/HomeObjectStoreStorage.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php index b361249ff4771..b2d0bc3d478db 100644 --- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php @@ -25,16 +25,16 @@ */ namespace OC\Files\ObjectStore; -use OC\User\User; +use OCP\Files\IHomeStorage; use OCP\IUser; -class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { +class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage { /** * The home user storage requires a user object to create a unique storage id * @param array $params */ public function __construct($params) { - if (! isset($params['user']) || ! $params['user'] instanceof User) { + if (! isset($params['user']) || ! $params['user'] instanceof IUser) { throw new \Exception('missing user object in parameters'); } $this->user = $params['user']; @@ -58,11 +58,7 @@ public function getOwner($path) { return false; } - /** - * @param string $path, optional - * @return \OC\User\User - */ - public function getUser($path = null): IUser { + public function getUser(): IUser { return $this->user; } } From 3be3dbdb3b4d707332a1c7edc1db378bc8e90375 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 20 Oct 2023 09:09:50 +0200 Subject: [PATCH 2/3] refactor(objectstorage): move $user property from ObjectStoreStorage class to HomeObjectStoreStorage Signed-off-by: Thomas Citharel --- .../ObjectStore/HomeObjectStoreStorage.php | 3 +++ .../Files/ObjectStore/ObjectStoreStorage.php | 17 +++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php index b2d0bc3d478db..feceb706e19df 100644 --- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php @@ -7,6 +7,7 @@ * @author Jörn Friedrich Dreyer * @author Morris Jobke * @author Roeland Jago Douma + * @author Thomas Citharel * * @license AGPL-3.0 * @@ -29,6 +30,8 @@ use OCP\IUser; class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage { + protected IUser $user; + /** * The home user storage requires a user object to create a unique storage id * @param array $params diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index eb8aaffe1e03e..5c2881bef0f41 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -51,20 +51,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite { use CopyDirectory; - /** - * @var \OCP\Files\ObjectStore\IObjectStore $objectStore - */ - protected $objectStore; - /** - * @var string $id - */ - protected $id; - /** - * @var \OC\User\User $user - */ - protected $user; - - private $objectPrefix = 'urn:oid:'; + protected IObjectStore $objectStore; + protected string $id; + private string $objectPrefix = 'urn:oid:'; private $logger; From 30798eb6c238a0090fd42d2b44644f4fc24d8c8d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 20 Oct 2023 09:08:08 +0200 Subject: [PATCH 3/3] refactor(objectstorage): cleanup types Signed-off-by: Thomas Citharel --- .../AppdataPreviewObjectStoreStorage.php | 9 ++++++--- .../Files/ObjectStore/HomeObjectStoreStorage.php | 16 ++++++++-------- .../Files/ObjectStore/ObjectStoreStorage.php | 11 +++++++---- .../ObjectStore/ObjectStoreStorageOverwrite.php | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php b/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php index 2f6db935236af..2c473cb6da95b 100644 --- a/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php @@ -26,9 +26,12 @@ namespace OC\Files\ObjectStore; class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage { - /** @var string */ - private $internalId; + private string $internalId; + /** + * @param array $params + * @throws \Exception + */ public function __construct($params) { if (!isset($params['internal-id'])) { throw new \Exception('missing id in parameters'); @@ -37,7 +40,7 @@ public function __construct($params) { parent::__construct($params); } - public function getId() { + public function getId(): string { return 'object::appdata::preview:' . $this->internalId; } } diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php index feceb706e19df..443c5147742c8 100644 --- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php @@ -26,6 +26,7 @@ */ namespace OC\Files\ObjectStore; +use Exception; use OCP\Files\IHomeStorage; use OCP\IUser; @@ -34,17 +35,19 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage /** * The home user storage requires a user object to create a unique storage id + * * @param array $params + * @throws Exception */ public function __construct($params) { if (! isset($params['user']) || ! $params['user'] instanceof IUser) { - throw new \Exception('missing user object in parameters'); + throw new Exception('missing user object in parameters'); } $this->user = $params['user']; parent::__construct($params); } - public function getId() { + public function getId(): string { return 'object::user:' . $this->user->getUID(); } @@ -52,13 +55,10 @@ public function getId() { * get the owner of a path * * @param string $path The path to get the owner - * @return false|string uid + * @return string uid */ - public function getOwner($path) { - if (is_object($this->user)) { - return $this->user->getUID(); - } - return false; + public function getOwner($path): string { + return $this->user->getUID(); } public function getUser(): IUser { diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 5c2881bef0f41..3e0fbd1591956 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -47,6 +47,7 @@ use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload; use OCP\Files\Storage\IChunkedFileWrite; use OCP\Files\Storage\IStorage; +use OCP\ILogger; class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite { use CopyDirectory; @@ -55,13 +56,15 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil protected string $id; private string $objectPrefix = 'urn:oid:'; - private $logger; + private ILogger $logger; private bool $handleCopiesAsOwned; + protected bool $validateWrites = true; - /** @var bool */ - protected $validateWrites = true; - + /** + * @param array $params + * @throws \Exception + */ public function __construct($params) { if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) { $this->objectStore = $params['objectstore']; diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php index b85f6289c9485..9c3981315359b 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php @@ -30,7 +30,7 @@ * Allow overwriting the object store instance for test purposes */ class ObjectStoreStorageOverwrite extends ObjectStoreStorage { - public function setObjectStore(IObjectStore $objectStore) { + public function setObjectStore(IObjectStore $objectStore): void { $this->objectStore = $objectStore; } @@ -38,7 +38,7 @@ public function getObjectStore(): IObjectStore { return $this->objectStore; } - public function setValidateWrites(bool $validate) { + public function setValidateWrites(bool $validate): void { $this->validateWrites = $validate; } }