From d7b8612ac0bf0bc4de7b1a59c7917c019a2b1d56 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Sat, 3 Oct 2015 11:05:51 +0100 Subject: [PATCH 01/19] Accept full URL for GitHub integration --- src/Command/Integration/IntegrationCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Command/Integration/IntegrationCommand.php b/src/Command/Integration/IntegrationCommand.php index 4dfc9c3b6..301318106 100644 --- a/src/Command/Integration/IntegrationCommand.php +++ b/src/Command/Integration/IntegrationCommand.php @@ -49,10 +49,17 @@ private function getFields() ]), 'repository' => new Field('Repository', [ 'conditions' => ['type' => 'github'], - 'description' => 'GitHub: the repository to track (in the form \'user/repo\')', + 'description' => 'GitHub: the repository to track (the URL, e.g. \'https://github.com/user/repo\')', 'validator' => function ($string) { return substr_count($string, '/', 1) === 1; }, + 'normalizer' => function ($string) { + if (preg_match('#^https?://#', $string)) { + return parse_url($string, PHP_URL_PATH); + } + + return $string; + }, ]), 'build_pull_requests' => new BooleanField('Build pull requests', [ 'conditions' => ['type' => 'github'], From c1ecc15f262a3bba537602ce355c6e9b9b4ab751 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Thu, 15 Oct 2015 00:57:14 +0100 Subject: [PATCH 02/19] Wait for user:add and user:role activities --- composer.json | 2 +- composer.lock | 15 +++++++-------- src/Command/User/UserAddCommand.php | 18 ++++++++++-------- src/Command/User/UserRoleCommand.php | 13 +++++++------ 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index b97371267..826d42849 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "doctrine/cache": "~1.4.2", "platformsh/console-form": "0.0.4", - "platformsh/client": "0.1.31", + "platformsh/client": "0.1.33", "symfony/console": "~2.5 >=2.5.2", "symfony/yaml": "~2.5", "symfony/finder": "~2.5", diff --git a/composer.lock b/composer.lock index 1e400b3fa..ffe86ded9 100644 --- a/composer.lock +++ b/composer.lock @@ -1,11 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4a729f896523816008f56930acbc21ca", - "content-hash": "367693d454d17a8dbfc588b5ba9e4c5a", + "hash": "04f347f7c79539157fba19a024383907", "packages": [ { "name": "cocur/slugify", @@ -679,16 +678,16 @@ }, { "name": "platformsh/client", - "version": "v0.1.31", + "version": "v0.1.33", "source": { "type": "git", "url": "https://github.com/platformsh/platformsh-client-php.git", - "reference": "3e95fe11d3dbf09afe508f990aa8954aba434992" + "reference": "0fc909b4f8213f038ef0eb9541cd0806e8daa1f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/3e95fe11d3dbf09afe508f990aa8954aba434992", - "reference": "3e95fe11d3dbf09afe508f990aa8954aba434992", + "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/0fc909b4f8213f038ef0eb9541cd0806e8daa1f7", + "reference": "0fc909b4f8213f038ef0eb9541cd0806e8daa1f7", "shasum": "" }, "require": { @@ -716,7 +715,7 @@ } ], "description": "Platform.sh API client", - "time": "2015-10-08 10:53:23" + "time": "2015-10-14 22:20:23" }, { "name": "platformsh/console-form", diff --git a/src/Command/User/UserAddCommand.php b/src/Command/User/UserAddCommand.php index 729f42b93..ca7259baa 100644 --- a/src/Command/User/UserAddCommand.php +++ b/src/Command/User/UserAddCommand.php @@ -2,7 +2,7 @@ namespace Platformsh\Cli\Command\User; use Platformsh\Cli\Util\ActivityUtil; -use Platformsh\Client\Model\Activity; +use Platformsh\Client\Model\ProjectAccess; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $projectRole = $input->getOption('role'); - if ($projectRole && !in_array($projectRole, array('admin', 'viewer'))) { + if ($projectRole && !in_array($projectRole, ProjectAccess::$roles)) { $this->stdErr->writeln("Valid project-level roles are 'admin' or 'viewer'"); return 1; } @@ -120,14 +120,16 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("Environment not found: $environmentId"); continue; } - $result = $user->changeEnvironmentRole($environments[$environmentId], $role); - if ($result instanceof Activity) { - $activities[] = $result; + $activity = $user->changeEnvironmentRole($environments[$environmentId], $role); + if (!$input->getOption('no-wait')) { + ActivityUtil::waitAndLog( + $activity, + $this->stdErr, + "Set role for environment $environmentId", + "Failed to set role for environment $environmentId" + ); } } - if (!$input->getOption('no-wait')) { - ActivityUtil::waitMultiple($activities, $this->stdErr, 'Waiting for environment(s) to be redeployed'); - } } $this->stdErr->writeln("User $email created"); diff --git a/src/Command/User/UserRoleCommand.php b/src/Command/User/UserRoleCommand.php index 4eada2d03..ffc110ffc 100644 --- a/src/Command/User/UserRoleCommand.php +++ b/src/Command/User/UserRoleCommand.php @@ -2,7 +2,8 @@ namespace Platformsh\Cli\Command\User; use Platformsh\Cli\Util\ActivityUtil; -use Platformsh\Client\Model\Activity; +use Platformsh\Client\Model\EnvironmentAccess; +use Platformsh\Client\Model\ProjectAccess; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -55,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $currentRole = null; - $validRoles = array('admin', 'viewer'); + $validRoles = ProjectAccess::$roles; if ($level == 'project') { $currentRole = $selectedUser['role']; } @@ -65,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } $currentRole = $selectedUser->getEnvironmentRole($this->getSelectedEnvironment()); - $validRoles = array('admin', 'viewer', 'contributor'); + $validRoles = EnvironmentAccess::$roles; } $role = $input->getOption('role'); @@ -88,11 +89,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("User $email updated"); } elseif ($role && $level == 'environment') { - $result = $selectedUser->changeEnvironmentRole($this->getSelectedEnvironment(), $role); + $activity = $selectedUser->changeEnvironmentRole($this->getSelectedEnvironment(), $role); $this->stdErr->writeln("User $email updated"); - if (!$input->getOption('no-wait') && $result instanceof Activity) { + if (!$input->getOption('no-wait')) { ActivityUtil::waitAndLog( - $result, + $activity, $this->stdErr, 'Environment redeployed successfully', 'Failed to redeploy environment' From 9f5488e86ea9603b6826aae93576e445c5f6d6b6 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Thu, 15 Oct 2015 01:36:45 +0100 Subject: [PATCH 03/19] Allow user:add to set 'no access' on environments --- src/Command/User/UserAddCommand.php | 75 ++++++++++++++++++++++++---- src/Command/User/UserCommand.php | 57 --------------------- src/Command/User/UserRoleCommand.php | 3 +- 3 files changed, 67 insertions(+), 68 deletions(-) delete mode 100644 src/Command/User/UserCommand.php diff --git a/src/Command/User/UserAddCommand.php b/src/Command/User/UserAddCommand.php index ca7259baa..642f1ed8a 100644 --- a/src/Command/User/UserAddCommand.php +++ b/src/Command/User/UserAddCommand.php @@ -1,6 +1,7 @@ getEnvironments($project); if ($input->isInteractive()) { - $this->stdErr->writeln("The user's environment-level roles can be 'viewer', 'contributor', or 'admin'."); + $this->stdErr->writeln("The user's environment-level roles can be 'viewer', 'contributor', 'admin', or 'none'."); } foreach ($environments as $environment) { - $question = new Question('' . $environment->id . ' environment role [V/c/a]: ', 'viewer'); + $question = new Question('' . $environment->id . ' environment role [v/c/a/N]: ', 'none'); $question->setValidator(array($this, 'validateRole')); $question->setMaxAttempts(5); $environmentRoles[$environment->id] = $this->standardizeRole($questionHelper->ask($input, $this->stdErr, $question)); @@ -120,14 +121,20 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("Environment not found: $environmentId"); continue; } - $activity = $user->changeEnvironmentRole($environments[$environmentId], $role); + if ($role == 'none') { + continue; + } + $access = $user->getEnvironmentAccess($environments[$environmentId]); + if ($access) { + $this->stdErr->writeln("Modifying the user's role on the environment: $environmentId"); + $activity = $access->update(['role' => $role]); + } + else { + $this->stdErr->writeln("Adding the user to the environment: $environmentId"); + $activity = $environments[$environmentId]->addUser($user->id, $role); + } if (!$input->getOption('no-wait')) { - ActivityUtil::waitAndLog( - $activity, - $this->stdErr, - "Set role for environment $environmentId", - "Failed to set role for environment $environmentId" - ); + ActivityUtil::waitAndLog($activity, $this->stdErr); } } } @@ -136,4 +143,52 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } + /** + * @param string $value + * + * @return string + */ + public function validateRole($value) + { + if (empty($value) || !in_array($value, array('admin', 'contributor', 'viewer', 'none', 'a', 'c', 'v', 'n'))) { + throw new \RuntimeException("Invalid role: $value"); + } + + return $value; + } + + /** + * @param string $value + * + * @return string + */ + public function validateEmail($value) + { + if (empty($value) || !filter_var($value, FILTER_VALIDATE_EMAIL)) { + throw new \RuntimeException("Invalid email address: $value"); + } + + return $value; + } + + /** + * @param string $givenRole + * + * @return string + * @throws \Exception + */ + protected function standardizeRole($givenRole) + { + $possibleRoles = array('viewer', 'admin', 'contributor', 'none'); + if (in_array($givenRole, $possibleRoles)) { + return $givenRole; + } + $role = strtolower($givenRole); + foreach ($possibleRoles as $possibleRole) { + if (strpos($possibleRole, $role) === 0) { + return $possibleRole; + } + } + throw new \Exception("Role not found: $givenRole"); + } } diff --git a/src/Command/User/UserCommand.php b/src/Command/User/UserCommand.php deleted file mode 100644 index b43fc1ea3..000000000 --- a/src/Command/User/UserCommand.php +++ /dev/null @@ -1,57 +0,0 @@ - Date: Sat, 17 Oct 2015 12:01:02 +0100 Subject: [PATCH 04/19] Update client dependency --- composer.json | 2 +- composer.lock | 15 ++++++++------- src/Command/User/UserAddCommand.php | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 826d42849..6a0587c75 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "doctrine/cache": "~1.4.2", "platformsh/console-form": "0.0.4", - "platformsh/client": "0.1.33", + "platformsh/client": "0.1.34", "symfony/console": "~2.5 >=2.5.2", "symfony/yaml": "~2.5", "symfony/finder": "~2.5", diff --git a/composer.lock b/composer.lock index ffe86ded9..8171bf61b 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,11 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "04f347f7c79539157fba19a024383907", + "hash": "860dbb4832b4004e6b22e112ab47ddf8", + "content-hash": "bc235f39f9faf7703ea8fbfb15ff789f", "packages": [ { "name": "cocur/slugify", @@ -678,16 +679,16 @@ }, { "name": "platformsh/client", - "version": "v0.1.33", + "version": "v0.1.34", "source": { "type": "git", "url": "https://github.com/platformsh/platformsh-client-php.git", - "reference": "0fc909b4f8213f038ef0eb9541cd0806e8daa1f7" + "reference": "ce7ec0542a30bc078394b37045bde1c723d592cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/0fc909b4f8213f038ef0eb9541cd0806e8daa1f7", - "reference": "0fc909b4f8213f038ef0eb9541cd0806e8daa1f7", + "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/ce7ec0542a30bc078394b37045bde1c723d592cb", + "reference": "ce7ec0542a30bc078394b37045bde1c723d592cb", "shasum": "" }, "require": { @@ -715,7 +716,7 @@ } ], "description": "Platform.sh API client", - "time": "2015-10-14 22:20:23" + "time": "2015-10-15 07:41:01" }, { "name": "platformsh/console-form", diff --git a/src/Command/User/UserAddCommand.php b/src/Command/User/UserAddCommand.php index 642f1ed8a..8aaef00c1 100644 --- a/src/Command/User/UserAddCommand.php +++ b/src/Command/User/UserAddCommand.php @@ -46,8 +46,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $project = $this->getSelectedProject(); $users = $project->getUsers(); - foreach ($users as $user) { - if ($user->getAccount()['email'] === $email) { + foreach ($users as $projectAccess) { + if ($projectAccess->getAccount()['email'] === $email) { $this->stdErr->writeln("The user already exists: $email"); return 1; } @@ -111,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->stdErr->writeln("Adding the user to the project"); - $user = $project->addUser($email, $projectRole); + $projectAccess = $project->addUser($email, $projectRole); if (!empty($environmentRoles)) { $this->stdErr->writeln("Setting environment role(s)"); @@ -124,14 +124,14 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($role == 'none') { continue; } - $access = $user->getEnvironmentAccess($environments[$environmentId]); + $access = $environments[$environmentId]->getUser($projectAccess->id); if ($access) { $this->stdErr->writeln("Modifying the user's role on the environment: $environmentId"); $activity = $access->update(['role' => $role]); } else { $this->stdErr->writeln("Adding the user to the environment: $environmentId"); - $activity = $environments[$environmentId]->addUser($user->id, $role); + $activity = $environments[$environmentId]->addUser($projectAccess->id, $role); } if (!$input->getOption('no-wait')) { ActivityUtil::waitAndLog($activity, $this->stdErr); From fe6fb6d66f6ebc80f7f7968e6755e8dc9b7ec5e0 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Sat, 17 Oct 2015 12:24:13 +0100 Subject: [PATCH 05/19] domain:list had old --project option --- src/Command/Domain/DomainListCommand.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Command/Domain/DomainListCommand.php b/src/Command/Domain/DomainListCommand.php index 67da48713..33cf67142 100644 --- a/src/Command/Domain/DomainListCommand.php +++ b/src/Command/Domain/DomainListCommand.php @@ -19,13 +19,8 @@ protected function configure() $this ->setName('domain:list') ->setAliases(array('domains')) - ->setDescription('Get a list of all domains') - ->addOption( - 'project', - null, - InputOption::VALUE_REQUIRED, - 'The project ID' - ); + ->setDescription('Get a list of all domains'); + $this->addProjectOption(); } /** From 0f5e72f8c3043bfa59b416d9e1493f69da53d001 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Sat, 17 Oct 2015 12:37:03 +0100 Subject: [PATCH 06/19] Fix: project cache was bypassed if there was a host --- src/Command/PlatformCommand.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Command/PlatformCommand.php b/src/Command/PlatformCommand.php index 3105885c5..d37c40fa6 100644 --- a/src/Command/PlatformCommand.php +++ b/src/Command/PlatformCommand.php @@ -458,6 +458,12 @@ protected function getProject($id, $host = null, $refresh = false) $host = parse_url($url, PHP_URL_HOST); } + // Find the project in the user's main project list. This uses a cache. + $projects = $this->getProjects($refresh); + if (isset($projects[$id])) { + return $projects[$id]; + } + // Get the project directly if a hostname is specified. if (!empty($host)) { $scheme = 'https'; @@ -468,12 +474,6 @@ protected function getProject($id, $host = null, $refresh = false) return $this->getClient()->getProjectDirect($id, $host, $scheme != 'http'); } - // Otherwise, find the project in the user's main project list. - $projects = $this->getProjects($refresh); - if (isset($projects[$id])) { - return $projects[$id]; - } - return false; } From 95557663d556ec278d9054c36b0cee3e2398d9b5 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Sun, 18 Oct 2015 12:18:23 +0100 Subject: [PATCH 07/19] Ensure cache is cleared when switching accounts --- src/Command/Auth/LoginCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Command/Auth/LoginCommand.php b/src/Command/Auth/LoginCommand.php index e4bb49ef6..010fb4596 100644 --- a/src/Command/Auth/LoginCommand.php +++ b/src/Command/Auth/LoginCommand.php @@ -30,6 +30,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("Please log in using your Platform.sh account\n"); $this->configureAccount($input, $this->stdErr); + $this->clearCache(); $this->stdErr->writeln("\nThank you, you are all set.\n"); } From 1a8584f673b633b9ca5a784ca5e1bfd31e7cd86e Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Sun, 18 Oct 2015 12:27:41 +0100 Subject: [PATCH 08/19] This isn't where we'd do account creation --- src/Command/Auth/LoginCommand.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Command/Auth/LoginCommand.php b/src/Command/Auth/LoginCommand.php index 010fb4596..9b9c2ed8c 100644 --- a/src/Command/Auth/LoginCommand.php +++ b/src/Command/Auth/LoginCommand.php @@ -54,21 +54,6 @@ function ($answer) { $question->setMaxAttempts(5); $email = $helper->ask($input, $output, $question); - $userExists = true; - if (!$userExists) { - $createAccountText = "\nThis email address is not associated with a Platform.sh account. \n"; - $createAccountText .= 'Would you like to create a new account?'; - $createAccount = $helper->confirm($createAccountText, $input, $output); - if ($createAccount) { - // @todo - } else { - // Start from the beginning. - $this->configureAccount($input, $output); - - return; - } - } - $pendingInvitation = false; if ($pendingInvitation) { $resendInviteText = "\nThis email address is associated with a Platform.sh account, \n"; From 13a1c9b6bb3cf06a635b868a56babc44c87b515f Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 19 Oct 2015 08:45:50 +0100 Subject: [PATCH 09/19] Unused var --- src/Command/User/UserAddCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Command/User/UserAddCommand.php b/src/Command/User/UserAddCommand.php index 8aaef00c1..ca0ca3ffc 100644 --- a/src/Command/User/UserAddCommand.php +++ b/src/Command/User/UserAddCommand.php @@ -115,7 +115,6 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!empty($environmentRoles)) { $this->stdErr->writeln("Setting environment role(s)"); - $activities = []; foreach ($environmentRoles as $environmentId => $role) { if (!isset($environments[$environmentId])) { $this->stdErr->writeln("Environment not found: $environmentId"); From 75063fbd119319d53beca2e841a0ace8253f8751 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 19 Oct 2015 22:05:01 +0100 Subject: [PATCH 10/19] Fix has_certificate check in domain:list --- src/Command/Domain/DomainListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/Domain/DomainListCommand.php b/src/Command/Domain/DomainListCommand.php index 33cf67142..bc66305b8 100644 --- a/src/Command/Domain/DomainListCommand.php +++ b/src/Command/Domain/DomainListCommand.php @@ -57,7 +57,7 @@ protected function buildDomainRows(array $tree) foreach ($tree as $domain) { $rows[] = array( $domain['id'], - $formatter->format((bool) $domain['has_certificate']), + $formatter->format((bool) $domain['ssl']['has_certificate']), $formatter->format($domain['created_at'], 'created_at'), ); } From 7a872856a3aeadeae9485d5697edca65847ddf87 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Tue, 20 Oct 2015 10:03:33 +0100 Subject: [PATCH 11/19] Handle new activities returned from httpaccess/smtp/variables --- composer.json | 2 +- composer.lock | 14 ++++----- src/Command/Activity/ActivityLogCommand.php | 2 +- src/Command/Domain/DomainAddCommand.php | 10 +++++-- src/Command/Domain/DomainDeleteCommand.php | 10 +++++-- src/Command/Domain/DomainListCommand.php | 1 - .../EnvironmentActivateCommand.php | 7 ++--- .../Environment/EnvironmentBranchCommand.php | 10 ++----- .../Environment/EnvironmentDeleteCommand.php | 6 ++-- .../EnvironmentHttpAccessCommand.php | 15 +++++++--- .../Environment/EnvironmentInfoCommand.php | 29 ++++++++++++------- .../Environment/EnvironmentMergeCommand.php | 8 ++--- .../EnvironmentSynchronizeCommand.php | 8 ++--- .../Integration/IntegrationAddCommand.php | 24 ++++++++++----- .../Integration/IntegrationDeleteCommand.php | 8 ++++- src/Command/PlatformCommand.php | 12 ++++++++ src/Command/Project/ProjectInfoCommand.php | 27 +++++++++++------ .../Snapshot/SnapshotCreateCommand.php | 1 + .../Snapshot/SnapshotRestoreCommand.php | 1 + src/Command/User/UserAddCommand.php | 27 +++++++++++------ src/Command/User/UserRoleCommand.php | 7 +---- .../Variable/VariableDeleteCommand.php | 18 ++++++++---- src/Command/Variable/VariableSetCommand.php | 22 +++++++------- src/Util/ActivityUtil.php | 2 +- 24 files changed, 169 insertions(+), 102 deletions(-) diff --git a/composer.json b/composer.json index 6a0587c75..a5d74c367 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "doctrine/cache": "~1.4.2", "platformsh/console-form": "0.0.4", - "platformsh/client": "0.1.34", + "platformsh/client": "0.2.1", "symfony/console": "~2.5 >=2.5.2", "symfony/yaml": "~2.5", "symfony/finder": "~2.5", diff --git a/composer.lock b/composer.lock index 8171bf61b..9c3b911c9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "860dbb4832b4004e6b22e112ab47ddf8", - "content-hash": "bc235f39f9faf7703ea8fbfb15ff789f", + "hash": "31235139388b8ee5b6f313a91b0b4dfd", + "content-hash": "79c090325cfd9dff8c33db203781062a", "packages": [ { "name": "cocur/slugify", @@ -679,16 +679,16 @@ }, { "name": "platformsh/client", - "version": "v0.1.34", + "version": "v0.2.1", "source": { "type": "git", "url": "https://github.com/platformsh/platformsh-client-php.git", - "reference": "ce7ec0542a30bc078394b37045bde1c723d592cb" + "reference": "051780d1bee15dd68e25024387fef813cc25bfd2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/ce7ec0542a30bc078394b37045bde1c723d592cb", - "reference": "ce7ec0542a30bc078394b37045bde1c723d592cb", + "url": "https://api.github.com/repos/platformsh/platformsh-client-php/zipball/051780d1bee15dd68e25024387fef813cc25bfd2", + "reference": "051780d1bee15dd68e25024387fef813cc25bfd2", "shasum": "" }, "require": { @@ -716,7 +716,7 @@ } ], "description": "Platform.sh API client", - "time": "2015-10-15 07:41:01" + "time": "2015-10-23 11:27:15" }, { "name": "platformsh/console-form", diff --git a/src/Command/Activity/ActivityLogCommand.php b/src/Command/Activity/ActivityLogCommand.php index b47015b8a..0a902dc29 100644 --- a/src/Command/Activity/ActivityLogCommand.php +++ b/src/Command/Activity/ActivityLogCommand.php @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) protected function displayLog(Activity $activity, OutputInterface $output, $poll = true, $interval = 1) { $logger = function ($log) use ($output) { - $output->write($log); + $output->write(preg_replace('/^/m', ' ', $log)); }; if (!$poll) { $logger($activity['log']); diff --git a/src/Command/Domain/DomainAddCommand.php b/src/Command/Domain/DomainAddCommand.php index 18aff415f..166a93b44 100644 --- a/src/Command/Domain/DomainAddCommand.php +++ b/src/Command/Domain/DomainAddCommand.php @@ -2,6 +2,8 @@ namespace Platformsh\Cli\Command\Domain; use GuzzleHttp\Exception\ClientException; +use Platformsh\Cli\Util\ActivityUtil; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,7 +18,7 @@ protected function configure() $this ->setName('domain:add') ->setDescription('Add a new domain to the project'); - $this->addProjectOption(); + $this->addProjectOption()->addNoWaitOption(); $this->addDomainOptions(); $this->setHelp('See https://docs.platform.sh/use-platform/going-live.html#1-domains'); $this->addExample('Add the domain example.com', 'example.com'); @@ -38,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } try { - $domain = $this->getSelectedProject() + $activity = $this->getSelectedProject() ->addDomain($this->domainName, $this->sslOptions); } catch (ClientException $e) { @@ -55,7 +57,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("The domain {$this->domainName} was successfully added to the project."); - $this->displayDomain($domain, $this->stdErr); + if ($activity instanceof Activity && !$input->getOption('no-wait')) { + ActivityUtil::waitAndLog($activity, $this->stdErr); + } return 0; } diff --git a/src/Command/Domain/DomainDeleteCommand.php b/src/Command/Domain/DomainDeleteCommand.php index 17d26dd48..1b926faab 100644 --- a/src/Command/Domain/DomainDeleteCommand.php +++ b/src/Command/Domain/DomainDeleteCommand.php @@ -2,6 +2,8 @@ namespace Platformsh\Cli\Command\Domain; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -17,7 +19,7 @@ protected function configure() ->setName('domain:delete') ->setDescription('Delete a domain from the project') ->addArgument('name', InputArgument::REQUIRED, 'The domain name'); - $this->addProjectOption(); + $this->addProjectOption()->addNoWaitOption(); $this->addExample('Delete the domain example.com', 'example.com'); } @@ -43,10 +45,14 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - $domain->delete(); + $activity = $domain->delete(); $this->stdErr->writeln("The domain $name has been deleted."); + if ($activity instanceof Activity && !$input->getOption('no-wait')) { + ActivityUtil::waitAndLog($activity, $this->stdErr); + } + return 0; } } diff --git a/src/Command/Domain/DomainListCommand.php b/src/Command/Domain/DomainListCommand.php index bc66305b8..768913a92 100644 --- a/src/Command/Domain/DomainListCommand.php +++ b/src/Command/Domain/DomainListCommand.php @@ -6,7 +6,6 @@ use Platformsh\Client\Model\Domain; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class DomainListCommand extends PlatformCommand diff --git a/src/Command/Environment/EnvironmentActivateCommand.php b/src/Command/Environment/EnvironmentActivateCommand.php index fe56f38a5..33e0bb7a3 100644 --- a/src/Command/Environment/EnvironmentActivateCommand.php +++ b/src/Command/Environment/EnvironmentActivateCommand.php @@ -6,7 +6,6 @@ use Platformsh\Client\Model\Environment; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class EnvironmentActivateCommand extends PlatformCommand @@ -17,10 +16,10 @@ protected function configure() $this ->setName('environment:activate') ->setDescription('Activate an environment') - ->addArgument('environment', InputArgument::IS_ARRAY, 'The environment(s) to activate') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete'); + ->addArgument('environment', InputArgument::IS_ARRAY, 'The environment(s) to activate'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Activate the environments "develop" and "stage"', 'develop stage'); } diff --git a/src/Command/Environment/EnvironmentBranchCommand.php b/src/Command/Environment/EnvironmentBranchCommand.php index df1ab7b18..48b95b2dc 100644 --- a/src/Command/Environment/EnvironmentBranchCommand.php +++ b/src/Command/Environment/EnvironmentBranchCommand.php @@ -34,12 +34,6 @@ protected function configure() InputOption::VALUE_NONE, "Create the new environment even if the branch cannot be checked out locally" ) - ->addOption( - 'no-wait', - null, - InputOption::VALUE_NONE, - 'Do not wait for the Platform.sh branch to be created' - ) ->addOption( 'build', null, @@ -47,7 +41,8 @@ protected function configure() "Build the new environment locally" ); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption("Do not wait for the environment to be branched"); $this->addExample('Create a new branch "sprint-2", based on "develop"', 'sprint-2 develop'); } @@ -167,6 +162,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $remoteSuccess = true; if (!$input->getOption('no-wait')) { + $this->stdErr->writeln('Waiting for the environment to be branched...'); $remoteSuccess = ActivityUtil::waitAndLog( $activity, $this->stdErr, diff --git a/src/Command/Environment/EnvironmentDeleteCommand.php b/src/Command/Environment/EnvironmentDeleteCommand.php index 7945c3e44..ecde96157 100644 --- a/src/Command/Environment/EnvironmentDeleteCommand.php +++ b/src/Command/Environment/EnvironmentDeleteCommand.php @@ -21,10 +21,10 @@ protected function configure() ->setDescription('Delete an environment') ->addArgument('environment', InputArgument::IS_ARRAY, 'The environment(s) to delete') ->addOption('inactive', null, InputOption::VALUE_NONE, 'Delete all inactive environments') - ->addOption('merged', null, InputOption::VALUE_NONE, 'Delete all merged environments') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete'); + ->addOption('merged', null, InputOption::VALUE_NONE, 'Delete all merged environments'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Delete the environments "test" and "example-1"', 'test example-1'); $this->addExample('Delete all inactive environments', '--inactive'); $this->addExample('Delete all environments merged with "master"', '--merged master'); diff --git a/src/Command/Environment/EnvironmentHttpAccessCommand.php b/src/Command/Environment/EnvironmentHttpAccessCommand.php index 74548ef06..20e5ecfd7 100644 --- a/src/Command/Environment/EnvironmentHttpAccessCommand.php +++ b/src/Command/Environment/EnvironmentHttpAccessCommand.php @@ -2,7 +2,9 @@ namespace Platformsh\Cli\Command\Environment; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; use Platformsh\Cli\Util\PropertyFormatter; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -36,7 +38,8 @@ protected function configure() 'Whether access control should be enabled: 1 to enable, 0 to disable' ); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Require a username and password', '--auth myname:mypassword'); $this->addExample('Restrict access to only one IP address', '--access deny:any --access allow:69.208.1.192'); $this->addExample('Remove the password requirement, keeping IP restrictions', '--auth 0'); @@ -186,17 +189,21 @@ protected function execute(InputInterface $input, OutputInterface $output) } // Patch the environment with the changes. - $selectedEnvironment->update(array('http_access' => $accessOpts)); + $activity = $selectedEnvironment->update(array('http_access' => $accessOpts)); $this->stdErr->writeln("Updated HTTP access settings for the environment $environmentId:"); $output->writeln($formatter->format($selectedEnvironment->getProperty('http_access'), 'http_access')); - if (!$selectedEnvironment->getLastActivity()) { + $success = true; + if (!$activity instanceof Activity) { $this->rebuildWarning(); } + elseif (!$input->getOption('no-wait')) { + $success = ActivityUtil::waitAndLog($activity, $this->stdErr); + } - return 0; + return $success ? 0 : 1; } } diff --git a/src/Command/Environment/EnvironmentInfoCommand.php b/src/Command/Environment/EnvironmentInfoCommand.php index 1b0516ecc..093833aee 100644 --- a/src/Command/Environment/EnvironmentInfoCommand.php +++ b/src/Command/Environment/EnvironmentInfoCommand.php @@ -2,7 +2,9 @@ namespace Platformsh\Cli\Command\Environment; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; use Platformsh\Cli\Util\PropertyFormatter; +use Platformsh\Client\Model\Activity; use Platformsh\Client\Model\Environment; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -27,7 +29,8 @@ protected function configure() ->addOption('refresh', null, InputOption::VALUE_NONE, 'Whether to refresh the cache') ->setDescription('Read or set properties for an environment'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Read all environment properties') ->addExample("Show the environment's status", 'status') ->addExample('Show the date the environment was created', 'created_at') @@ -57,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $value = $input->getArgument('value'); if ($value !== null) { - return $this->setProperty($property, $value, $environment); + return $this->setProperty($property, $value, $environment, $input->getOption('no-wait')); } $output->writeln($this->formatter->format($environment->getProperty($property), $property)); @@ -84,13 +87,14 @@ protected function listProperties(Environment $environment, OutputInterface $out } /** - * @param string $property - * @param string $value - * @param Environment $environment + * @param string $property + * @param string $value + * @param Environment $environment + * @param bool $noWait * * @return int */ - protected function setProperty($property, $value, Environment $environment) + protected function setProperty($property, $value, Environment $environment, $noWait) { if (!$this->validateValue($property, $value)) { return 1; @@ -108,18 +112,21 @@ protected function setProperty($property, $value, Environment $environment) return 0; } - $environment->update(array($property => $value)); + $activity = $environment->update(array($property => $value)); $this->stdErr->writeln("Property $property set to: " . $this->formatter->format($environment[$property], $property)); $rebuildProperties = array('enable_smtp', 'restrict_robots'); - if (in_array($property, $rebuildProperties) && !$environment->getLastActivity()) { + $success = true; + if ($activity instanceof Activity && !$noWait) { + $success = ActivityUtil::waitAndLog($activity, $this->stdErr); + } + elseif (!($activity instanceof Activity) && in_array($property, $rebuildProperties)) { $this->rebuildWarning(); } - // Refresh the stored environments. - $this->getEnvironments($this->getSelectedProject(), true); + $this->clearEnvironmentsCache(); - return 0; + return $success ? 0 : 1; } /** diff --git a/src/Command/Environment/EnvironmentMergeCommand.php b/src/Command/Environment/EnvironmentMergeCommand.php index de11191c8..60b2ababc 100644 --- a/src/Command/Environment/EnvironmentMergeCommand.php +++ b/src/Command/Environment/EnvironmentMergeCommand.php @@ -5,7 +5,6 @@ use Platformsh\Cli\Util\ActivityUtil; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class EnvironmentMergeCommand extends PlatformCommand @@ -17,10 +16,10 @@ protected function configure() ->setName('environment:merge') ->setAliases(array('merge')) ->setDescription('Merge an environment') - ->addArgument('environment', InputArgument::OPTIONAL, 'The environment to merge') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete'); + ->addArgument('environment', InputArgument::OPTIONAL, 'The environment to merge'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Merge the environment "sprint-2" into its parent', 'sprint-2'); } @@ -53,6 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $activity = $selectedEnvironment->merge(); if (!$input->getOption('no-wait')) { + $this->stdErr->writeln("Waiting for the merge to complete..."); $success = ActivityUtil::waitAndLog( $activity, $this->stdErr, diff --git a/src/Command/Environment/EnvironmentSynchronizeCommand.php b/src/Command/Environment/EnvironmentSynchronizeCommand.php index e37ac2c94..d7f1fcf16 100644 --- a/src/Command/Environment/EnvironmentSynchronizeCommand.php +++ b/src/Command/Environment/EnvironmentSynchronizeCommand.php @@ -5,7 +5,6 @@ use Platformsh\Cli\Util\ActivityUtil; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class EnvironmentSynchronizeCommand extends PlatformCommand @@ -22,10 +21,10 @@ protected function configure() InputArgument::IS_ARRAY, 'What to synchronize: code, data or both', null - ) - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete'); + ); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Synchronize data from the parent environment', 'data'); } @@ -89,6 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $activity = $selectedEnvironment->synchronize($syncData, $syncCode); if (!$input->getOption('no-wait')) { + $this->stdErr->writeln("Waiting for synchronization to complete..."); $success = ActivityUtil::waitAndLog( $activity, $this->stdErr, diff --git a/src/Command/Integration/IntegrationAddCommand.php b/src/Command/Integration/IntegrationAddCommand.php index 768b9dab0..71a4363e2 100644 --- a/src/Command/Integration/IntegrationAddCommand.php +++ b/src/Command/Integration/IntegrationAddCommand.php @@ -1,6 +1,8 @@ setName('integration:add') ->setDescription('Add an integration to the project'); $this->getForm()->configureInputDefinition($this->getDefinition()); - $this->addProjectOption(); + $this->addProjectOption()->addNoWaitOption(); $this->addExample( 'Add an integration with a GitHub repository', '--type github --repository myuser/example-repo --token UFpYS1MzQktjNw --fetch-branches 0' @@ -29,12 +31,20 @@ protected function execute(InputInterface $input, OutputInterface $output) $values = $this->getForm() ->resolveOptions($input, $this->stdErr, $this->getHelper('question')); - $integration = $this->getSelectedProject() - ->addIntegration($values['type'], $values); - $id = $integration['id']; - $this->stdErr->writeln("Integration $id created for {$values['type']}"); - - $output->writeln($this->formatIntegrationData($integration)); + $activity = $this->getSelectedProject() + ->addIntegration($values['type'], $values); + + if ($activity instanceof Activity) { + $data = $activity->payload['integration']; + $integrationId = $data['id']; + $this->stdErr->writeln("Integration $integrationId created for {$values['type']}"); + if (!$input->getOption('no-wait')) { + ActivityUtil::waitAndLog($activity, $this->stdErr); + } + } + else { + $this->stdErr->writeln("Integration created for {$values['type']}"); + } return 0; } diff --git a/src/Command/Integration/IntegrationDeleteCommand.php b/src/Command/Integration/IntegrationDeleteCommand.php index eab12cb3d..f1793ebbd 100644 --- a/src/Command/Integration/IntegrationDeleteCommand.php +++ b/src/Command/Integration/IntegrationDeleteCommand.php @@ -2,6 +2,8 @@ namespace Platformsh\Cli\Command\Integration; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -48,10 +50,14 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } - $integration->delete(); + $activity = $integration->delete(); $this->stdErr->writeln("Deleted integration $id"); + if ($activity instanceof Activity && !$input->getOption('no-wait')) { + ActivityUtil::waitAndLog($activity, $this->stdErr); + } + return 0; } diff --git a/src/Command/PlatformCommand.php b/src/Command/PlatformCommand.php index d37c40fa6..7b710f09c 100644 --- a/src/Command/PlatformCommand.php +++ b/src/Command/PlatformCommand.php @@ -690,6 +690,18 @@ protected function addAppOption() return $this->addOption('app', null, InputOption::VALUE_REQUIRED, 'The remote application name'); } + /** + * Add the --no-wait option. + * + * @param string $description + * + * @return self + */ + protected function addNoWaitOption($description = 'Do not wait for the operation to complete') + { + return $this->addOption('no-wait', null, InputOption::VALUE_NONE, $description); + } + /** * @param string $projectId * @param string $host diff --git a/src/Command/Project/ProjectInfoCommand.php b/src/Command/Project/ProjectInfoCommand.php index 617a8e105..fa1e92af1 100644 --- a/src/Command/Project/ProjectInfoCommand.php +++ b/src/Command/Project/ProjectInfoCommand.php @@ -2,7 +2,9 @@ namespace Platformsh\Cli\Command\Project; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; use Platformsh\Cli\Util\PropertyFormatter; +use Platformsh\Client\Model\Activity; use Platformsh\Client\Model\Project; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -26,7 +28,7 @@ protected function configure() ->addArgument('value', InputArgument::OPTIONAL, 'Set a new value for the property') ->addOption('refresh', null, InputOption::VALUE_NONE, 'Whether to refresh the cache') ->setDescription('Read or set properties for a project'); - $this->addProjectOption(); + $this->addProjectOption()->addNoWaitOption(); $this->addExample('Read all project properties') ->addExample("Show the project's Git URL", 'git') ->addExample("Change the project's title", 'title "My project"'); @@ -52,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $value = $input->getArgument('value'); if ($value !== null) { - return $this->setProperty($property, $value, $project); + return $this->setProperty($property, $value, $project, $input->getOption('no-wait')); } $output->writeln($this->formatter->format($project->getProperty($property), $property)); @@ -96,13 +98,14 @@ protected function listProperties(Project $project, OutputInterface $output) } /** - * @param string $property - * @param string $value - * @param Project $project + * @param string $property + * @param string $value + * @param Project $project + * @param bool $noWait * * @return int */ - protected function setProperty($property, $value, Project $project) + protected function setProperty($property, $value, Project $project, $noWait) { if (!$this->validateValue($property, $value)) { return 1; @@ -122,11 +125,17 @@ protected function setProperty($property, $value, Project $project) } $project->ensureFull(); - $project->update(array($property => $value)); + $activity = $project->update(array($property => $value)); $this->stdErr->writeln("Property $property set to: " . $this->formatter->format($value, $property)); - $this->getProjects(true); - return 0; + $this->clearProjectsCache(); + + $success = true; + if ($activity instanceof Activity && !$noWait) { + $success = ActivityUtil::waitAndLog($activity, $this->stdErr); + } + + return $success ? 0 : 1; } /** diff --git a/src/Command/Snapshot/SnapshotCreateCommand.php b/src/Command/Snapshot/SnapshotCreateCommand.php index e0e3c299e..992d63fbb 100644 --- a/src/Command/Snapshot/SnapshotCreateCommand.php +++ b/src/Command/Snapshot/SnapshotCreateCommand.php @@ -44,6 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->stdErr->writeln("Creating a snapshot of $environmentId"); if (!$input->getOption('no-wait')) { + $this->stdErr->writeln("Waiting for the snapshot to complete..."); $success = ActivityUtil::waitAndLog( $activity, $this->stdErr, diff --git a/src/Command/Snapshot/SnapshotRestoreCommand.php b/src/Command/Snapshot/SnapshotRestoreCommand.php index ab61b4591..40244a89e 100644 --- a/src/Command/Snapshot/SnapshotRestoreCommand.php +++ b/src/Command/Snapshot/SnapshotRestoreCommand.php @@ -87,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $activity = $selectedActivity->restore(); if (!$input->getOption('no-wait')) { + $this->stdErr->writeln("Waiting for the restore to complete..."); $success = ActivityUtil::waitAndLog( $activity, $this->stdErr, diff --git a/src/Command/User/UserAddCommand.php b/src/Command/User/UserAddCommand.php index ca0ca3ffc..b29ccefd4 100644 --- a/src/Command/User/UserAddCommand.php +++ b/src/Command/User/UserAddCommand.php @@ -19,9 +19,9 @@ protected function configure() ->setName('user:add') ->setDescription('Add a user to the project') ->addArgument('email', InputArgument::OPTIONAL, "The new user's email address") - ->addOption('role', null, InputOption::VALUE_REQUIRED, "The new user's role: 'admin' or 'viewer'") - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for environment(s) to be redeployed'); + ->addOption('role', null, InputOption::VALUE_REQUIRED, "The new user's role: 'admin' or 'viewer'"); $this->addProjectOption(); + $this->addNoWaitOption(); $this->addExample('Add Alice as a new administrator', 'alice@example.com --role admin'); } @@ -111,10 +111,20 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->stdErr->writeln("Adding the user to the project"); - $projectAccess = $project->addUser($email, $projectRole); + $result = $project->addUser($email, $projectRole); + + $this->stdErr->writeln("User $email created"); if (!empty($environmentRoles)) { + + if (!isset($result['_embedded']['entity']['id'])) { + $this->stdErr->writeln("Failed to find user ID from response"); + return 1; + } + $uuid = $result['_embedded']['entity']['id']; + $this->stdErr->writeln("Setting environment role(s)"); + $activities = []; foreach ($environmentRoles as $environmentId => $role) { if (!isset($environments[$environmentId])) { $this->stdErr->writeln("Environment not found: $environmentId"); @@ -123,22 +133,21 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($role == 'none') { continue; } - $access = $environments[$environmentId]->getUser($projectAccess->id); + $access = $environments[$environmentId]->getUser($uuid); if ($access) { $this->stdErr->writeln("Modifying the user's role on the environment: $environmentId"); $activity = $access->update(['role' => $role]); } else { $this->stdErr->writeln("Adding the user to the environment: $environmentId"); - $activity = $environments[$environmentId]->addUser($projectAccess->id, $role); - } - if (!$input->getOption('no-wait')) { - ActivityUtil::waitAndLog($activity, $this->stdErr); + $activities[] = $environments[$environmentId]->addUser($uuid, $role); } } + if (!$input->getOption('no-wait')) { + ActivityUtil::waitMultiple($activities, $this->stdErr); + } } - $this->stdErr->writeln("User $email created"); return 0; } diff --git a/src/Command/User/UserRoleCommand.php b/src/Command/User/UserRoleCommand.php index 131466397..376bd2267 100644 --- a/src/Command/User/UserRoleCommand.php +++ b/src/Command/User/UserRoleCommand.php @@ -93,12 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $activity = $selectedUser->changeEnvironmentRole($this->getSelectedEnvironment(), $role); $this->stdErr->writeln("User $email updated"); if (!$input->getOption('no-wait')) { - ActivityUtil::waitAndLog( - $activity, - $this->stdErr, - 'Environment redeployed successfully', - 'Failed to redeploy environment' - ); + ActivityUtil::waitAndLog($activity, $this->stdErr); } } diff --git a/src/Command/Variable/VariableDeleteCommand.php b/src/Command/Variable/VariableDeleteCommand.php index 5bc591dd0..d894f2d14 100644 --- a/src/Command/Variable/VariableDeleteCommand.php +++ b/src/Command/Variable/VariableDeleteCommand.php @@ -2,6 +2,8 @@ namespace Platformsh\Cli\Command\Variable; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -18,7 +20,8 @@ protected function configure() ->addArgument('name', InputArgument::REQUIRED, 'The variable name') ->setDescription('Delete a variable from an environment'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Delete the variable "example"', 'example'); } @@ -63,16 +66,19 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } - $variable->delete(); + $activity = $variable->delete(); $this->stdErr->writeln("Deleted variable $variableName"); - if (!$this->getSelectedEnvironment() - ->getLastActivity() - ) { + + $success = true; + if (!$activity instanceof Activity) { $this->rebuildWarning(); } + elseif (!$input->getOption('no-wait')) { + $success = ActivityUtil::waitAndLog($activity, $this->stdErr); + } - return 0; + return $success ? 0 : 1; } } diff --git a/src/Command/Variable/VariableSetCommand.php b/src/Command/Variable/VariableSetCommand.php index 9520f0d5f..98fe147fa 100644 --- a/src/Command/Variable/VariableSetCommand.php +++ b/src/Command/Variable/VariableSetCommand.php @@ -2,6 +2,8 @@ namespace Platformsh\Cli\Command\Variable; use Platformsh\Cli\Command\PlatformCommand; +use Platformsh\Cli\Util\ActivityUtil; +use Platformsh\Client\Model\Activity; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,7 +24,8 @@ protected function configure() ->addOption('json', null, InputOption::VALUE_NONE, 'Mark the value as JSON') ->setDescription('Set a variable for an environment'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample('Set the variable "example" to the string "123"', 'example 123'); $this->addExample('Set the variable "example" to the Boolean TRUE', 'example --json true'); $this->addExample('Set the variable "example" to a list of values', 'example --json \'["value1", "value2"]\''); @@ -54,23 +57,20 @@ protected function execute(InputInterface $input, OutputInterface $output) } // Set the variable to a new value. - $variable = $this->getSelectedEnvironment() + $activity = $this->getSelectedEnvironment() ->setVariable($variableName, $variableValue, $json); - if (!$variable) { - $this->stdErr->writeln("Failed to set variable $variableName"); - - return 1; - } $this->stdErr->writeln("Variable $variableName set to: $variableValue"); - if (!$this->getSelectedEnvironment() - ->getLastActivity() - ) { + $success = true; + if (!$activity instanceof Activity) { $this->rebuildWarning(); } + elseif (!$input->getOption('no-wait')) { + $success = ActivityUtil::waitAndLog($activity, $this->stdErr); + } - return 0; + return $success ? 0 : 1; } /** diff --git a/src/Util/ActivityUtil.php b/src/Util/ActivityUtil.php index 46573c4df..620b1a4bc 100644 --- a/src/Util/ActivityUtil.php +++ b/src/Util/ActivityUtil.php @@ -22,7 +22,7 @@ abstract class ActivityUtil */ public static function waitAndLog(Activity $activity, OutputInterface $output, $success = null, $failure = null) { - $output->writeln('Waiting for the remote operation to complete...'); + $output->writeln('Waiting for activity ' . $activity->id . ' (' . $activity->getDescription() . '):'); $activity->wait( null, function ($log) use ($output) { From 2a004c638dc16840308e95cc51b86b92a4cd969f Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 15:33:49 +0100 Subject: [PATCH 12/19] Even clearer drush version error output We need to see the exact command being run --- src/Helper/DrushHelper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Helper/DrushHelper.php b/src/Helper/DrushHelper.php index 016b5c7d6..d7e4a58fd 100644 --- a/src/Helper/DrushHelper.php +++ b/src/Helper/DrushHelper.php @@ -59,7 +59,8 @@ public function getVersion($reset = false) if (!$reset && isset($version)) { return $version; } - exec($this->getDrushExecutable() . ' --version', $drushVersion, $returnCode); + $command = $this->getDrushExecutable() . ' --version'; + exec($command, $drushVersion, $returnCode); if ($returnCode > 0) { $message = $returnCode == 127 ? 'Error finding Drush version' : 'Drush is not installed'; throw new \Exception($message, $returnCode); @@ -68,7 +69,7 @@ public function getVersion($reset = false) // Parse the version from the Drush output. It should be a string a bit // like " Drush Version : 8.0.0-beta14 ". if (!preg_match('/:\s*([0-9]+\.[a-z0-9\-\.]+)\s*$/', $drushVersion[0], $matches)) { - throw new \Exception("Unexpected 'drush --version' output: \n" . implode("\n", $drushVersion)); + throw new \Exception("Unexpected output from command '$command': \n" . implode("\n", $drushVersion)); } $version = $matches[1]; From 5962e17d1e3565ff195d19d5171d7bef37cb4c7d Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 15:34:55 +0100 Subject: [PATCH 13/19] addIntegration() doesn't return an activity --- .../Integration/IntegrationAddCommand.php | 23 ++++++------ .../Integration/IntegrationCommand.php | 35 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/Command/Integration/IntegrationAddCommand.php b/src/Command/Integration/IntegrationAddCommand.php index 71a4363e2..8a4a0d5bf 100644 --- a/src/Command/Integration/IntegrationAddCommand.php +++ b/src/Command/Integration/IntegrationAddCommand.php @@ -31,21 +31,22 @@ protected function execute(InputInterface $input, OutputInterface $output) $values = $this->getForm() ->resolveOptions($input, $this->stdErr, $this->getHelper('question')); - $activity = $this->getSelectedProject() + $result = $this->getSelectedProject() ->addIntegration($values['type'], $values); - if ($activity instanceof Activity) { - $data = $activity->payload['integration']; - $integrationId = $data['id']; - $this->stdErr->writeln("Integration $integrationId created for {$values['type']}"); - if (!$input->getOption('no-wait')) { - ActivityUtil::waitAndLog($activity, $this->stdErr); - } - } - else { - $this->stdErr->writeln("Integration created for {$values['type']}"); + $integrationId = $result instanceof Activity + ? $result->payload['integration']['id'] + : $result['_embedded']['entity']['id']; + + $this->stdErr->writeln("Created integration $integrationId (type: {$values['type']})"); + + if ($result instanceof Activity && !$input->getOption('no-wait')) { + $success = ActivityUtil::waitAndLog($result, $this->stdErr); } + $integration = $this->getSelectedProject()->getIntegration($integrationId); + $output->writeln($this->formatIntegrationData($integration)); + return 0; } diff --git a/src/Command/Integration/IntegrationCommand.php b/src/Command/Integration/IntegrationCommand.php index 4dfc9c3b6..65205761e 100644 --- a/src/Command/Integration/IntegrationCommand.php +++ b/src/Command/Integration/IntegrationCommand.php @@ -96,28 +96,31 @@ private function getFields() protected function formatIntegrationData(Integration $integration) { $properties = $integration->getProperties(); - $output = ''; + $info = []; if ($properties['type'] == 'github') { - $payloadUrl = $integration->hasLink('#hook') ? $integration->getLink('#hook', true) : '[unknown]'; - $output = "Repository: " . $properties['repository'] - . "\nBuild PRs: " . ($properties['build_pull_requests'] ? 'yes' : 'no') - . "\nFetch branches: " . ($properties['fetch_branches'] ? 'yes' : 'no') - . "\nPayload URL: " . $payloadUrl; + $info["Repository"] = $properties['repository']; + $info["Build PRs"] = $properties['build_pull_requests'] ? 'yes' : 'no'; + $info["Fetch branches"] = $properties['fetch_branches'] ? 'yes' : 'no'; + $info["Payload URL"] = $integration->hasLink('#hook') ? $integration->getLink('#hook', true) : '[unknown]'; } elseif ($properties['type'] == 'bitbucket') { - $payloadUrl = $integration->hasLink('#hook') ? $integration->getLink('#hook', true) : '[unknown]'; - $output = "Repository: " . $properties['repository'] - . "\nFetch branches: " . ($properties['fetch_branches'] ? 'yes' : 'no') - . "\nPrune branches: " . (!empty($properties['prune_branches']) ? 'yes' : 'no') - . "\nPayload URL: " . $payloadUrl; + $info["Repository"] = $properties['repository']; + $info["Fetch branches"] = $properties['fetch_branches'] ? 'yes' : 'no'; + $info["Prune branches"] = $properties['prune_branches'] ? 'yes' : 'no'; + $info["Payload URL"] = $integration->hasLink('#hook') ? $integration->getLink('#hook', true) : '[unknown]'; } elseif ($properties['type'] == 'hipchat') { - $output = "Room ID: " . $properties['room'] - . "\nEvents: " . implode(', ', $properties['events']) - . "\nStates: " . implode(', ', $properties['states']); + $info["Room ID"] = $properties['room']; + $info["Events"] = implode(', ', $properties['events']); + $info["States"] = implode(', ', $properties['states']); } elseif ($properties['type'] == 'webhook') { - $output = "URL: " . $properties['url']; + $info["URL"] = $properties['url']; + } + + $output = ''; + foreach ($info as $label => $value) { + $output .= "$label: $value\n"; } - return $output; + return rtrim($output); } } From 616ecd4fb7ea88263c0faf29046a169014911b22 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 15:50:10 +0100 Subject: [PATCH 14/19] Earlier feedback from domain:add --- src/Command/Domain/DomainAddCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Command/Domain/DomainAddCommand.php b/src/Command/Domain/DomainAddCommand.php index 166a93b44..04e24ddb3 100644 --- a/src/Command/Domain/DomainAddCommand.php +++ b/src/Command/Domain/DomainAddCommand.php @@ -40,6 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } try { + $this->stdErr->writeln("Adding the domain {$this->domainName}"); $activity = $this->getSelectedProject() ->addDomain($this->domainName, $this->sslOptions); } @@ -55,8 +56,6 @@ protected function execute(InputInterface $input, OutputInterface $output) throw $e; } - $this->stdErr->writeln("The domain {$this->domainName} was successfully added to the project."); - if ($activity instanceof Activity && !$input->getOption('no-wait')) { ActivityUtil::waitAndLog($activity, $this->stdErr); } From 9e6dcc3f33640abcea6272dd5d6b89eb26eab2d2 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 15:50:49 +0100 Subject: [PATCH 15/19] Grammar --- src/Util/ActivityUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/ActivityUtil.php b/src/Util/ActivityUtil.php index 620b1a4bc..acdb13d71 100644 --- a/src/Util/ActivityUtil.php +++ b/src/Util/ActivityUtil.php @@ -22,7 +22,7 @@ abstract class ActivityUtil */ public static function waitAndLog(Activity $activity, OutputInterface $output, $success = null, $failure = null) { - $output->writeln('Waiting for activity ' . $activity->id . ' (' . $activity->getDescription() . '):'); + $output->writeln('Waiting for the activity ' . $activity->id . ' (' . $activity->getDescription() . '):'); $activity->wait( null, function ($log) use ($output) { From b158014c38703054abfe080c6cea6fe59d6c6aa7 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 16:12:31 +0100 Subject: [PATCH 16/19] Deduplicate --no-wait options --- src/Command/Snapshot/SnapshotCreateCommand.php | 9 ++++----- src/Command/Snapshot/SnapshotRestoreCommand.php | 9 ++++----- src/Command/User/UserRoleCommand.php | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Command/Snapshot/SnapshotCreateCommand.php b/src/Command/Snapshot/SnapshotCreateCommand.php index 992d63fbb..fea7c94e0 100644 --- a/src/Command/Snapshot/SnapshotCreateCommand.php +++ b/src/Command/Snapshot/SnapshotCreateCommand.php @@ -5,7 +5,6 @@ use Platformsh\Cli\Util\ActivityUtil; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class SnapshotCreateCommand extends PlatformCommand @@ -15,12 +14,12 @@ protected function configure() { $this ->setName('snapshot:create') - ->setHiddenAliases(array('backup', 'environment:backup')) ->setDescription('Make a snapshot of an environment') - ->addArgument('environment', InputArgument::OPTIONAL, 'The environment') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the snapshot to complete'); + ->addArgument('environment', InputArgument::OPTIONAL, 'The environment'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption('Do not wait for the snapshot to complete'); + $this->setHiddenAliases(array('backup', 'environment:backup')); $this->setHelp('See https://docs.platform.sh/use-platform/backup-and-restore.html'); $this->addExample('Make a snapshot of the current environment'); } diff --git a/src/Command/Snapshot/SnapshotRestoreCommand.php b/src/Command/Snapshot/SnapshotRestoreCommand.php index 40244a89e..bea002679 100644 --- a/src/Command/Snapshot/SnapshotRestoreCommand.php +++ b/src/Command/Snapshot/SnapshotRestoreCommand.php @@ -5,7 +5,6 @@ use Platformsh\Cli\Util\ActivityUtil; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class SnapshotRestoreCommand extends PlatformCommand @@ -15,12 +14,12 @@ protected function configure() { $this ->setName('snapshot:restore') - ->setHiddenAliases(array('environment:restore')) ->setDescription('Restore an environment snapshot') - ->addArgument('snapshot', InputArgument::OPTIONAL, 'The name of the snapshot. Defaults to the most recent one') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete'); + ->addArgument('snapshot', InputArgument::OPTIONAL, 'The name of the snapshot. Defaults to the most recent one'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); + $this->setHiddenAliases(array('environment:restore')); $this->addExample('Restore the most recent snapshot'); $this->addExample('Restore a specific snapshot', '92c9a4b2aa75422efb3d'); } diff --git a/src/Command/User/UserRoleCommand.php b/src/Command/User/UserRoleCommand.php index 376bd2267..6e9045814 100644 --- a/src/Command/User/UserRoleCommand.php +++ b/src/Command/User/UserRoleCommand.php @@ -21,10 +21,10 @@ protected function configure() ->addArgument('email', InputArgument::REQUIRED, "The user's email address") ->addOption('role', 'r', InputOption::VALUE_REQUIRED, "A new role for the user") ->addOption('level', 'l', InputOption::VALUE_REQUIRED, "The role level ('project' or 'environment')", 'project') - ->addOption('pipe', null, InputOption::VALUE_NONE, 'Output the role only') - ->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for environment(s) to be redeployed'); + ->addOption('pipe', null, InputOption::VALUE_NONE, 'Output the role only'); $this->addProjectOption() - ->addEnvironmentOption(); + ->addEnvironmentOption() + ->addNoWaitOption(); $this->addExample("View Alice's role on the project", 'alice@example.com'); $this->addExample("View Alice's role on the environment", 'alice@example.com --level environment'); $this->addExample("Give Alice the 'contributor' role on the environment 'test'", 'alice@example.com --level environment --environment test --role contributor'); From 3e59777921e1bcad76f96e3352b37cb264afb3cf Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Wed, 14 Oct 2015 09:38:20 +0100 Subject: [PATCH 17/19] Test with normal 'composer install' too --- .travis.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index dec34d433..31c36508b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,30 @@ language: php + +sudo: false + php: - 5.4 - 5.5 - 5.6 - hhvm - 7.0 + matrix: - allow_failures: - - php: 7.0 - fast_finish: true -sudo: false + allow_failures: + - php: 7.0 + fast_finish: true + +env: + - COMPOSER_LOWEST=0 + - COMPOSER_LOWEST=1 + cache: directories: - $HOME/.composer/cache + install: - composer install --no-interaction - - travis_wait composer update --prefer-lowest --no-interaction + - if [ "$COMPOSER_LOWEST" = 1 ]; then travis_wait composer update --prefer-lowest --no-interaction; fi + script: - ./vendor/bin/phpunit -c ./phpunit.xml --coverage-text From 1027eff72485f3a99c552d914f5a1bcd67aed7ab Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Wed, 14 Oct 2015 09:55:25 +0100 Subject: [PATCH 18/19] Require higher version of ringphp, for PHP 7 compatibility --- composer.json | 1 + composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index a5d74c367..8af4ec2bb 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "license": "MIT", "require": { "doctrine/cache": "~1.4.2", + "guzzlehttp/ringphp": "^1.1", "platformsh/console-form": "0.0.4", "platformsh/client": "0.2.1", "symfony/console": "~2.5 >=2.5.2", diff --git a/composer.lock b/composer.lock index 9c3b911c9..91cedc11e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "31235139388b8ee5b6f313a91b0b4dfd", - "content-hash": "79c090325cfd9dff8c33db203781062a", + "hash": "c4e297c9dc0d730ea5c19bcbaec8cfe3", + "content-hash": "9c29f564a6842f1325c7da53e9266f87", "packages": [ { "name": "cocur/slugify", @@ -1380,16 +1380,16 @@ }, { "name": "mikey179/vfsStream", - "version": "v1.5.0", + "version": "v1.6.0", "source": { "type": "git", "url": "https://github.com/mikey179/vfsStream.git", - "reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a" + "reference": "73bcb605b741a7d5044b47592338c633788b0eb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/4dc0d2f622412f561f5b242b19b98068bbbc883a", - "reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a", + "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/73bcb605b741a7d5044b47592338c633788b0eb7", + "reference": "73bcb605b741a7d5044b47592338c633788b0eb7", "shasum": "" }, "require": { @@ -1401,7 +1401,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -1422,7 +1422,7 @@ ], "description": "Virtual file system to mock the real file system in unit tests.", "homepage": "http://vfs.bovigo.org/", - "time": "2015-03-29 11:19:49" + "time": "2015-10-06 16:59:57" }, { "name": "pear/console_table", @@ -1481,16 +1481,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.2.3", + "version": "2.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f" + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef1ca6835468857944d5c3b48fa503d5554cff2f", - "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", "shasum": "" }, "require": { @@ -1539,7 +1539,7 @@ "testing", "xunit" ], - "time": "2015-09-14 06:51:16" + "time": "2015-10-06 15:47:00" }, { "name": "phpunit/php-file-iterator", From 36d06231ec8796e67ba0e2434491777bfa2a8c8f Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Fri, 23 Oct 2015 17:05:36 +0100 Subject: [PATCH 19/19] Report errors in local:clean, and better reporting levels --- platform | 4 +++- src/Command/PlatformCommand.php | 11 +++++++++++ src/Helper/FilesystemHelper.php | 1 + src/Local/LocalBuild.php | 8 ++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/platform b/platform index 8470a320a..47f9a61db 100755 --- a/platform +++ b/platform @@ -3,7 +3,9 @@ define('CLI_ROOT', __DIR__); -error_reporting(getenv('PLATFORMSH_CLI_DEBUG') ? E_ALL : false); +// Ensure that errors are only reported once. +ini_set('display_errors', 1); +ini_set('log_errors', 0); if (file_exists(CLI_ROOT . '/vendor/autoload.php')) { require CLI_ROOT . '/vendor/autoload.php'; diff --git a/src/Command/PlatformCommand.php b/src/Command/PlatformCommand.php index 7b710f09c..643b55d38 100644 --- a/src/Command/PlatformCommand.php +++ b/src/Command/PlatformCommand.php @@ -193,6 +193,17 @@ protected function initialize(InputInterface $input, OutputInterface $output) $this->output = $output; $this->stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; self::$interactive = $input->isInteractive(); + + // Tune error reporting based on the output verbosity. + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { + error_reporting(E_ALL); + } + elseif ($output->getVerbosity() === OutputInterface::VERBOSITY_QUIET) { + error_reporting(false); + } + else { + error_reporting(E_PARSE | E_ERROR | E_USER_ERROR); + } } /** diff --git a/src/Helper/FilesystemHelper.php b/src/Helper/FilesystemHelper.php index 2a6172703..aa4627b85 100644 --- a/src/Helper/FilesystemHelper.php +++ b/src/Helper/FilesystemHelper.php @@ -73,6 +73,7 @@ public function remove($filename) try { $this->fs->remove($filename); } catch (IOException $e) { + trigger_error($e->getMessage(), E_USER_WARNING); return false; } diff --git a/src/Local/LocalBuild.php b/src/Local/LocalBuild.php index b865b9bcb..7bcd80364 100644 --- a/src/Local/LocalBuild.php +++ b/src/Local/LocalBuild.php @@ -645,8 +645,12 @@ function ($a, $b) { if (!$quiet) { $this->output->writeln("Deleting: " . basename($filename)); } - $this->fsHelper->remove($filename); - $numDeleted++; + if ($this->fsHelper->remove($filename)) { + $numDeleted++; + } + elseif (!$quiet) { + $this->output->writeln("Failed to delete: " . basename($filename) . ""); + } } else { $numKept++; }