Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ public function touch_hook(Node $node): void {

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
Expand Down Expand Up @@ -252,9 +254,11 @@ public function post_write_hook(Node $node): void {
// 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public function post_write_hook(Node $node): void {
}
// 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(), Plugin::AUTHOR, $author);
$this->versionManager->setMetadataValue($node, $revision, Plugin::AUTHOR, $author);
}
}
}
8 changes: 8 additions & 0 deletions apps/files_versions/lib/Versions/IVersionBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\Files_Versions\Versions;

use OC\Files\Node\Node;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -78,4 +79,11 @@ public function read(IVersion $version);
* @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;
}
4 changes: 4 additions & 0 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi
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.');
Expand Down
5 changes: 5 additions & 0 deletions apps/files_versions/lib/Versions/VersionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi
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;
}
Expand Down
Loading