ask before clearing the cache

This commit is contained in:
Uwe Steinmann 2025-11-13 18:56:08 +01:00
parent 994fe49e6d
commit 7c9ef030d6

View File

@ -6,6 +6,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Seeddms\Seeddms\Settings; use Seeddms\Seeddms\Settings;
use Seeddms\Seeddms\Translator; use Seeddms\Seeddms\Translator;
@ -33,9 +35,10 @@ class ClearcacheCommand extends Command
protected function configure() protected function configure()
{ {
$this->setName('cache:clear') $this->setName('cache:clear')
->setDescription('Clears the cache') ->setDescription('Clear cache')
->setHelp('Clears all cache or those specified.') ->setHelp('Clears either all caches or those specified with option --cache. Think twice before you clear a cache with previews. Depending on the number of documents in your DMS, it may take a long time to recreate the cache.')
->addOption('cache', '', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Remove files from cache.', null) ->addOption('cache', '', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Remove files from this cache.', null)
->addOption('force', '', InputOption::VALUE_NONE, 'Force operation, do not ask')
; ;
} }
@ -52,6 +55,14 @@ class ClearcacheCommand extends Command
return Command::FAILURE; return Command::FAILURE;
} }
if (!$input->getOption('force')) {
$helper = new QuestionHelper();
$question = new ConfirmationQuestion('Do you really want to clear the cache? ', false);
if (!$helper->ask($input, $output, $question)) {
return Command::SUCCESS;
}
}
require_once('inc/inc.DBInit.php'); require_once('inc/inc.DBInit.php');
$post = array_flip($input->getOption('cache')); $post = array_flip($input->getOption('cache'));