Skip to content

Commit

Permalink
Refines db commands and runs phpmd over codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 19, 2020
1 parent 4e3e706 commit 2014784
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 135 deletions.
1 change: 1 addition & 0 deletions src/Cli/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function injectParameters($container)
$parameterInjection->register('AcquiaCloudApi\Endpoints\Insights', new AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Endpoints\LogForwardingDestinations', new AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Endpoints\SslCertificates', new AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Endpoints\Organizations', new AcquiaCliInjector);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function waitForNotification($response)
case self::TASKFAILED:
// If there's one failure we should throw an exception
throw new \Exception('Acquia task failed.');
break(2);
break(2);
// If tasks are started or in progress, we should continue back
// to the top of the loop and wait until tasks are complete.
case self::TASKSTARTED:
Expand All @@ -203,7 +203,7 @@ protected function waitForNotification($response)
break(2);
default:
throw new \Exception('Unknown notification status.');
break(2);
break(2);
}

// Timeout if the command exceeds the configured timeout threshold.
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ApplicationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function applicationTagDelete(Applications $applicationsAdapter, $uuid, $
* @param string $name
*
* @command application:rename
* @alias app:rename,a:rename
* @aliases app:rename,a:rename
*/
public function applicationRename(Applications $applicationsAdapter, $uuid, $name)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function code(Client $client, Code $codeAdapter, $uuid, $match = null)
/**
* Deploys code from one environment to another.
*
* @param string $uuid
* @param string $environmentFrom
* @param string $environmentTo
* @param string $uuid
* @param string $environmentFrom
* @param string $environmentTo
*
* @command code:deploy
* @aliases c:d
Expand Down
38 changes: 19 additions & 19 deletions src/Commands/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class CronCommand extends AcquiaCommand
/**
* Shows all cron tasks associated with an environment.
*
* @param string $uuid
* @param string $environment
* @param string $uuid
* @param string $environment
*
* @command cron:list
*/
Expand Down Expand Up @@ -55,11 +55,11 @@ public function crons(Crons $cronAdapter, $uuid, $environment)
/**
* Adds a new cron task for an environment.
*
* @param string $uuid
* @param string $environment
* @param string $commandString The command to be run on cron wrapped in quotes.
* @param string $frequency The crontab format frequency wrapped in quotes
* @param string $label An optional label for the cron command wrapped in quotes.
* @param string $uuid
* @param string $environment
* @param string $commandString The command to be run on cron wrapped in quotes.
* @param string $frequency The crontab format frequency wrapped in quotes
* @param string $label An optional label for the cron command wrapped in quotes.
*
* @command cron:create
* @aliases cron:add
Expand All @@ -75,9 +75,9 @@ public function cronAdd(Crons $cronAdapter, $uuid, $environment, $commandString,
/**
* Removes a cron task for an environment.
*
* @param string $uuid
* @param string $environment
* @param int $cronId
* @param string $uuid
* @param string $environment
* @param int $cronId
*
* @command cron:delete
* @aliases cron:remove
Expand All @@ -95,9 +95,9 @@ public function cronDelete(Crons $cronAdapter, $uuid, $environment, $cronId)
/**
* Enables a disabled cron entry.
*
* @param string $uuid
* @param string $environment
* @param int $cronId
* @param string $uuid
* @param string $environment
* @param int $cronId
*
* @command cron:enable
*/
Expand All @@ -112,9 +112,9 @@ public function cronEnable(Crons $cronAdapter, $uuid, $environment, $cronId)
/**
* Disables an enabled cron entry.
*
* @param string $uuid
* @param string $environment
* @param int $cronId
* @param string $uuid
* @param string $environment
* @param int $cronId
*
* @command cron:disable
*/
Expand All @@ -131,9 +131,9 @@ public function cronDisable(Crons $cronAdapter, $uuid, $environment, $cronId)
/**
* Shows detailed information about a single cron command.
*
* @param string $uuid
* @param string $environment
* @param int $cronId
* @param string $uuid
* @param string $environment
* @param int $cronId
*
* @command cron:info
*/
Expand Down
64 changes: 44 additions & 20 deletions src/Commands/DbBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,55 @@ class DbBackupCommand extends AcquiaCommand
/**
* Backs up all DBs in an environment.
*
* @param string $uuid
* @param string $environment
* @param string $uuid
* @param string $environment
*
* @command database:backup:all
* @aliases db:backup:all
*/
public function dbBackupAll($uuid, $environment)
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);
$this->backupAllEnvironmentDbs($uuid, $environment);
}

