chore: get revision for a node

Signed-off-by: Borja Domínguez Vázquez <borja.dominguez@hotmail.com>
Signed-off-by: Borja Domínguez Vázquez <iam.n3uro@gmail.com>

wip

Signed-off-by: Borja Domínguez Vázquez <borja.dominguez@hotmail.com>
Signed-off-by: Borja Domínguez Vázquez <iam.n3uro@gmail.com>

wip

Signed-off-by: Borja Domínguez Vázquez <borja.dominguez@hotmail.com>
Signed-off-by: Borja Domínguez Vázquez <iam.n3uro@gmail.com>

Update IVersionBackend.php

Signed-off-by: Borja Domínguez Vázquez <iam.n3uro@gmail.com>

wip
This commit is contained in:
Borja Domínguez Vázquez
2025-07-05 22:28:49 +02:00
committed by Borja Domínguez Vázquez
parent f9cdb947fc
commit cdeed5bcbe
5 changed files with 25 additions and 3 deletions

View File

@ -152,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
@ -252,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(),

View File

@ -48,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(), Plugin::AUTHOR, $author);
$this->versionManager->setMetadataValue($node, $revision, Plugin::AUTHOR, $author);
}
}
}

View File

@ -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;
}

View File

@ -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.');

View File

@ -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;
}