setName('orm:clear-cache:metadata')
->setDescription('Clear all metadata cache of the various cache drivers')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
->setHelp(<<<'EOT'
The %command.name% command is meant to clear the metadata cache of associated Entity Manager.
EOT);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getMetadataCache();
if (! $cacheDriver) {
throw new InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');
}
$ui->comment('Clearing all Metadata cache entries');
$result = $cacheDriver->clear();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
$ui->success($message);
return 0;
}
}