1
|
|
|
<?php |
2
|
|
|
namespace Kunstmaan\Skylab\Command; |
3
|
|
|
|
4
|
|
|
use Kunstmaan\Skylab\Skeleton\AbstractSkeleton; |
5
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* RemoveProjectCommand |
11
|
|
|
*/ |
12
|
|
|
class RemoveProjectCommand extends AbstractCommand |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Configures the current command. |
17
|
|
|
*/ |
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
$this |
21
|
|
|
->addDefaults() |
22
|
|
|
->setName('remove') |
23
|
|
|
->setDescription('Removes a Skylab project') |
24
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'The name of the project.') |
25
|
|
|
->addOption("force", null, InputOption::VALUE_NONE, 'Does not ask before removing') |
26
|
|
|
->setHelp(<<<EOT |
27
|
|
|
The <info>remove</info> command will remove the project after creating a backup first. |
28
|
|
|
|
29
|
|
|
<info>php skylab.phar remove testproject</info> # Will remove the testproject project |
30
|
|
|
<info>php skylab.phar remove testproject --force</info> # Will do the same, but don't ask you if you are sure. |
31
|
|
|
|
32
|
|
|
EOT |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function doExecute() |
37
|
|
|
{ |
38
|
|
|
$projectname = $this->dialogProvider->askFor("Please enter the name of the project", 'name'); |
39
|
|
|
|
40
|
|
|
// Check if the project exists, do use in creating a new one with the same name. |
41
|
|
|
if (!$this->fileSystemProvider->projectExists($projectname)) { |
42
|
|
|
$this->dialogProvider->logError("A project with name $projectname does not exists!", false); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (!$this->input->getOption('force') && !$this->dialogProvider->askConfirmation('Are you sure you want to remove ' . $projectname . '?')) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->dialogProvider->logStep("Removing project $projectname"); |
50
|
|
|
|
51
|
|
|
$command = $this->getApplication()->find('backup'); |
52
|
|
|
$arguments = array( |
53
|
|
|
'command' => 'backup', |
54
|
|
|
'project' => $projectname, |
55
|
|
|
'--hideLogo' => true |
56
|
|
|
); |
57
|
|
|
$input = new ArrayInput($arguments); |
58
|
|
|
$returnCode = $command->run($input, $this->output); |
59
|
|
|
|
60
|
|
|
if (!$returnCode) { |
61
|
|
|
$this->permissionsProvider->killProcesses($projectname); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$project = $this->projectConfigProvider->loadProjectConfig($projectname); |
65
|
|
|
|
66
|
|
|
$this->skeletonProvider->skeletonLoop(function (AbstractSkeleton $skeleton) use ($project) { |
67
|
|
|
$this->dialogProvider->logTask("Running preRemove for skeleton " . $skeleton->getName()); |
68
|
|
|
$skeleton->preRemove($project); |
69
|
|
|
}, new \ArrayObject($project["skeletons"])); |
70
|
|
|
|
71
|
|
|
$this->dialogProvider->logTask("Deleting the project folder at " . $this->fileSystemProvider->getProjectDirectory($projectname)); |
72
|
|
|
$this->fileSystemProvider->removeProjectDirectory($project); |
73
|
|
|
|
74
|
|
|
$this->skeletonProvider->skeletonLoop(function (AbstractSkeleton $skeleton) use ($project) { |
75
|
|
|
$this->dialogProvider->logTask("Running postRemove for skeleton " . $skeleton->getName()); |
76
|
|
|
$skeleton->postRemove($project); |
77
|
|
|
}, new \ArrayObject($project["skeletons"])); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|