Passed
Push — master ( 8b8928...9eea0d )
by Andreas
11:05
created

cacheinvalidate::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.console
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
namespace midcom\console\command;
10
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use midcom_services_cache;
15
use Symfony\Component\Filesystem\Filesystem;
16
use Symfony\Component\Console\Attribute\AsCommand;
17
18
/**
19
 * clear the cache of the current site
20
 *
21
 * @see midcom_services_cache
22
 * @package midcom.console
23
 */
24
#[AsCommand(
25
    name: 'midcom:cache-invalidate',
26
    description: 'Clears the cache',
27
    aliases: ['cache-invalidate']
28
)]
29
class cacheinvalidate extends Command
30
{
31
    private midcom_services_cache $cache;
32
33
    private string $cachedir;
34
35
    public function __construct(midcom_services_cache $cache, string $cachedir)
36
    {
37
        $this->cache = $cache;
38
        $this->cachedir = $cachedir;
39
        parent::__construct();
40
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output) : int
43
    {
44
        try {
45
            $this->cache->invalidate_all();
46
        } catch (\Throwable $e) {
47
            $output->writeln($e->getMessage());
48
        }
49
50
        $fs = new Filesystem;
51
        $fs->remove([$this->cachedir]);
52
        return Command::SUCCESS;
53
    }
54
}
55