aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r--apps/files_versions/lib/AppInfo/Application.php1
-rw-r--r--apps/files_versions/lib/BackgroundJob/ExpireVersions.php1
-rw-r--r--apps/files_versions/lib/Capabilities.php1
-rw-r--r--apps/files_versions/lib/Command/CleanUp.php1
-rw-r--r--apps/files_versions/lib/Command/Expire.php1
-rw-r--r--apps/files_versions/lib/Command/ExpireVersions.php1
-rw-r--r--apps/files_versions/lib/Controller/PreviewController.php1
-rw-r--r--apps/files_versions/lib/Events/CreateVersionEvent.php1
-rw-r--r--apps/files_versions/lib/Expiration.php1
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php71
-rw-r--r--apps/files_versions/lib/Listener/VersionAuthorListener.php4
-rw-r--r--apps/files_versions/lib/Sabre/Plugin.php10
-rw-r--r--apps/files_versions/lib/Sabre/RootCollection.php1
-rw-r--r--apps/files_versions/lib/Sabre/VersionHome.php1
-rw-r--r--apps/files_versions/lib/Storage.php6
-rw-r--r--apps/files_versions/lib/Versions/BackendNotFoundException.php1
-rw-r--r--apps/files_versions/lib/Versions/IVersionBackend.php8
-rw-r--r--apps/files_versions/lib/Versions/LegacyVersionsBackend.php4
-rw-r--r--apps/files_versions/lib/Versions/VersionManager.php9
19 files changed, 113 insertions, 11 deletions
diff --git a/apps/files_versions/lib/AppInfo/Application.php b/apps/files_versions/lib/AppInfo/Application.php
index 1f35034d820..29158276415 100644
--- a/apps/files_versions/lib/AppInfo/Application.php
+++ b/apps/files_versions/lib/AppInfo/Application.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/BackgroundJob/ExpireVersions.php b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php
index 6de29364835..794cbc5b882 100644
--- a/apps/files_versions/lib/BackgroundJob/ExpireVersions.php
+++ b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/Capabilities.php b/apps/files_versions/lib/Capabilities.php
index 4919006bce3..cb6394f0a36 100644
--- a/apps/files_versions/lib/Capabilities.php
+++ b/apps/files_versions/lib/Capabilities.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/Command/CleanUp.php b/apps/files_versions/lib/Command/CleanUp.php
index 1cd3dccc4dd..e8c46afef16 100644
--- a/apps/files_versions/lib/Command/CleanUp.php
+++ b/apps/files_versions/lib/Command/CleanUp.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/Command/Expire.php b/apps/files_versions/lib/Command/Expire.php
index d1181087150..a30e623c347 100644
--- a/apps/files_versions/lib/Command/Expire.php
+++ b/apps/files_versions/lib/Command/Expire.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/Command/ExpireVersions.php b/apps/files_versions/lib/Command/ExpireVersions.php
index fd0118549c6..d3f341a21d2 100644
--- a/apps/files_versions/lib/Command/ExpireVersions.php
+++ b/apps/files_versions/lib/Command/ExpireVersions.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
diff --git a/apps/files_versions/lib/Controller/PreviewController.php b/apps/files_versions/lib/Controller/PreviewController.php
index be62c5eb957..2c3ff8da70d 100644
--- a/apps/files_versions/lib/Controller/PreviewController.php
+++ b/apps/files_versions/lib/Controller/PreviewController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_versions/lib/Events/CreateVersionEvent.php b/apps/files_versions/lib/Events/CreateVersionEvent.php
index 1399cdbb988..92ed26b2dd6 100644
--- a/apps/files_versions/lib/Events/CreateVersionEvent.php
+++ b/apps/files_versions/lib/Events/CreateVersionEvent.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_versions/lib/Expiration.php b/apps/files_versions/lib/Expiration.php
index 5ef749ad115..1e04d93379f 100644
--- a/apps/files_versions/lib/Expiration.php
+++ b/apps/files_versions/lib/Expiration.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 4b7385d6e2d..969ca4ded45 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -12,6 +12,7 @@ use OC\DB\Exceptions\DbalException;
use OC\Files\Filesystem;
use OC\Files\Mount\MoveableMount;
use OC\Files\Node\NonExistingFile;
+use OC\Files\Node\NonExistingFolder;
use OC\Files\View;
use OCA\Files_Versions\Storage;
use OCA\Files_Versions\Versions\INeedSyncVersionBackend;
@@ -125,6 +126,22 @@ class FileEventsListener implements IEventListener {
}
public function touch_hook(Node $node): void {
+ // Do not handle folders.
+ if ($node instanceof Folder) {
+ return;
+ }
+
+ if ($node instanceof NonExistingFile) {
+ $this->logger->error(
+ 'Failed to create or update version for {path}, node does not exist',
+ [
+ 'path' => $node->getPath(),
+ ]
+ );
+
+ return;
+ }
+
$previousNode = $this->nodesTouched[$node->getId()] ?? null;
if ($previousNode === null) {
@@ -135,8 +152,10 @@ class FileEventsListener implements IEventListener {
try {
if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
+ $revision = $this->versionManager->getRevision($previousNode);
+
// We update the timestamp of the version entity associated with the previousNode.
- $this->versionManager->updateVersionEntity($node, $previousNode->getMTime(), ['timestamp' => $node->getMTime()]);
+ $this->versionManager->updateVersionEntity($node, $revision, ['timestamp' => $node->getMTime()]);
}
} catch (DbalException $ex) {
// Ignore UniqueConstraintViolationException, as we are probably in the middle of a rollback
@@ -152,7 +171,22 @@ class FileEventsListener implements IEventListener {
public function created(Node $node): void {
// Do not handle folders.
- if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
+ if (!($node instanceof File)) {
+ return;
+ }
+
+ if ($node instanceof NonExistingFile) {
+ $this->logger->error(
+ 'Failed to create version for {path}, node does not exist',
+ [
+ 'path' => $node->getPath(),
+ ]
+ );
+
+ return;
+ }
+
+ if ($this->versionManager instanceof INeedSyncVersionBackend) {
$this->versionManager->createVersionEntity($node);
}
}
@@ -190,6 +224,17 @@ class FileEventsListener implements IEventListener {
return;
}
+ if ($node instanceof NonExistingFile) {
+ $this->logger->error(
+ 'Failed to create or update version for {path}, node does not exist',
+ [
+ 'path' => $node->getPath(),
+ ]
+ );
+
+ return;
+ }
+
$writeHookInfo = $this->writeHookInfo[$node->getId()] ?? null;
if ($writeHookInfo === null) {
@@ -209,9 +254,11 @@ class FileEventsListener implements IEventListener {
// If no new version was stored in the FS, no new version should be added in the DB.
// So we simply update the associated version.
if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
+ $revision = $this->versionManager->getRevision($writeHookInfo['previousNode']);
+
$this->versionManager->updateVersionEntity(
$node,
- $writeHookInfo['previousNode']->getMtime(),
+ $revision,
[
'timestamp' => $node->getMTime(),
'size' => $node->getSize(),
@@ -402,6 +449,24 @@ class FileEventsListener implements IEventListener {
}
}
+ if (!($node instanceof NonExistingFile) && !($node instanceof NonExistingFolder)) {
+ $this->logger->debug('Failed to compute path for node', [
+ 'node' => [
+ 'path' => $node->getPath(),
+ 'owner' => $owner,
+ 'fileid' => $node->getId(),
+ 'size' => $node->getSize(),
+ 'mtime' => $node->getMTime(),
+ ]
+ ]);
+ } else {
+ $this->logger->debug('Failed to compute path for node', [
+ 'node' => [
+ 'path' => $node->getPath(),
+ 'owner' => $owner,
+ ]
+ ]);
+ }
return null;
}
}
diff --git a/apps/files_versions/lib/Listener/VersionAuthorListener.php b/apps/files_versions/lib/Listener/VersionAuthorListener.php
index 6f4e6c0ee57..9b93b1f888b 100644
--- a/apps/files_versions/lib/Listener/VersionAuthorListener.php
+++ b/apps/files_versions/lib/Listener/VersionAuthorListener.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace OCA\Files_Versions\Listener;
use OC\Files\Node\Folder;
+use OCA\Files_Versions\Sabre\Plugin;
use OCA\Files_Versions\Versions\IMetadataVersionBackend;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\EventDispatcher\Event;
@@ -47,8 +48,9 @@ class VersionAuthorListener implements IEventListener {
}
// check if our version manager supports setting the metadata
if ($this->versionManager instanceof IMetadataVersionBackend) {
+ $revision = $this->versionManager->getRevision($node);
$author = $user->getUID();
- $this->versionManager->setMetadataValue($node, $node->getMTime(), 'author', $author);
+ $this->versionManager->setMetadataValue($node, $revision, Plugin::AUTHOR, $author);
}
}
}
diff --git a/apps/files_versions/lib/Sabre/Plugin.php b/apps/files_versions/lib/Sabre/Plugin.php
index 10a1896773d..4b4cb0638bf 100644
--- a/apps/files_versions/lib/Sabre/Plugin.php
+++ b/apps/files_versions/lib/Sabre/Plugin.php
@@ -24,6 +24,10 @@ use Sabre\HTTP\ResponseInterface;
class Plugin extends ServerPlugin {
private Server $server;
+ public const LABEL = 'label';
+
+ public const AUTHOR = 'author';
+
public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label';
public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author
@@ -76,8 +80,8 @@ class Plugin extends ServerPlugin {
public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof VersionFile) {
- $propFind->handle(self::VERSION_LABEL, fn () => $node->getMetadataValue('label'));
- $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataValue('author'));
+ $propFind->handle(self::VERSION_LABEL, fn () => $node->getMetadataValue(self::LABEL));
+ $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataValue(self::AUTHOR));
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
}
}
@@ -86,7 +90,7 @@ class Plugin extends ServerPlugin {
$node = $this->server->tree->getNodeForPath($path);
if ($node instanceof VersionFile) {
- $propPatch->handle(self::VERSION_LABEL, fn (string $label) => $node->setMetadataValue('label', $label));
+ $propPatch->handle(self::VERSION_LABEL, fn (string $label) => $node->setMetadataValue(self::LABEL, $label));
}
}
}
diff --git a/apps/files_versions/lib/Sabre/RootCollection.php b/apps/files_versions/lib/Sabre/RootCollection.php
index ded4f3dda7b..1e7129f23da 100644
--- a/apps/files_versions/lib/Sabre/RootCollection.php
+++ b/apps/files_versions/lib/Sabre/RootCollection.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_versions/lib/Sabre/VersionHome.php b/apps/files_versions/lib/Sabre/VersionHome.php
index 7f182958d94..07ac491f2a1 100644
--- a/apps/files_versions/lib/Sabre/VersionHome.php
+++ b/apps/files_versions/lib/Sabre/VersionHome.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 0fb3a0522f4..6d53a19a518 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
namespace OCA\Files_Versions;
use OC\Files\Filesystem;
+use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
@@ -418,8 +420,8 @@ class Storage {
try {
// TODO add a proper way of overwriting a file while maintaining file ids
- if ($storage1->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class)
- || $storage2->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class)
+ if ($storage1->instanceOfStorage(ObjectStoreStorage::class)
+ || $storage2->instanceOfStorage(ObjectStoreStorage::class)
) {
$source = $storage1->fopen($internalPath1, 'r');
$result = $source !== false;
diff --git a/apps/files_versions/lib/Versions/BackendNotFoundException.php b/apps/files_versions/lib/Versions/BackendNotFoundException.php
index af903e9abeb..f1fbecb852a 100644
--- a/apps/files_versions/lib/Versions/BackendNotFoundException.php
+++ b/apps/files_versions/lib/Versions/BackendNotFoundException.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_versions/lib/Versions/IVersionBackend.php b/apps/files_versions/lib/Versions/IVersionBackend.php
index 28e3f4dffcf..18f8c17f0ac 100644
--- a/apps/files_versions/lib/Versions/IVersionBackend.php
+++ b/apps/files_versions/lib/Versions/IVersionBackend.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
*/
namespace OCA\Files_Versions\Versions;
+use OC\Files\Node\Node;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
@@ -78,4 +79,11 @@ interface IVersionBackend {
* @since 15.0.0
*/
public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): File;
+
+ /**
+ * Get the revision for a node
+ *
+ * @since 32.0.0
+ */
+ public function getRevision(Node $node): int;
}
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
index 59a10a0775d..40180674b7c 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -212,6 +212,10 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
return $file;
}
+ public function getRevision(Node $node): int {
+ return $node->getMTime();
+ }
+
public function deleteVersion(IVersion $version): void {
if (!$this->currentUserHasPermissions($version->getSourceFile(), Constants::PERMISSION_DELETE)) {
throw new Forbidden('You cannot delete this version because you do not have delete permissions on the source file.');
diff --git a/apps/files_versions/lib/Versions/VersionManager.php b/apps/files_versions/lib/Versions/VersionManager.php
index eb53f04d388..f72e451f368 100644
--- a/apps/files_versions/lib/Versions/VersionManager.php
+++ b/apps/files_versions/lib/Versions/VersionManager.php
@@ -60,8 +60,8 @@ class VersionManager implements IVersionManager, IDeletableVersionBackend, INeed
foreach ($backends as $type => $backendsForType) {
if (
- $storage->instanceOfStorage($type) &&
- ($foundType === '' || is_subclass_of($type, $foundType))
+ $storage->instanceOfStorage($type)
+ && ($foundType === '' || is_subclass_of($type, $foundType))
) {
foreach ($backendsForType as $backend) {
/** @var IVersionBackend $backend */
@@ -110,6 +110,11 @@ class VersionManager implements IVersionManager, IDeletableVersionBackend, INeed
return $backend->getVersionFile($user, $sourceFile, $revision);
}
+ public function getRevision(Node $node): int {
+ $backend = $this->getBackendForStorage($node->getStorage());
+ return $backend->getRevision($node);
+ }
+
public function useBackendForStorage(IStorage $storage): bool {
return false;
}