1
|
|
|
<?php namespace Magestead\Command\Cache; |
2
|
|
|
|
3
|
|
|
use Magestead\Command\ProcessCommand; |
4
|
|
|
use Magestead\Helper\Config; |
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class FlushCommand |
12
|
|
|
* @package Magestead\Command\Cache |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
class FlushCommand extends Command |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
protected $_config; |
17
|
|
|
protected $_projectPath; |
18
|
|
|
|
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this->_projectPath = getcwd(); |
22
|
|
|
$this->setName("cache:flush"); |
23
|
|
|
$this->setDescription("Flushes cache storage used by cache types"); |
24
|
|
|
$this->addArgument('type', InputArgument::OPTIONAL, '[cache code/type]'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param InputInterface $input |
29
|
|
|
* @param OutputInterface $output |
30
|
|
|
* @return ProcessCommand |
31
|
|
|
*/ |
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
$output->writeln('<info>Flushing cache storage</info>'); |
35
|
|
|
|
36
|
|
|
$cacheType = $input->getArgument('type'); |
37
|
|
|
$command = $this->getCommand(new Config($output), $cacheType); |
38
|
|
|
$pCommand = "vagrant ssh -c '". $command ."'"; |
39
|
|
|
return new ProcessCommand($pCommand, $this->_projectPath, $output); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param Config $config |
44
|
|
|
* @return bool|string |
45
|
|
|
*/ |
46
|
|
|
protected function getCommand(Config $config, $cacheType) |
47
|
|
|
{ |
48
|
|
|
$type = $config->type; |
|
|
|
|
49
|
|
|
switch ($type) { |
50
|
|
|
case 'magento': |
51
|
|
|
return "cd /var/www/public;../bin/n98-magerun.phar cache:flush $cacheType"; |
52
|
|
|
case 'magento2': |
53
|
|
|
return "cd /var/www/public;bin/magento cache:flush $cacheType"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.