1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine MongoDBBundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Saxulum\DoctrineMongodbOdmCommands\Command; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Command to clear the metadata cache of the various cache drivers. |
25
|
|
|
* |
26
|
|
|
* @author Fabien Potencier <[email protected]> |
27
|
|
|
* @author Jonathan H. Wage <[email protected]> |
28
|
|
|
* @author Henrik Westphal <[email protected]> |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
class ClearMetadataCacheDoctrineODMCommand extends MetadataCommand |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
parent::configure(); |
35
|
|
|
|
36
|
|
|
$this |
37
|
|
|
->setName('doctrine:mongodb:cache:clear-metadata') |
38
|
|
|
->setDescription('Clear all metadata cache for a document manager.') |
39
|
|
|
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') |
40
|
|
|
->setHelp(<<<EOT |
41
|
|
|
The <info>doctrine:mongodb:cache:clear-metadata</info> command clears all metadata cache for the default document manager: |
42
|
|
|
|
43
|
|
|
<info>./app/console doctrine:mongodb:cache:clear-metadata</info> |
44
|
|
|
|
45
|
|
|
You can also optionally specify the <comment>--dm</comment> option to specify which document manager to clear the cache for: |
46
|
|
|
|
47
|
|
|
<info>./app/console doctrine:mongodb:cache:clear-metadata --dm=default</info> |
48
|
|
|
EOT |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
DoctrineCommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); |
55
|
|
|
|
56
|
|
|
return parent::execute($input, $output); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.