1 | <?php |
||
21 | class FlushCommand extends AbstractMagentoCommand |
||
22 | { |
||
23 | /** |
||
24 | * @var OutputInterface |
||
25 | */ |
||
26 | private $output; |
||
27 | |||
28 | const NAME = 'cache:dir:flush'; |
||
29 | |||
30 | protected function configure() |
||
31 | { |
||
32 | $this |
||
33 | ->setName(FlushCommand::NAME) |
||
34 | ->setDescription('Flush (empty) Magento cache directory'); |
||
35 | } |
||
36 | |||
37 | public function getHelp() |
||
38 | { |
||
39 | return <<<HELP |
||
40 | The default cache backend is the files cache in Magento. The default |
||
41 | directory of that default cache backend is the directory "var/cache" |
||
42 | within the Magento web-root directory (should be blocked from external |
||
43 | access). |
||
44 | |||
45 | The cache:dir:flish Magerun command will remove all files within that |
||
46 | directory. This is currently the most purist form to reset default |
||
47 | caching configuration in Magento. |
||
48 | |||
49 | Flushing the cache directory can help to re-initialize the whole Magento |
||
50 | application after it got stuck in cached configuration like a half-done |
||
51 | cache initialization, old config data within the files cache and similar. |
||
52 | HELP; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param InputInterface $input |
||
57 | * @param OutputInterface $output |
||
58 | * |
||
59 | * @return int|void |
||
60 | */ |
||
61 | protected function execute(InputInterface $input, OutputInterface $output) |
||
62 | { |
||
63 | $this->output = $output; |
||
64 | $this->detectMagento($output, true); |
||
65 | |||
66 | if (!$this->initMagento()) { |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | $workingDirectory = getcwd(); |
||
71 | $magentoRootFolder = $this->getApplication()->getMagentoRootFolder(); |
||
72 | $cacheDir = $magentoRootFolder . '/var/cache'; |
||
73 | |||
74 | $output->writeln(sprintf('<info>Flushing cache directory <comment>%s</comment></info>', $cacheDir)); |
||
75 | |||
76 | $this->verbose(sprintf('<debug>root-dir: <comment>%s</comment>', $magentoRootFolder)); |
||
77 | $this->verbose(sprintf('<debug>cwd: <comment>%s</comment>', $workingDirectory)); |
||
78 | |||
79 | $this->emptyDirectory($cacheDir); |
||
80 | |||
81 | $output->writeln('Cache directory flushed'); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $path |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | private function emptyDirectory($path) |
||
124 | |||
125 | /** |
||
126 | * @param string $message |
||
127 | */ |
||
128 | private function verbose($message) |
||
140 | } |
||
141 |