|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache; |
|
21
|
|
|
|
|
22
|
|
|
use Symfony\Component\Console\Command\Command; |
|
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
24
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Command to clear the metadata cache of the various cache drivers. |
|
28
|
|
|
* |
|
29
|
|
|
* @since 1.0 |
|
30
|
|
|
* @version $Revision$ |
|
31
|
|
|
* @author Benjamin Eberlei <[email protected]> |
|
32
|
|
|
* @author Guilherme Blanco <[email protected]> |
|
33
|
|
|
* @author Jonathan Wage <[email protected]> |
|
34
|
|
|
* @author Roman Borschel <[email protected]> |
|
35
|
|
|
* @author Henrik Westphal <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
class MetadataCommand extends Command |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @see \Symfony\Component\Console\Command\Command |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function configure() |
|
43
|
|
|
{ |
|
44
|
|
|
$this |
|
45
|
|
|
->setName('odm:clear-cache:metadata') |
|
46
|
|
|
->setDescription('Clear all metadata cache of the various cache drivers.') |
|
47
|
|
|
->setDefinition(array()) |
|
48
|
|
|
->setHelp(<<<EOT |
|
49
|
|
|
Clear all metadata cache of the various cache drivers. |
|
50
|
|
|
EOT |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @see \Symfony\Component\Console\Command\Command |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
58
|
|
|
{ |
|
59
|
|
|
$dm = $this->getHelper('documentManager')->getDocumentManager(); |
|
60
|
|
|
$cacheDriver = $dm->getConfiguration()->getMetadataCacheImpl(); |
|
61
|
|
|
|
|
62
|
|
|
if ( ! $cacheDriver) { |
|
63
|
|
|
throw new \InvalidArgumentException('No Metadata cache driver is configured on given DocumentManager.'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ($cacheDriver instanceof \Doctrine\Common\Cache\ApcCache) { |
|
67
|
|
|
throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$output->write('Clearing ALL Metadata cache entries' . PHP_EOL); |
|
71
|
|
|
|
|
72
|
|
|
$success = $cacheDriver->deleteAll(); |
|
73
|
|
|
|
|
74
|
|
|
if ($success) { |
|
75
|
|
|
$output->write('The cache entries were successfully deleted.' . PHP_EOL); |
|
76
|
|
|
} else { |
|
77
|
|
|
$output->write('No entries to be deleted.' . PHP_EOL); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|