diff options
author | Louis Chemineau <louis@chmn.me> | 2022-12-15 15:35:31 +0100 |
---|---|---|
committer | Louis (Rebase PR Action) <artonge@users.noreply.github.com> | 2023-01-26 10:12:23 +0000 |
commit | 88abb2d97c84211d4874aa02bf92580fbb1ae83e (patch) | |
tree | d5d5b04ee6a903bbd2ba45b2269a24b81df5fb34 /apps/files_versions/lib | |
parent | 3da63f4148898ec4bc9544a4a9ef07bac3e07669 (diff) | |
download | nextcloud-server-88abb2d97c84211d4874aa02bf92580fbb1ae83e.tar.gz nextcloud-server-88abb2d97c84211d4874aa02bf92580fbb1ae83e.zip |
Fix versions restoring with S3
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r-- | apps/files_versions/lib/Listener/FileEventsListener.php | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index 20b3881e953..76590733e26 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -30,6 +30,8 @@ */ namespace OCA\Files_Versions\Listener; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; +use OC\DB\Exceptions\DbalException; use OC\Files\Filesystem; use OC\Files\Mount\MoveableMount; use OC\Files\Node\NonExistingFile; @@ -37,6 +39,7 @@ use OC\Files\View; use OCA\Files_Versions\Db\VersionEntity; use OCA\Files_Versions\Db\VersionsMapper; use OCA\Files_Versions\Storage; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\BeforeNodeCopiedEvent; @@ -151,14 +154,30 @@ class FileEventsListener implements IEventListener { unset($this->nodesTouched[$node->getId()]); - // We update the timestamp of the version entity associated with the previousNode. - $versionEntity = $this->versionsMapper->findVersionForFileId($previousNode->getId(), $previousNode->getMTime()); - // Create a version in the DB for the current content. - $versionEntity->setTimestamp($node->getMTime()); - $this->versionsMapper->update($versionEntity); + try { + // We update the timestamp of the version entity associated with the previousNode. + $versionEntity = $this->versionsMapper->findVersionForFileId($previousNode->getId(), $previousNode->getMTime()); + // Create a version in the DB for the current content. + $versionEntity->setTimestamp($node->getMTime()); + $this->versionsMapper->update($versionEntity); + } catch (DbalException $ex) { + // Ignore UniqueConstraintViolationException, as we are probably in the middle of a rollback + // Where the previous node would temporary have the mtime of the old version, so the rollback touches it to fix it. + if (!($ex->getPrevious() instanceof UniqueConstraintViolationException)) { + throw $ex; + } + } catch (DoesNotExistException $ex) { + // Ignore DoesNotExistException, as we are probably in the middle of a rollback + // Where the previous node would temporary have a wrong mtime, so the rollback touches it to fix it. + } } public function created(Node $node): void { + // Do not handle folders. + if ($node instanceof Folder) { + return; + } + $versionEntity = new VersionEntity(); $versionEntity->setFileId($node->getId()); $versionEntity->setTimestamp($node->getMTime()); |