|
1
|
|
|
<?php |
|
2
|
|
|
namespace Samurai\Module\Task; |
|
3
|
|
|
|
|
4
|
|
|
use Samurai\Task\ITask; |
|
5
|
|
|
use Samurai\Task\Task; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Removing |
|
12
|
|
|
* @package Samurai\module\Task |
|
13
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
View Code Duplication |
class Removing extends Task |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param InputInterface $input |
|
19
|
|
|
* @param OutputInterface $output |
|
20
|
|
|
* @return bool |
|
21
|
|
|
*/ |
|
22
|
4 |
|
public function execute(InputInterface $input, OutputInterface $output) |
|
23
|
|
|
{ |
|
24
|
4 |
|
$moduleName = $input->getArgument('name'); |
|
25
|
4 |
|
if(!$this->getService('module_manager')->has($moduleName)){ |
|
26
|
1 |
|
$output->writeln(sprintf('<error>Error: no module "%s" found</error>', $moduleName)); |
|
27
|
1 |
|
return ITask::BLOCKING_ERROR_CODE; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
3 |
|
$module = $this->getService('module_manager')->get($moduleName); |
|
31
|
3 |
|
if($this->confirmRemove($input, $output, $module->getPackage())){ |
|
32
|
2 |
|
$this->getService('module_procedure')->setOutput($output); |
|
33
|
2 |
|
$this->getService('module_procedure')->remove($module); |
|
34
|
2 |
|
} |
|
35
|
3 |
|
return ITask::NO_ERROR_CODE; |
|
36
|
4 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param InputInterface $input |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
* @param string $modulePackage |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
3 |
|
private function confirmRemove(InputInterface $input, OutputInterface $output, $modulePackage) |
|
45
|
|
|
{ |
|
46
|
3 |
|
return $this->getService('helper_set')->get('question')->ask( |
|
47
|
3 |
|
$input, |
|
48
|
3 |
|
$output, |
|
49
|
3 |
|
$this->buildQuestion($modulePackage) |
|
50
|
3 |
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $modulePackage |
|
55
|
|
|
* @return ConfirmationQuestion |
|
56
|
|
|
*/ |
|
57
|
3 |
|
private function buildQuestion($modulePackage) |
|
58
|
|
|
{ |
|
59
|
3 |
|
return new ConfirmationQuestion( |
|
60
|
3 |
|
sprintf( |
|
61
|
3 |
|
'<question>Do you want to remove the module "%s"</question>[y]', |
|
62
|
|
|
$modulePackage |
|
63
|
3 |
|
) |
|
64
|
3 |
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|