Skip to content

Commit

Permalink
Converts domains, insights, organisations to 2.0 of PHP SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent 5f2a0ab commit aaca391
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ public function validateUuidHook(CommandData $commandData)
// Convert environment parameters to an EnvironmentResponse
if ($commandData->input()->hasArgument('environment')) {
$environmentName = $commandData->input()->getArgument('environment');
$environment = $this->getEnvironmentFromEnvironmentName($uuid, $environmentName);
$commandData->input()->setArgument('environment', $environment);
if (null !== $environmentName) {
$environment = $this->getEnvironmentFromEnvironmentName($uuid, $environmentName);
$commandData->input()->setArgument('environment', $environment);
}
}
if ($commandData->input()->hasArgument('environmentFrom')) {
$environmentFromName = $commandData->input()->getArgument('environmentFrom');
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public function acquiaDbBackupRestore($uuid, $environment, $backupId)
{
$environmentName = $environment->label;
if ($this->confirm("Are you sure you want to restore backup id ${backupId} to ${environmentName}?")) {
$this->cloudapi->restoreDatabaseBackup($environment->uuid, $backupId);
$this->waitForTask($uuid, 'DatabaseBackupRestored');
$dbAdapter = new DatabaseBackups($this->cloudapi);
$response = $dbAdapter->restore($environment->uuid, $backupId);
$this->waitForNotification($response);
}
}

Expand Down
23 changes: 15 additions & 8 deletions src/Commands/DomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AcquiaCli\Commands;

use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Endpoints\Domains;

/**
* Class DomainCommand
Expand All @@ -24,8 +25,9 @@ public function acquiaAddDomain($uuid, $environment, $domain)
{
$label = $environment->label;
$this->say("Adding ${domain} to ${label} environment");
$this->cloudapi->createDomain($environment->uuid, $domain);
$this->waitForTask($uuid, 'DomainAdded');
$domainAdapter = new Domains($this->cloudapi);
$response = $domainAdapter->create($environment->uuid, $domain);
$this->waitForNotification($response);
}

/**
Expand All @@ -42,8 +44,9 @@ public function acquiaRemoveDomain($uuid, $environment, $domain)
if ($this->confirm('Are you sure you want to remove this domain?')) {
$label = $environment->label;
$this->say("Removing ${domain} from environment ${label}");
$this->cloudapi->deleteDomain($environment->uuid, $domain);
$this->waitForTask($uuid, 'DomainRemoved');
$domainAdapter = new Domains($this->cloudapi);
$response = $domainAdapter->delete($environment->uuid, $domain);
$this->waitForNotification($response);
}
}

Expand All @@ -64,11 +67,15 @@ public function acquiaMoveDomain($uuid, $domain, $environmentFrom, $environmentT
if ($this->confirm(
"Are you sure you want to move ${domain} from ${environmentFromLabel} to ${environmentToLabel}?"
)) {
$domainAdapter = new Domains($this->cloudapi);
$this->say("Moving ${domain} from ${environmentFromLabel} to ${environmentToLabel}");
$this->cloudapi->deleteDomain($environmentFrom->uuid, $domain);
$this->waitForTask($uuid, 'DomainRemoved');
$this->cloudapi->createDomain($environmentTo->uuid, $domain);
$this->waitForTask($uuid, 'DomainAdded');

$deleteResponse = $domainAdapter->delete($environment->uuid, $domain);
$this->waitForNotification($deleteResponse);

$addResponse = $domainAdapter->create($environment->uuid, $domain);
$this->waitForNotification($addResponse);

}
}
}
15 changes: 9 additions & 6 deletions src/Commands/InsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AcquiaCloudApi\Response\InsightCountResponse;
use AcquiaCloudApi\Response\InsightResponse;
use AcquiaCloudApi\Endpoints\Insights;
use Symfony\Component\Console\Helper\Table;

/**
Expand All @@ -17,17 +18,19 @@ class InsightsCommand extends AcquiaCommand
* Shows Insights information for specified applications.
*
* @param string $uuid
* @param string $env
* @param string $environment
*
* @command insights:info
*/
public function acquiaInsightsInfo($uuid, $env = null)
public function acquiaInsightsInfo($uuid, $environment = null)
{
if (null === $env) {
$insights = $this->cloudapi->applicationInsights($uuid);

$insightsAdapter = new Insights($this->cloudapi);

if (null === $environment) {
$insights = $insightsAdapter->getAll($uuid);
} else {
$environment = $this->getEnvironmentFromEnvironmentName($uuid, $env);
$insights = $this->cloudapi->environmentInsights($environment->uuid);
$insights = $insightsAdapter->getEnvironment($environment->uuid);
}
foreach ($insights as $insight) {
/** @var InsightResponse $insight */
Expand Down
16 changes: 10 additions & 6 deletions src/Commands/OrganizationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ public function organizationApplications($organizationUuid)
/**
* Shows teams within an organization.
*
* @param string $organizationUuid
* @param string $organization
*
* @command organization:teams
* @alias org:teams
*/
public function organizationTeams($organizationUuid)
public function organizationTeams($organization)
{
$teams = $this->cloudapi->organizationTeams($organizationUuid);
$organizationUuid = $organization->uuid;
$organizationsAdapter = new Organizations($this->cloudapi);
$teams = $organizationsAdapter->getTeams($organizationUuid);

$this->say("Teams in organisation: ${organizationUuid}");
$table = new Table($this->output());
Expand All @@ -112,14 +114,16 @@ public function organizationTeams($organizationUuid)
/**
* Shows all members.
*
* @param string $organizationUuid
* @param string $organization
*
* @command organization:members
* @alias org:members
*/
public function members($organizationUuid)
public function members($organization)
{
$members = $this->cloudapi->members($organizationUuid);
$organizationUuid = $organization->uuid;
$organizationsAdapter = new Organizations($this->cloudapi);
$members = $organizationsAdapter->getMembers($organizationUuid);

$this->say("Members in organisation: ${organizationUuid}");
$table = new Table($this->output());
Expand Down

0 comments on commit aaca391

Please sign in to comment.