Skip to content

Commit

Permalink
Merge branch 'development', release error...
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Oct 4, 2015
2 parents f968383 + bff60b7 commit be24ec9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ local
local:drush-aliases (drush-aliases) Find the project's Drush aliases
local:init (init) Create a local project file structure from a Git repository
project
project:delete Delete a project
project:get (get) Clone and build a project locally
project:list (projects) Get a list of all active projects
project:metadata Read or set metadata for a project
Expand Down
1 change: 1 addition & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected function getCommands()
$commands[] = new Command\Local\LocalDrushAliasesCommand();
$commands[] = new Command\Local\LocalDirCommand();
$commands[] = new Command\Local\LocalInitCommand();
$commands[] = new Command\Project\ProjectDeleteCommand();
$commands[] = new Command\Project\ProjectGetCommand();
$commands[] = new Command\Project\ProjectListCommand();
$commands[] = new Command\Project\ProjectMetadataCommand();
Expand Down
10 changes: 10 additions & 0 deletions src/Command/PlatformCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,16 @@ public function clearEnvironmentsCache(Project $project = null)
self::$cache->delete('environments:' . $project->id);
}

/**
* Clear the projects cache.
*
* Use this after deleting projects/users.
*/
protected function clearProjectsCache()
{
self::$cache->delete('projects');
}

/**
* @param Project $project
* @param Environment[] $environments
Expand Down
63 changes: 63 additions & 0 deletions src/Command/Project/ProjectDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace Platformsh\Cli\Command\Project;

use Platformsh\Cli\Command\PlatformCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ProjectDeleteCommand extends PlatformCommand
{

protected function configure()
{
$this
->setName('project:delete')
->setDescription('Delete a project');
$this->addProjectOption();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input);
$project = $this->getSelectedProject();
$client = $this->getClient();

$account = $client->getAccountInfo();
if ($account['uuid'] != $project->owner) {
$this->stdErr->writeln("Only the project's owner can delete it.");
return 1;
}

/** @var \Platformsh\Cli\Helper\PlatformQuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
$title = $project->title;

$confirmQuestion = "You are about to delete the project:"
. "\n <comment>$title</comment> (<comment>{$project->id}</comment>)"
. "\n\n * This action is <options=bold>irreversible</>."
. "\n * Your site will no longer be accessible."
. "\n * All data associated with this project will be deleted, including backups."
. "\n * You will be charged at the end of the month for any remaining project costs."
. "\n\nAre you sure you want to delete this project?";
if (!$questionHelper->confirm($confirmQuestion, $input, $output, false)) {
return 1;
}

if ($input->isInteractive() && strlen($title)) {
$confirmName = $questionHelper->askInput("Type the project title to confirm", $input, $this->stdErr);
if ($confirmName !== $title) {
$this->stdErr->writeln("Incorrect project title (expected: $title)");
return 1;
}
}

$subscriptionId = $project->getSubscriptionId();
$subscription = $client->getSubscription($subscriptionId);

$result = $subscription->delete();
$this->clearProjectsCache();

$this->stdErr->writeln("\nThe project <info>$title</info> (<info>{$project->id}</info>) was deleted.");
return 0;
}
}

0 comments on commit be24ec9

Please sign in to comment.