Skip to content

Commit

Permalink
Fixes usages of Client in injection.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent 8070d13 commit 4aa1b0a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 68 deletions.
1 change: 1 addition & 0 deletions src/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function getContainer($input, $output, $application, $config, $client)

$parameterInjection = $container->get('parameterInjection');
$parameterInjection->register('AcquiaCli\CloudApi', new \AcquiaCli\Injector\AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Connector\Client', new \AcquiaCli\Injector\AcquiaCliInjector);
$parameterInjection->register(
'AcquiaCloudApi\Endpoints\Applications',
new \AcquiaCli\Injector\AcquiaCliInjector
Expand Down
39 changes: 0 additions & 39 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,6 @@ public function validateUuidHook(CommandData $commandData)
$uuid = $this->getUuidFromHostingName($uuid);
$commandData->input()->setArgument('uuid', $uuid);
}

// Convert environment parameters to an EnvironmentResponse
// if ($commandData->input()->hasArgument('environment')) {
// $environmentName = $commandData->input()->getArgument('environment');
// if (null !== $environmentName) {
// $environment = $this->getEnvironmentFromEnvironmentName($uuid, $environmentName);
// $commandData->input()->setArgument('environment', $environment);
// }
// }
// if ($commandData->input()->hasArgument('environmentFrom')) {
// $environmentFromName = $commandData->input()->getArgument('environmentFrom');
// $environmentFrom = $this->getEnvironmentFromEnvironmentName($uuid, $environmentFromName);
// $commandData->input()->setArgument('environmentFrom', $environmentFrom);
// }
// if ($commandData->input()->hasArgument('environmentTo')) {
// $environmentToName = $commandData->input()->getArgument('environmentTo');
// $environmentTo = $this->getEnvironmentFromEnvironmentName($uuid, $environmentToName);
// $commandData->input()->setArgument('environmentTo', $environmentTo);
// }
}
// Convert Organization name to UUID.
if ($commandData->input()->hasArgument('organization')) {
Expand All @@ -152,26 +133,6 @@ public function validateUuidHook(CommandData $commandData)
}
}

/**
* @param string $uuid
* @param string $environment
* @return EnvironmentResponse
* @throws Exception
*/
// protected function getEnvironmentFromEnvironmentName($uuid, $environment)
// {
// $environmentsAdapter = new Environments($this->cloudapi);
// $environments = $environmentsAdapter->getAll($uuid);

// foreach ($environments as $e) {
// if ($environment === $e->name) {
// return $e;
// }
// }

// throw new Exception('Unable to find ID for environment');
// }

