|
1
|
|
|
<?php namespace Magestead\Command\Index; |
|
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
|
|
View Code Duplication |
class ShowModeCommand extends Command |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
protected $_config; |
|
13
|
|
|
protected $_projectPath; |
|
14
|
|
|
|
|
15
|
|
|
protected function configure() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->_projectPath = getcwd(); |
|
18
|
|
|
$this->setName("index:mode:show"); |
|
19
|
|
|
$this->setDescription("Show index mode"); |
|
20
|
|
|
$this->addArgument('index', InputArgument::OPTIONAL, '[indexer]'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param InputInterface $input |
|
25
|
|
|
* @param OutputInterface $output |
|
26
|
|
|
* @return ProcessCommand |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
29
|
|
|
{ |
|
30
|
|
|
$output->writeln('<info>Getting index mode</info>'); |
|
31
|
|
|
$index = $input->getArgument('index'); |
|
32
|
|
|
|
|
33
|
|
|
$command = $this->getCommand(new Config($output), $index); |
|
34
|
|
|
if ($command) { |
|
35
|
|
|
$passedCommand = "vagrant ssh -c '". $command ."'"; |
|
36
|
|
|
return new ProcessCommand($passedCommand, $this->_projectPath, $output); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$output->writeln('<error>Command not available for this application</error>'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param Config $config |
|
44
|
|
|
* @param $index |
|
45
|
|
|
* @return bool|string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getCommand(Config $config, $index) |
|
48
|
|
|
{ |
|
49
|
|
|
$type = $config->type; |
|
|
|
|
|
|
50
|
|
|
switch ($type) { |
|
51
|
|
|
case 'magento2': |
|
52
|
|
|
return "cd /var/www/public;bin/magento indexer:show-mode $index"; |
|
53
|
|
|
break; |
|
|
|
|
|
|
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.