diff options
author | Louis Chemineau <louis@chmn.me> | 2023-06-21 09:51:36 +0200 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2023-06-21 09:56:20 +0200 |
commit | ecdcc72e4d85d51fe63cd3c5e499dce3a6bf03f7 (patch) | |
tree | d79a705a4a510bef8a3881ce0c44a5068d62914d /apps/files_versions | |
parent | e76c96be5c480dd730d8c9a7e7bf772517591779 (diff) | |
download | nextcloud-server-ecdcc72e4d85d51fe63cd3c5e499dce3a6bf03f7.tar.gz nextcloud-server-ecdcc72e4d85d51fe63cd3c5e499dce3a6bf03f7.zip |
Handle previousNode size === 0 on version creation
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/lib/Listener/FileEventsListener.php | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index 082c88295cb..69fb0f1fa54 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -226,31 +226,21 @@ class FileEventsListener implements IEventListener { return; } - if ($writeHookInfo['versionCreated'] && $node->getMTime() !== $writeHookInfo['previousNode']->getMTime()) { + if ( + ($writeHookInfo['versionCreated'] && $node->getMTime() !== $writeHookInfo['previousNode']->getMTime()) || + $writeHookInfo['previousNode']->getSize() === 0 + ) { // If a new version was created, insert a version in the DB for the current content. // Unless both versions have the same mtime. - $versionEntity = new VersionEntity(); - $versionEntity->setFileId($node->getId()); - $versionEntity->setTimestamp($node->getMTime()); - $versionEntity->setSize($node->getSize()); - $versionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype())); - $versionEntity->setMetadata([]); - $this->versionsMapper->insert($versionEntity); + $this->created($node); } else { // 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. - try { - $currentVersionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $writeHookInfo['previousNode']->getMtime()); - $currentVersionEntity->setTimestamp($node->getMTime()); - $currentVersionEntity->setSize($node->getSize()); - $currentVersionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype())); - $this->versionsMapper->update($currentVersionEntity); - } catch (DoesNotExistException) { - // There might be cases where the current version entry doesn't exist, - // e.g. if none was written due to an empty file or from before the versions table was introduced - // We just create the initial version entry then for the current entity - $this->created($node); - } + $currentVersionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $writeHookInfo['previousNode']->getMtime()); + $currentVersionEntity->setTimestamp($node->getMTime()); + $currentVersionEntity->setSize($node->getSize()); + $currentVersionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype())); + $this->versionsMapper->update($currentVersionEntity); } unset($this->writeHookInfo[$node->getId()]); |