mirror of
https://github.com/nextcloud/server.git
synced 2025-08-16 15:41:57 +00:00
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:

committed by
Borja Domínguez Vázquez

parent
f9cdb947fc
commit
cdeed5bcbe
@ -152,8 +152,10 @@ class FileEventsListener implements IEventListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
|
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.
|
// 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) {
|
} catch (DbalException $ex) {
|
||||||
// Ignore UniqueConstraintViolationException, as we are probably in the middle of a rollback
|
// 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.
|
// 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.
|
// So we simply update the associated version.
|
||||||
if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
|
if ($node instanceof File && $this->versionManager instanceof INeedSyncVersionBackend) {
|
||||||
|
$revision = $this->versionManager->getRevision($writeHookInfo['previousNode']);
|
||||||
|
|
||||||
$this->versionManager->updateVersionEntity(
|
$this->versionManager->updateVersionEntity(
|
||||||
$node,
|
$node,
|
||||||
$writeHookInfo['previousNode']->getMtime(),
|
$revision,
|
||||||
[
|
[
|
||||||
'timestamp' => $node->getMTime(),
|
'timestamp' => $node->getMTime(),
|
||||||
'size' => $node->getSize(),
|
'size' => $node->getSize(),
|
||||||
|
@ -48,8 +48,9 @@ class VersionAuthorListener implements IEventListener {
|
|||||||
}
|
}
|
||||||
// check if our version manager supports setting the metadata
|
// check if our version manager supports setting the metadata
|
||||||
if ($this->versionManager instanceof IMetadataVersionBackend) {
|
if ($this->versionManager instanceof IMetadataVersionBackend) {
|
||||||
|
$revision = $this->versionManager->getRevision($node);
|
||||||
$author = $user->getUID();
|
$author = $user->getUID();
|
||||||
$this->versionManager->setMetadataValue($node, $node->getMTime(), Plugin::AUTHOR, $author);
|
$this->versionManager->setMetadataValue($node, $revision, Plugin::AUTHOR, $author);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
namespace OCA\Files_Versions\Versions;
|
namespace OCA\Files_Versions\Versions;
|
||||||
|
|
||||||
|
use OC\Files\Node\Node;
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\FileInfo;
|
use OCP\Files\FileInfo;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
@ -78,4 +79,11 @@ interface IVersionBackend {
|
|||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
*/
|
*/
|
||||||
public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): File;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,10 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
|
|||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRevision(Node $node): int {
|
||||||
|
return $node->getMTime();
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteVersion(IVersion $version): void {
|
public function deleteVersion(IVersion $version): void {
|
||||||
if (!$this->currentUserHasPermissions($version->getSourceFile(), Constants::PERMISSION_DELETE)) {
|
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.');
|
throw new Forbidden('You cannot delete this version because you do not have delete permissions on the source file.');
|
||||||
|
@ -110,6 +110,11 @@ class VersionManager implements IVersionManager, IDeletableVersionBackend, INeed
|
|||||||
return $backend->getVersionFile($user, $sourceFile, $revision);
|
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 {
|
public function useBackendForStorage(IStorage $storage): bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user