|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dekalee\Cdn77Bundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Dekalee\Cdn77\Query\PurgeAllQuery; |
|
6
|
|
|
use Dekalee\Cdn77\Query\PurgeFileQuery; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PurgeAllCacheCommand |
|
14
|
|
|
*/ |
|
15
|
|
|
class PurgeAllCacheCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
protected $purgeFileQuery; |
|
18
|
|
|
protected $purgeAllQuery; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param PurgeFileQuery $purgeFileQuery |
|
22
|
|
|
* @param PurgeAllQuery $purgeAllQuery |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(PurgeFileQuery $purgeFileQuery, PurgeAllQuery $purgeAllQuery) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct(); |
|
27
|
|
|
$this->purgeFileQuery = $purgeFileQuery; |
|
28
|
|
|
$this->purgeAllQuery = $purgeAllQuery; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Configure the command |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function configure() |
|
36
|
|
|
{ |
|
37
|
|
|
$this |
|
38
|
|
|
->setName('dekalee:cdn77:purge') |
|
39
|
|
|
->setDescription('Purge some cache from cdn77') |
|
40
|
|
|
->addOption('resource', null, InputOption::VALUE_OPTIONAL, 'If you want to purge only one resource') |
|
41
|
|
|
->addOption('file', null, InputOption::VALUE_OPTIONAL, 'If you want to purge only the cache for one file') |
|
42
|
|
|
; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param InputInterface $input |
|
47
|
|
|
* @param OutputInterface $output |
|
48
|
|
|
* |
|
49
|
|
|
* @return int|null|void |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
|
|
$ressource = $input->getOption('resource'); |
|
54
|
|
|
|
|
55
|
|
|
if ($file = $input->getOption('file')) { |
|
56
|
|
|
$this->purgeFileQuery->execute($ressource, [$file]); |
|
57
|
|
|
} else { |
|
58
|
|
|
$this->purgeAllQuery->execute($ressource); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$output->writeln('Purge query send'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|