aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/FilesMetadata/Model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/FilesMetadata/Model')
-rw-r--r--lib/private/FilesMetadata/Model/FilesMetadata.php59
-rw-r--r--lib/private/FilesMetadata/Model/MetadataValueWrapper.php61
2 files changed, 72 insertions, 48 deletions
diff --git a/lib/private/FilesMetadata/Model/FilesMetadata.php b/lib/private/FilesMetadata/Model/FilesMetadata.php
index 629b537dabe..b66e1fe3711 100644
--- a/lib/private/FilesMetadata/Model/FilesMetadata.php
+++ b/lib/private/FilesMetadata/Model/FilesMetadata.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
- *
- * @author Maxence Lange <maxence@artificial-owl.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\FilesMetadata\Model;
@@ -44,9 +27,10 @@ class FilesMetadata implements IFilesMetadata {
private bool $updated = false;
private int $lastUpdate = 0;
private string $syncToken = '';
+ private ?int $storageId = null;
public function __construct(
- private int $fileId = 0
+ private int $fileId = 0,
) {
}
@@ -59,6 +43,22 @@ class FilesMetadata implements IFilesMetadata {
return $this->fileId;
}
+ public function getStorageId(): ?int {
+ return $this->storageId;
+ }
+
+ /**
+ * Set which storage the file this metadata belongs to.
+ *
+ * This helps with sharded filecache setups to know where to store the metadata
+ *
+ * @param int $storageId
+ * @return void
+ */
+ public function setStorageId(int $storageId): void {
+ $this->storageId = $storageId;
+ }
+
/**
* @inheritDoc
* @return int timestamp
@@ -156,6 +156,23 @@ class FilesMetadata implements IFilesMetadata {
$this->metadata[$key]->setEditPermission($permission);
}
+
+ public function getEtag(string $key): string {
+ if (!array_key_exists($key, $this->metadata)) {
+ return '';
+ }
+
+ return $this->metadata[$key]->getEtag();
+ }
+
+ public function setEtag(string $key, string $etag): void {
+ if (!array_key_exists($key, $this->metadata)) {
+ throw new FilesMetadataNotFoundException();
+ }
+
+ $this->metadata[$key]->setEtag($etag);
+ }
+
/**
* @param string $key metadata key
*
@@ -480,7 +497,7 @@ class FilesMetadata implements IFilesMetadata {
// if value does not exist, or type has changed, we keep on the writing
}
- $valueWrapper = new MetadataValueWrapper(IMetadataValueWrapper::TYPE_STRING_LIST);
+ $valueWrapper = new MetadataValueWrapper(IMetadataValueWrapper::TYPE_INT_LIST);
$this->metadata[$key] = $valueWrapper->setValueIntList($value)->setIndexed($index);
$this->updated = true;
diff --git a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php
index 90f1554180d..710a8129340 100644
--- a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php
+++ b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
- *
- * @author Maxence Lange <maxence@artificial-owl.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\FilesMetadata\Model;
@@ -38,6 +21,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
private string $type;
/** @var string|int|float|bool|array|string[]|int[] */
private mixed $value = null;
+ private string $etag = '';
private bool $indexed = false;
private int $editPermission = self::EDIT_FORBIDDEN;
@@ -233,7 +217,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueString(): string {
$this->assertType(self::TYPE_STRING);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -249,7 +233,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueInt(): int {
$this->assertType(self::TYPE_INT);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -265,7 +249,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueFloat(): float {
$this->assertType(self::TYPE_FLOAT);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -281,7 +265,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueBool(): bool {
$this->assertType(self::TYPE_BOOL);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -297,7 +281,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueArray(): array {
$this->assertType(self::TYPE_ARRAY);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -313,7 +297,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueStringList(): array {
$this->assertType(self::TYPE_STRING_LIST);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -329,7 +313,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
*/
public function getValueIntList(): array {
$this->assertType(self::TYPE_INT_LIST);
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -343,7 +327,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
* @since 28.0.0
*/
public function getValueAny(): mixed {
- if (null === $this->value) {
+ if ($this->value === null) {
throw new FilesMetadataNotFoundException('value is not set');
}
@@ -351,6 +335,27 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
}
/**
+ * @inheritDoc
+ * @return string stored etag
+ * @since 29.0.0
+ */
+ public function getEtag(): string {
+ return $this->etag;
+ }
+
+ /**
+ * @param string $etag etag value
+ *
+ * @inheritDoc
+ * @return self
+ * @since 29.0.0
+ */
+ public function setEtag(string $etag): self {
+ $this->etag = $etag;
+ return $this;
+ }
+
+ /**
* @param bool $indexed TRUE to set the stored value as an indexed value
*
* @inheritDoc
@@ -405,6 +410,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
public function import(array $data): self {
$this->value = $data['value'] ?? null;
$this->type = $data['type'] ?? '';
+ $this->setEtag($data['etag'] ?? '');
$this->setIndexed($data['indexed'] ?? false);
$this->setEditPermission($data['editPermission'] ?? self::EDIT_FORBIDDEN);
return $this;
@@ -414,6 +420,7 @@ class MetadataValueWrapper implements IMetadataValueWrapper {
return [
'value' => ($emptyValues) ? null : $this->value,
'type' => $this->getType(),
+ 'etag' => $this->getEtag(),
'indexed' => $this->isIndexed(),
'editPermission' => $this->getEditPermission()
];