Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve project suspension warnings #1486

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"guzzlehttp/guzzle": "^5.3",
"guzzlehttp/ringphp": "^1.1",
"platformsh/console-form": ">=0.0.37 <2.0",
"platformsh/client": ">=0.85.0 <2.0",
"platformsh/client": ">=0.85.1 <2.0",
"symfony/console": "^3.0 >=3.2",
"symfony/yaml": "^3.0 || ^2.6",
"symfony/finder": "^3.0",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2472,4 +2472,31 @@ protected function validateResourcesInitInput(InputInterface $input, Project $pr
}
return $resourcesInit;
}

/**
* Warn the user if a project is suspended.
*
* @param \Platformsh\Client\Model\Project $project
*/
protected function warnIfSuspended(Project $project)
{
if ($project->isSuspended()) {
$this->stdErr->writeln('This project is <error>suspended</error>.');
if ($this->config()->getWithDefault('warnings.project_suspended_payment', true)) {
$orgId = $project->getProperty('organization', false);
if ($orgId) {
try {
$organization = $this->api()->getClient()->getOrganizationById($orgId);
} catch (BadResponseException $e) {
$organization = false;
}
if ($organization && $organization->hasLink('payment-source')) {
$this->stdErr->writeln(sprintf('To re-activate it, update the payment details for your organization, %s.', $this->api()->getOrganizationLabel($organization, 'comment')));
}
} elseif ($project->owner === $this->api()->getMyUserId()) {
$this->stdErr->writeln('To re-activate it, update your payment details.');
}
}
}
}
}
6 changes: 6 additions & 0 deletions src/Command/Environment/EnvironmentSshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ protected function execute(InputInterface $input, OutputInterface $output)

$exitCode = $shell->executeSimple($command, null, $ssh->getEnv());
if ($exitCode !== 0) {
if ($this->getSelectedProject()->isSuspended()) {
$this->stdErr->writeln('');
$this->warnIfSuspended($this->getSelectedProject());
return $exitCode;
}

/** @var \Platformsh\Cli\Service\SshDiagnostics $diagnostics */
$diagnostics = $this->getService('ssh_diagnostics');
$diagnostics->diagnoseFailureWithTest($sshUrl, $start, $exitCode);
Expand Down
39 changes: 14 additions & 25 deletions src/Command/WelcomeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Platformsh\Cli\Command;

use GuzzleHttp\Exception\BadResponseException;
use Platformsh\Client\Model\Project;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -70,32 +71,17 @@ private function welcomeForLocalProjectDir(Project $project)
$this->stdErr->writeln("Project ID: <info>{$project->id}</info>");
$this->stdErr->writeln("Project dashboard: <info>" . $this->api()->getConsoleURL($project) . "</info>\n");

// Show the environments.
$this->runOtherCommand('environments', [
'--project' => $project->id,
]);
$executable = $this->config()->get('application.executable');
$this->stdErr->writeln("\nYou can list other projects by running <info>$executable projects</info>");
}

/**
* Warn the user if a project is suspended.
*
* @param \Platformsh\Client\Model\Project $project
*/
private function warnIfSuspended(Project $project)
{
if ($project->isSuspended()) {
$messages = [];
$messages[] = '<comment>This project is suspended.</comment>';
if ($this->config()->getWithDefault('warnings.project_suspended_payment', true)) {
if ($project->owner === $this->api()->getMyUserId()) {
$messages[] = '<comment>Update your payment details to re-activate it</comment>';
}
}
$messages[] = '';
$this->stdErr->writeln($messages);
$this->warnIfSuspended($project);
} else {
// Show the environments.
$this->runOtherCommand('environments', [
'--project' => $project->id,
]);
}

$executable = $this->config()->get('application.executable');
$this->stdErr->writeln("\nYou can list other projects by running <info>$executable projects</info>");
}

/**
Expand Down Expand Up @@ -128,7 +114,10 @@ private function welcomeOnContainer()
$this->stdErr->writeln('Application name: <info>' . $appName . '</info>');
}

$this->warnIfSuspended($project);
if ($project->isSuspended()) {
$this->warnIfSuspended($project);
return;
}
} else {
$this->stdErr->writeln('Project ID: <info>' . $projectId . '</info>');
if ($environmentId) {
Expand Down