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.
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>.
20 namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
22 use Symfony\Component\Console\Input\InputArgument,
23 Symfony\Component\Console\Input\InputOption,
24 Symfony\Component\Console,
25 Doctrine\Common\Cache;
28 * Command to clear the metadata cache of the various cache drivers.
31 * @link www.doctrine-project.org
33 * @author Benjamin Eberlei <kontakt@beberlei.de>
34 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
35 * @author Jonathan Wage <jonwage@gmail.com>
36 * @author Roman Borschel <roman@code-factory.org>
38 class MetadataCommand extends Console\Command\Command
41 * @see Console\Command\Command
43 protected function configure()
46 ->setName('orm:clear-cache:metadata')
47 ->setDescription('Clear all metadata cache of the various cache drivers.')
48 ->setDefinition(array(
50 'flush', null, InputOption::VALUE_NONE,
51 'If defined, cache entries will be flushed instead of deleted/invalidated.'
56 The <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
57 It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
60 The execution type differ on how you execute the command.
61 If you want to invalidate the entries (and not delete from cache instance), this command would do the work:
63 <info>%command.name%</info>
65 Alternatively, if you want to flush the cache provider using this command:
67 <info>%command.name% --flush</info>
69 Finally, be aware that if <info>--flush</info> option is passed, not all cache providers are able to flush entries,
70 because of a limitation of its execution nature.
76 * @see Console\Command\Command
78 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
80 $em = $this->getHelper('em')->getEntityManager();
81 $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
83 if ( ! $cacheDriver) {
84 throw new \InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');
87 if ($cacheDriver instanceof Cache\ApcCache) {
88 throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
91 $output->write('Clearing ALL Metadata cache entries' . PHP_EOL);
93 $result = $cacheDriver->deleteAll();
94 $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
96 if (true === $input->getOption('flush')) {
97 $result = $cacheDriver->flushAll();
98 $message = ($result) ? 'Successfully flushed cache entries.' : $message;
101 $output->write($message . PHP_EOL);