Completed
Push — 2.x-dev-kit ( 6f250c )
by
unknown
02:44
created

CacheFlushAllCommand::execute()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 20
rs 8.8571
cc 5
eloc 11
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\CacheBundle\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class CacheFlushAllCommand extends BaseCacheCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function configure()
24
    {
25
        $this->setName('sonata:cache:flush-all');
26
        $this->setDescription('Flush all information set in cache managers');
27
28
        $this->addOption('cache', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Flush elements stored in given cache');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $output->writeln('<info>clearing cache information</info>');
37
38
        foreach ($this->getManager()->getCacheServices() as $name => $cache) {
39
            if ($input->getOption('cache') && !in_array($name, $input->getOption('cache'))) {
40
                continue;
41
            }
42
43
            $output->write(sprintf(' > %s : starting .... ', $name));
44
45
            if ($cache->flushAll() === true) {
46
                $output->writeln('<info>OK</info>');
47
            } else {
48
                $output->writeln('<error>FAILED!</error>');
49
            }
50
        }
51
52
        $output->writeln('<info>done!</info>');
53
    }
54
}
55