From e2f2244aaef2291c5b88b2dda61228f4c6347ca2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 17 Jun 2024 16:15:16 +0200 Subject: [PATCH] fix(cron): Cleanup old documents folders that got renamed during reset Signed-off-by: Jonas --- lib/Cron/Cleanup.php | 3 +++ lib/Service/DocumentService.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Cron/Cleanup.php b/lib/Cron/Cleanup.php index b77172260b9..e28b3ff4d8f 100644 --- a/lib/Cron/Cleanup.php +++ b/lib/Cron/Cleanup.php @@ -55,5 +55,8 @@ protected function run($argument): void { $this->logger->debug('Run cleanup job for text sessions'); $removedSessions = $this->sessionService->removeInactiveSessionsWithoutSteps(null); $this->logger->debug('Removed ' . $removedSessions . ' inactive sessions'); + + $this->logger->debug('Run cleanup job for obsolete documents folders'); + $this->documentService->cleanupOldDocumentsFolders(); } } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 2f4dcaaedcf..eaf8b4255b0 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -661,4 +661,19 @@ public function clearAll(): void { } $this->ensureDocumentsFolder(); } + + public function cleanupOldDocumentsFolders(): void { + try { + $appFolder = $this->rootFolder->get('appdata_' . $this->config->getSystemValueString('instanceid', '') . '/text'); + if (!$appFolder instanceof Folder) { + throw new NotFoundException('Folder not found'); + } + foreach ($appFolder->getDirectoryListing() as $node) { + if (str_starts_with($node->getName(), 'documents_old_')) { + $node->delete(); + } + } + } catch (NotFoundException ) { + } + } }