From bb8f88493dbf42260642a2e73cfa4672ef3d5fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 24 Apr 2025 12:41:12 +0200 Subject: [PATCH] feat: XML dump cleanup command --- src/Command/CleanupXMLDumpsCommand.php | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Command/CleanupXMLDumpsCommand.php diff --git a/src/Command/CleanupXMLDumpsCommand.php b/src/Command/CleanupXMLDumpsCommand.php new file mode 100644 index 0000000..7f07a46 --- /dev/null +++ b/src/Command/CleanupXMLDumpsCommand.php @@ -0,0 +1,55 @@ +modify('-1 week')->getTimestamp(); + + try { + $files = $this + ->xmlDump + ->listContents('.') + ->filter(fn(StorageAttributes $attributes) => $attributes->isFile() && $attributes->lastModified() < $maxDate) + ->map(fn(StorageAttributes $attributes) => $attributes->path()) + ->toArray(); + } catch (FilesystemException $e) { + $output->writeln('' . $e->getMessage() . ''); + + return Command::FAILURE; + } + + foreach ($files as $file) { + $this->xmlDump->delete($file); + } + + $message = 'Removed '.count($files).' outdated XML dumps'; + $this->logger->info($message); + $output->writeln(''.$message.''); + + return Command::SUCCESS; + } +}