/**
* Backs up a DB in an environment.
*
* @param string $uuid
* @param string $environment
* @param string $dbName
*
* @command database:backup
* @aliases db:backup
*/
public function dbBackup($uuid, $environment)
public function dbBackup(Databases $databaseAdapter, $uuid, $environment, $dbName)
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);
$this->backupAllEnvironmentDbs($uuid, $environment);

// @TODO replace this call with a specific API call.
// https://cloudapi-docs.acquia.com/#/Environments/getEnvironmentsDatabase
$databases = $databaseAdapter->getAll($uuid);
foreach ($databases as $database) {
if ($database->name === $dbName) {
$this->backupDb($uuid, $environment, $database);
}
}
}

/**
* Shows a list of database backups for all databases in an environment.
*
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param string $uuid
* @param string $environment
* @param string $dbName
*
* @command database:backup:list
* @aliases db:backup:list
*/
public function dbBackupList(
Client $client,
Databases $databaseAdapter,
DatabaseBackups $databaseBackupsAdapter,
$uuid,
$environment,
Expand All @@ -61,8 +86,7 @@ public function dbBackupList(
if (null !== $dbName) {
$client->addQuery('filter', "name=${dbName}");
}
$dbAdapter = new Databases($this->cloudapi);
$databases = $dbAdapter->getAll($uuid);
$databases = $databaseAdapter->getAll($uuid);
$client->clearQuery();

$table = new Table($this->output());
Expand Down Expand Up @@ -97,10 +121,10 @@ public function dbBackupList(
/**
* Restores a database from a saved backup.
*
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param int $backupId
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param int $backupId
*
* @command database:backup:restore
* @aliases db:backup:restore
Expand All @@ -122,10 +146,10 @@ public function dbBackupRestore(DatabaseBackups $databaseBackupsAdapter, $uuid,
/**
* Provides a database backup link.
*
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param int $backupId
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param int $backupId
*
* @command database:backup:link
* @aliases db:backup:link
Expand All @@ -148,9 +172,9 @@ public function dbBackupLink($uuid, $environment, $dbName, $backupId)
/**
* Downloads a database backup.
*
* @param string $uuid
* @param string $environment
* @param string $dbName
* @param string $uuid
* @param string $environment
* @param string $dbName
*
* @throws \Exception
*
Expand Down
27 changes: 9 additions & 18 deletions src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
class DbCommand extends AcquiaCommand
{

protected $databaseAdapter;

public function __construct()
{
parent::__construct();

$this->databaseAdapter = new Databases($this->cloudapi);
}

/**
* Shows all databases.
*
Expand All @@ -36,9 +27,9 @@ public function __construct()
* @command database:list
* @aliases db:list
*/
public function dbList($uuid)
public function dbList(Databases $databaseAdapter, $uuid)
{
$databases = $this->databaseAdapter->getAll($uuid);
$databases = $databaseAdapter->getAll($uuid);
$table = new Table($this->output());
$table->setHeaders(['Databases']);
foreach ($databases as $database) {
Expand All @@ -63,9 +54,9 @@ public function dbList($uuid)
* @command database:create
* @aliases database:add,db:create,db:add
*/
public function dbCreate($uuid, $dbName)
public function dbCreate(Databases $databaseAdapter, $uuid, $dbName)
{
$response = $this->databaseAdapter->create($uuid, $dbName);
$response = $databaseAdapter->create($uuid, $dbName);
$this->say(sprintf('Creating database (%s)', $dbName));
$this->waitForNotification($response);
}
Expand All @@ -79,29 +70,29 @@ public function dbCreate($uuid, $dbName)
* @command database:delete
* @aliases database:remove,db:remove,db:delete
*/
public function dbDelete($uuid, $dbName)
public function dbDelete(Databases $databaseAdapter, $uuid, $dbName)
{
if ($this->confirm('Are you sure you want to delete this database?')) {
$this->say(sprintf('Deleting database (%s)', $dbName));
$response = $this->databaseAdapter->delete($uuid, $dbName);
$response = $databaseAdapter->delete($uuid, $dbName);
$this->waitForNotification($response);
}
}

/**
* Truncaates a database.
* Truncates a database (only applicable to Acquia free tier).
*
* @param string $uuid
* @param string $dbName
*
* @command database:truncate
* @aliases db:truncate
*/
public function dbTruncate($uuid, $dbName)
public function dbTruncate(Databases $databaseAdapter, $uuid, $dbName)
{
if ($this->confirm('Are you sure you want to truncate this database?')) {
$this->say(sprintf('Truncate database (%s)', $dbName));
$response = $this->databaseAdapter->truncate($uuid, $dbName);
$response = $databaseAdapter->truncate($uuid, $dbName);
$this->waitForNotification($response);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/DomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function domainInfo(OutputInterface $output, Domains $domainAdapter, $uui

$table = new Table($output);
$table->setHeaders(['Hostname', 'Active', 'DNS Resolves', 'IP Addresses', 'CNAMES']);
$table->setColumnStyle(1, 'center-align');
$table->setColumnStyle(2, 'center-align');
$table
->addRows(
[
Expand All @@ -94,7 +96,7 @@ public function domainInfo(OutputInterface $output, Domains $domainAdapter, $uui
* @param string $domain
*
* @command domain:create
* @alias domain:add
* @aliases domain:add
*/
public function domainCreate(Domains $domainAdapter, $uuid, $environment, $domain)
{
Expand All @@ -112,7 +114,7 @@ public function domainCreate(Domains $domainAdapter, $uuid, $environment, $domai
* @param string $domain
*
* @command domain:delete
* @alias domain:remove
* @aliases domain:remove
*/
public function domainDelete(Domains $domainAdapter, $uuid, $environment, $domain)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/EnvironmentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function renderEnvironmentInfo(EnvironmentResponse $environment, Serve
* @param string $name
*
* @command environment:rename
* @alias env:rename,e:rename
* @aliases env:rename,e:rename
*/
public function environmentRename(Environments $environmentsAdapter, $uuid, $environment, $name)
{
Expand All @@ -220,12 +220,12 @@ public function environmentRename(Environments $environmentsAdapter, $uuid, $env
* @param string $environment
*
* @command environment:delete
* @alias env:delete,e:d,environment:remove,env:remove
* @aliases env:delete,e:d,environment:remove,env:remove
*/
public function environmentDelete(Environments $environmentsAdapter, $uuid, $environment)
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);
if ($this->confirm("Are you sure you want to delete this environment?")) {
if ($this->confirm(sprintf('Are you sure you want to delete the %s environment?', $environment->label))) {
$this->say(sprintf('Deleting %s environment', $environment->label));
$response = $environmentsAdapter->delete($environment->uuid);
$this->waitForNotification($response);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/LogForwardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function logforwardList(
}

/**
* Gets information about a Log ForwaRD.
* Gets information about a Log Forward.
*
* @param string $uuid
* @param string $environment
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/LogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class LogsCommand extends AcquiaCommand
/**
* Streams logs from an environment.
*
* @param string $uuid
* @param string $environment
* @param array $opts
* @param string $uuid
* @param string $environment
* @param array $opts
* @option $colourise Colourise the output
* @option $logtypes Filter to specific log types
* @option $servers Filter to specific servers
Expand Down
Loading

0 comments on commit 2014784

Please sign in to comment.