aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-06-21 10:35:12 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2023-07-12 19:55:30 +0200
commite1445f39eb1d8ae187077219b2248d89144ef81d (patch)
tree4d33050b9145ce368551b27df24ec8d84f253cc8
parent695565fb83de83e3e972f313ff02ad01c398da9c (diff)
downloadnextcloud-server-e1445f39eb1d8ae187077219b2248d89144ef81d.tar.gz
nextcloud-server-e1445f39eb1d8ae187077219b2248d89144ef81d.zip
fix: Add logging statement for cases when updating the version fails
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php37
1 files changed, 29 insertions, 8 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 69fb0f1fa54..1777342feab 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -40,6 +40,7 @@ use OCA\Files_Versions\Db\VersionEntity;
use OCA\Files_Versions\Db\VersionsMapper;
use OCA\Files_Versions\Storage;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\DB\Exception;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
@@ -57,6 +58,7 @@ use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use Psr\Log\LoggerInterface;
class FileEventsListener implements IEventListener {
private IRootFolder $rootFolder;
@@ -74,15 +76,18 @@ class FileEventsListener implements IEventListener {
*/
private array $versionsDeleted = [];
private IMimeTypeLoader $mimeTypeLoader;
+ private LoggerInterface $logger;
public function __construct(
IRootFolder $rootFolder,
VersionsMapper $versionsMapper,
- IMimeTypeLoader $mimeTypeLoader
+ IMimeTypeLoader $mimeTypeLoader,
+ LoggerInterface $logger,
) {
$this->rootFolder = $rootFolder;
$this->versionsMapper = $versionsMapper;
$this->mimeTypeLoader = $mimeTypeLoader;
+ $this->logger = $logger;
}
public function handle(Event $event): void {
@@ -234,13 +239,29 @@ class FileEventsListener implements IEventListener {
// Unless both versions have the same mtime.
$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.
- $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);
+ try {
+ // 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.
+ $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 (Exception $e) {
+ $this->logger->error('Failed to update existing version for ' . $node->getPath(), [
+ 'exception' => $e,
+ 'versionCreated' => $writeHookInfo['versionCreated'],
+ 'previousNode' => [
+ 'size' => $writeHookInfo['previousNode']->getSize(),
+ 'mtime' => $writeHookInfo['previousNode']->getMTime(),
+ ],
+ 'node' => [
+ 'size' => $node->getSize(),
+ 'mtime' => $node->getMTime(),
+ ]
+ ]);
+ throw $e;
+ }
}
unset($this->writeHookInfo[$node->getId()]);