Skip to content

Commit

Permalink
fix: add no-compression option to delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Dec 10, 2024
1 parent a0fefac commit 24c90df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Classes/Command/DeleteBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class DeleteBackupCommand extends Command
private const INPUT_DIR = 'dir';
private const INPUT_FILE = 'file';
private const INPUT_KEEP_COUNT = 'keep-count';
private const INPUT_NO_COMPRESSION = 'no-compression';

/**
* @var mixed[]
Expand Down Expand Up @@ -52,6 +53,12 @@ protected function configure(): void
InputOption::VALUE_OPTIONAL,
'Number of database backups to keep',
$this->extensionConfiguration['delete']['keepCount']
)
->addOption(
self::INPUT_NO_COMPRESSION,
null,
InputOption::VALUE_NONE,
'Only delete non-compressed backups',
);
}

Expand All @@ -66,15 +73,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$dir = $input->getOption(self::INPUT_DIR);
$file = $input->getOption(self::INPUT_FILE);
$noCompression = $input->getOption(self::INPUT_NO_COMPRESSION);

if (!is_dir($dir)) {
$output->writeln(sprintf('Directory \'%s\' does not exist.', $dir));
return Command::FAILURE;
}

$files = array_values(array_diff(scandir($dir, SCANDIR_SORT_ASCENDING) ?: [], ['.', '..']));
$matches = array_filter($files, function (string $fileToCheck) use ($file) {
return (bool) preg_match(FileNamingUtility::getRegexPattern($file), $fileToCheck);
$matches = array_filter($files, function (string $fileToCheck) use ($file, $noCompression) {
return (bool) preg_match(FileNamingUtility::getRegexPattern($file, !$noCompression), $fileToCheck);
});

$filesToBeDeleted = array_slice($matches, 0, -(int)$input->getOption(self::INPUT_KEEP_COUNT));
Expand Down

0 comments on commit 24c90df

Please sign in to comment.