aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib/Sabre/VersionFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib/Sabre/VersionFile.php')
-rw-r--r--apps/files_versions/lib/Sabre/VersionFile.php63
1 files changed, 24 insertions, 39 deletions
diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php
index 8fd97b0636f..faa03473648 100644
--- a/apps/files_versions/lib/Sabre/VersionFile.php
+++ b/apps/files_versions/lib/Sabre/VersionFile.php
@@ -3,30 +3,14 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
use OCA\Files_Versions\Versions\IDeletableVersionBackend;
+use OCA\Files_Versions\Versions\IMetadataVersion;
+use OCA\Files_Versions\Versions\IMetadataVersionBackend;
use OCA\Files_Versions\Versions\INameableVersion;
use OCA\Files_Versions\Versions\INameableVersionBackend;
use OCA\Files_Versions\Versions\IVersion;
@@ -37,15 +21,10 @@ use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile;
class VersionFile implements IFile {
- /** @var IVersion */
- private $version;
-
- /** @var IVersionManager */
- private $versionManager;
-
- public function __construct(IVersion $version, IVersionManager $versionManager) {
- $this->version = $version;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private IVersion $version,
+ private IVersionManager $versionManager,
+ ) {
}
public function put($data) {
@@ -92,23 +71,29 @@ class VersionFile implements IFile {
throw new Forbidden();
}
- public function getLabel(): ?string {
- if ($this->version instanceof INameableVersion && $this->version->getSourceFile()->getSize() > 0) {
- return $this->version->getLabel();
- } else {
- return null;
- }
- }
+ public function setMetadataValue(string $key, string $value): bool {
+ $backend = $this->version->getBackend();
- public function setLabel($label): bool {
- if ($this->versionManager instanceof INameableVersionBackend) {
- $this->versionManager->setVersionLabel($this->version, $label);
+ if ($backend instanceof IMetadataVersionBackend) {
+ $backend->setMetadataValue($this->version->getSourceFile(), $this->version->getTimestamp(), $key, $value);
+ return true;
+ } elseif ($key === 'label' && $backend instanceof INameableVersionBackend) {
+ $backend->setVersionLabel($this->version, $value);
return true;
} else {
return false;
}
}
+ public function getMetadataValue(string $key): ?string {
+ if ($this->version instanceof IMetadataVersion) {
+ return $this->version->getMetadataValue($key);
+ } elseif ($key === 'label' && $this->version instanceof INameableVersion) {
+ return $this->version->getLabel();
+ }
+ return null;
+ }
+
public function getLastModified(): int {
return $this->version->getTimestamp();
}