Skip to content

Commit 39113a4

Browse files
committed
Merge branch 'kirtangajjar-add-self-deletion' into develop-v4
2 parents 2cef0dc + 6dd58a8 commit 39113a4

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
use Behat\Behat\Hook\Scope\AfterFeatureScope;
88

99

10-
use Behat\Gherkin\Node\PyStringNode,
11-
Behat\Gherkin\Node\TableNode;
10+
use Behat\Gherkin\Node\PyStringNode;
1211

1312
class FeatureContext implements Context
1413
{
@@ -93,7 +92,27 @@ public function stdoutShouldReturnSomethingLike($output_stream, PyStringNode $ex
9392
}
9493
}
9594

96-
95+
/**
96+
* @Then ee should be deleted
97+
*/
98+
public function eeShouldBeDeleted()
99+
{
100+
$result = EE::launch("docker ps -aqf label=org.label-schema.vendor=\"EasyEngine\" | wc -l", false, true);
101+
if( trim($result->stdout) !== '0' ) {
102+
throw new Exception("All containers have not been removed.");
103+
}
104+
$home = getenv('HOME');
105+
if(file_exists("$home/.ee/")){
106+
throw new Exception("~/.ee/ has not been removed");
107+
}
108+
if(file_exists("$home/ee-sites/")){
109+
throw new Exception("~/ee-sites/ has not been removed");
110+
}
111+
if(file_exists('/opt/easyengine/')){
112+
throw new Exception("/opt/easyengine/ has not been removed");
113+
}
114+
}
115+
97116
/**
98117
* @AfterFeature
99118
*/

features/cli.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ Feature: CLI Command
1313
Scenario: ee update works properly
1414
Given ee phar is generated
1515
When I run 'sudo php ee.phar cli update --yes'
16-
Then return value should be 0
16+
Then return value should be 0
17+
18+
Scenario: ee uninstall works properly
19+
When I run 'sudo bin/ee cli self-uninstall --yes'
20+
Then ee should be deleted

php/commands/src/CLI_Command.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
use \Composer\Semver\Comparator;
4+
use \Symfony\Component\Filesystem\Filesystem;
45
use \EE\Utils;
5-
use Mustangostang\Spyc;
66

77
/**
88
* Review current EE info, check for updates, or see defined aliases.
@@ -162,7 +162,7 @@ public function info( $_, $assoc_args ) {
162162
/**
163163
* Function to run migrations required to upgrade to the newer version. Will always be invoked from the newer phar downloaded inside the /tmp folder
164164
*/
165-
public function migrate() {
165+
private function migrate() {
166166
EE\Migration\Executor::execute_migrations();
167167
}
168168

@@ -488,6 +488,40 @@ public function cmd_dump() {
488488
echo json_encode( $this->command_to_array( EE::get_root_command() ) );
489489
}
490490

491+
/**
492+
* Uninstalls easyengine completely along with all sites
493+
*
494+
* ## OPTIONS
495+
*
496+
* [--yes]
497+
* : Do not prompt for confirmation.
498+
*
499+
* @subcommand self-uninstall
500+
*/
501+
public function self_uninstall( $args, $assoc_args ) {
502+
503+
EE::confirm("Are you sure you want to remove EasyEngine and all its sites(along with their data)?\nThis is an irreversible action. No backup will be kept.", $assoc_args);
504+
505+
Utils\default_launch("docker rm -f $(docker ps -aqf label=org.label-schema.vendor=\"EasyEngine\")");
506+
$home = Utils\get_home_dir();
507+
Utils\default_launch("rm -rf $home/.ee/");
508+
509+
$records = EE::db()->select(['site_path']);
510+
511+
if( $records !== false ) {
512+
$sites_paths = array_column($records, 'site_path');
513+
$fs = new Filesystem();
514+
$fs->remove($sites_paths);
515+
}
516+
517+
Utils\default_launch("rm -df $home/ee-sites/");
518+
Utils\default_launch("rm -rf /opt/easyengine/");
519+
520+
if ( Utils\inside_phar() ) {
521+
unlink( realpath( $_SERVER['argv'][0] ) );
522+
}
523+
}
524+
491525
/**
492526
* Generate tab completion strings.
493527
*

0 commit comments

Comments
 (0)