/**
* @param string $organizationName
* @return OrganizationResponse
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AcquiaCloudApi\Response\EnvironmentResponse;
use Symfony\Component\Console\Helper\Table;
use AcquiaCloudApi\Endpoints\Code;
use AcquiaCloudApi\Connector\Client;

/**
* Class CodeCommand
Expand All @@ -23,13 +24,13 @@ class CodeCommand extends AcquiaCommand
* @command code:list
* @aliases c:l
*/
public function code(Code $codeAdapter, $uuid, $match = null)
public function code(Client $client, Code $codeAdapter, $uuid, $match = null)
{
if (null !== $match) {
$this->cloudapi->addQuery('filter', "name=@*${match}*");
$client->addQuery('filter', "name=@*${match}*");
}
$branches = $codeAdapter->getAll($uuid);
$this->cloudapi->clearQuery();
$client->clearQuery();
$output = $this->output();
$table = new Table($output);
Expand Down
43 changes: 31 additions & 12 deletions src/Commands/DbBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AcquiaCli\Commands;

use AcquiaCloudApi\Connector\Connector;
use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Endpoints\Databases;
use AcquiaCloudApi\Endpoints\DatabaseBackups;
Expand Down Expand Up @@ -47,16 +48,21 @@ public function dbBackup($uuid, $environment)
* @command database:backup:list
* @aliases db:backup:list
*/
public function dbBackupList(DatabaseBackups $databaseBackupsAdapter, $uuid, $environment, $dbName = null)
{
public function dbBackupList(
Client $client,
DatabaseBackups $databaseBackupsAdapter,
$uuid,
$environment,
$dbName = null
) {
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

if (null !== $dbName) {
$this->cloudapi->addQuery('filter', "name=${dbName}");
$client->addQuery('filter', "name=${dbName}");
}
$dbAdapter = new Databases($this->cloudapi);
$databases = $dbAdapter->getAll($uuid);
$this->cloudapi->clearQuery();
$client->clearQuery();

$table = new Table($this->output());
$table->setHeaders(['ID', 'Type', 'Timestamp']);
Expand Down Expand Up @@ -148,19 +154,24 @@ public function dbBackupLink($uuid, $environment, $dbName, $backupId)
* @aliases db:backup:download
* @option $backup Select which backup to download by backup ID. If omitted, the latest will be downloaded.
* @option $path Select a path to download the backup to. If omitted, the system temp directory will be used.
* @option $filename Choose a filename to call the backup. If omitted, the name will be automatically generated.
*/
public function dbBackupDownload(
Client $client,
DatabaseBackups $databaseBackupsAdapter,
$uuid,
$environment,
$dbName,
$opts = ['backup' => null, 'path' => null]
$opts = ['backup' => null, 'path' => null, 'filename' => null]
) {

$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

if (!$opts['backup']) {
$this->cloudapi->addQuery('sort', '-created');
$this->cloudapi->addQuery('limit', 1);
$client->addQuery('sort', '-created');
$client->addQuery('limit', 1);
$backup = $databaseBackupsAdapter->getAll($environment->uuid, $dbName);
$this->cloudapi->clearQuery();
$client->clearQuery();
if (empty($backup)) {
throw new \Exception('Unable to find a database backup to download.');
}
Expand All @@ -169,7 +180,11 @@ public function dbBackupDownload(
$backupId = $opts['backup'];
}

$backupName = sprintf('%s-%s-%s', $environment->name, $dbName, $backupId);
if (null === $opts['filename']) {
$backupName = sprintf('%s-%s-%s', $environment->name, $dbName, $backupId);
} else {
$backupName = $opts['filename'];
}

if (null === $opts['path']) {
$location = tempnam(sys_get_temp_dir(), $backupName) . '.sql.gz';
Expand All @@ -183,9 +198,13 @@ public function dbBackupDownload(
$this->downloadProgress->start();
$this->downloadProgress->setMessage(sprintf('Downloading database backup to %s', $location));

$this->cloudapi->addOption('sink', $location);
$this->cloudapi->addOption('curl.options', ['CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_FILE' => $location]);
$this->cloudapi->addOption('progress', function (
$client->addOption('sink', $location);
$client->addOption(
'curl.options',
['CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_FILE' => $location]
);

$client->addOption('progress', function (
$downloadTotal,
$downloadedBytes
) {
Expand Down
14 changes: 10 additions & 4 deletions src/Commands/EnvironmentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AcquiaCli\Commands;

use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Endpoints\Environments;
use AcquiaCloudApi\Endpoints\Servers;
use AcquiaCloudApi\Response\EnvironmentResponse;
Expand Down Expand Up @@ -61,16 +62,21 @@ public function environmentList(Environments $environmentsAdapter, OutputInterfa
* @command environment:info
* @aliases env:info,e:i
*/
public function environmentInfo(Environments $environmentsAdapter, Servers $serversAdapter, $uuid, $env = null)
{
public function environmentInfo(
Client $client,
Environments $environmentsAdapter,
Servers $serversAdapter,
$uuid,
$env = null
) {

if (null !== $env) {
$this->cloudapi->addQuery('filter', "name=${env}");
$client->addQuery('filter', "name=${env}");
}

$environments = $environmentsAdapter->getAll($uuid);

$this->cloudapi->clearQuery();
$client->clearQuery();

foreach ($environments as $e) {
$this->renderEnvironmentInfo($e, $serversAdapter);
Expand Down
11 changes: 6 additions & 5 deletions src/Commands/NotificationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AcquiaCli\Commands;

use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Endpoints\Notifications;
use AcquiaCloudApi\Endpoints\Organizations;
use Symfony\Component\Console\Helper\Table;
Expand Down Expand Up @@ -34,19 +35,19 @@ public function __construct()
* @command notification:list
* @alias n:l
*/
public function notificationList($uuid, $limit = 50, $filter = null, $sort = '~created_at')
public function notificationList(Client $client, $uuid, $limit = 50, $filter = null, $sort = '~created_at')
{

// Allows for limits and sort criteria.
$sort = str_replace('~', '-', $sort);
$this->cloudapi->addQuery('limit', $limit);
$this->cloudapi->addQuery('sort', $sort);
$client->addQuery('limit', $limit);
$client->addQuery('sort', $sort);
if (null !== $filter) {
$this->cloudapi->addQuery('filter', "name=${filter}");
$client->addQuery('filter', "name=${filter}");
}

$notifications = $this->notificationsAdapter->getAll($uuid);
$this->cloudapi->clearQuery();
$client->clearQuery();

$output = $this->output();
$table = new Table($output);
Expand Down
11 changes: 6 additions & 5 deletions src/Commands/SshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AcquiaCli\Commands;

use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Endpoints\Environments;

Expand All @@ -20,16 +21,16 @@ class SshCommand extends EnvironmentsCommand
*
* @command ssh:info
*/
public function sshInfo(Environments $environmentsAdapter, $uuid, $env = null)
public function sshInfo(Client $client, Environments $environmentsAdapter, $uuid, $env = null)
{

// if (null !== $env) {
// $this->cloudapi->addQuery('filter', "name=${env}");
// }
if (null !== $env) {
$client->addQuery('filter', "name=${env}");
}

$environments = $environmentsAdapter->getAll($uuid);

$this->cloudapi->clearQuery();
$client->clearQuery();

foreach ($environments as $e) {
/** @var $e EnvironmentResponse */
Expand Down
2 changes: 2 additions & 0 deletions src/Injector/AcquiaCliInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function get(CommandData $commandData, $interfaceName)
return $this->cloudapi;
case 'AcquiaCli\Config':
return $this->config;
case 'AcquiaCloudApi\Connector\Client':
return $this->client;
case 'AcquiaCloudApi\Endpoints\Applications':
return new Applications($this->client);
case 'AcquiaCloudApi\Endpoints\Environments':
Expand Down

0 comments on commit 4aa1b0a

Please sign in to comment.