-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathMetadataCommand.php
59 lines (48 loc) · 1.93 KB
/
MetadataCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command to clear the metadata cache of the various cache drivers.
*
* @link www.doctrine-project.org
*/
class MetadataCommand extends AbstractEntityManagerCommand
{
/** @return void */
protected function configure()
{
$this->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 <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
EOT
);
}
/**
* {@inheritDoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$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 <info>all</info> Metadata cache entries');
$result = $cacheDriver->clear();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
$ui->success($message);
return 0;
}
}