|
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
|
|
|
|