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; + } +}