|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[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 ONGR\SettingsBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
19
|
|
|
|
|
20
|
|
|
class CacheClearCommand extends ContainerAwareCommand |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::configure(); |
|
28
|
|
|
|
|
29
|
|
|
$this |
|
30
|
|
|
->setName('ongr:settings:cache:clear') |
|
31
|
|
|
->setDescription('Clears a selected setting from cache.') |
|
32
|
|
|
->addArgument( |
|
33
|
|
|
'setting_name', |
|
34
|
|
|
InputArgument::REQUIRED, |
|
35
|
|
|
'Setting name to remove from cache' |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
43
|
|
|
{ |
|
44
|
|
|
$io = new SymfonyStyle($input, $output); |
|
45
|
|
|
|
|
46
|
|
|
if (!$this->getContainer()->has('ong_settings.cache_provider')) { |
|
47
|
|
|
throw new \RuntimeException('`ong_settings.cache_provider` service not available'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$cache = $this->getContainer()->get('ong_settings.cache_provider'); |
|
51
|
|
|
$setting = $input->getArgument('setting_name'); |
|
52
|
|
|
|
|
53
|
|
|
if (!$cache->contains($setting)) { |
|
54
|
|
|
$io->note(sprintf('Cache does not contain a setting named `%s`', $setting)); |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$cache->delete($setting); |
|
59
|
|
|
|
|
60
|
|
|
$io->success(sprintf('`%s` has been successfully cleared from cache', $setting)); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|