Skip to content
21 changes: 21 additions & 0 deletions src/Commands/Env/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Pantheon\Terminus\Commands\StructuredListTrait;
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;
use Pantheon\Terminus\Models\TerminusModel;

/**
* Class InfoCommand.
Expand Down Expand Up @@ -49,4 +50,24 @@ public function info($site_env)

return $this->getPropertyList($this->getEnv($site_env));
}

/**
* @param TerminusModel $model A model with data to extract
* @return PropertyList A PropertyList-type object with applied filters
*/
public function getPropertyList(TerminusModel $model)
{
$properties = $model->serialize();
if ($model->isEvcsSite()) {
// Remove properties that are not applicable to EVCS sites
unset($properties['connection_mode']);
}
if ($model->getSite()->isNodejs()) {
// Remove properties that are not applicable to Node.js sites
unset($properties['drush_version']);
unset($properties['php_version']);
unset($properties['locked']);
}
return new PropertyList($properties);
}
}
5 changes: 5 additions & 0 deletions src/Commands/Env/WakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function wake($site_env, $options = [
]);
throw new TerminusException('Could not reach {target}', $wakeStatus);
}
if ($env->getSite()->isNodejs()) {
// We do not expect a 'styx' header for Node.js sites so if we make it here, we assume success.
$this->log()->notice('OK >> {target} responded', $wakeStatus);
return;
}
if (empty($wakeStatus['styx'])) {
throw new TerminusException('Pantheon headers missing, which is not quite right.');
}
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/Local/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Pantheon\Terminus\Exceptions\TerminusException;

/**
* Class CloneCommand.
Expand Down Expand Up @@ -47,6 +48,13 @@ public function clone(
array $options = ['site_dir' => null, 'override' => null, 'branch' => 'master']
): string {
$site = $this->getSiteById($site_id);

if ($site->isEvcs()) {
throw new TerminusException(
'This command is not supported for sites with external vcs. Please clone from your external repository.'
);
}

$env = $site->getEnvironments()->get('dev');

$gitUrl = $env->connectionInfo()['git_url'] ?? null;
Expand Down
7 changes: 7 additions & 0 deletions src/Commands/Local/CommitAndPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public function commitAndPushCommand($site): string
);
}
}

if ($siteData->isEvcs()) {
throw new TerminusException(
'This command is not supported for sites with external vcs. Please clone from your external repository.'
);
}

$git = new \CzProject\GitPhp\Git();
$repo = $git->open($siteData->getLocalCopyDir());
$repo->addAllChanges();
Expand Down
9 changes: 8 additions & 1 deletion src/Commands/Lock/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Pantheon\Terminus\Commands\StructuredListTrait;
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;
use Pantheon\Terminus\Exceptions\TerminusException;

/**
* Class InfoCommand.
Expand Down Expand Up @@ -40,6 +41,12 @@ class InfoCommand extends TerminusCommand implements SiteAwareInterface
*/
public function info($site_env)
{
return $this->getPropertyList($this->getEnv($site_env)->getLock());
$env = $this->getEnv($site_env);
if ($env->getSite()->isNodejs()) {
throw new TerminusException(
'Locking is not supported for Node.js sites.'
);
}
return $this->getPropertyList($env->getLock());
}
}
7 changes: 7 additions & 0 deletions src/Commands/Multidev/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public function create(
) {
$this->requireSiteIsNotFrozen($site_env);
$site = $this->getSiteById($site_env);

if ($site->isEvcs()) {
throw new \Pantheon\Terminus\Exceptions\TerminusException(
'Multidev environments should be created from your external repository for this site.'
);
}

$env = $this->getEnv($site_env);

if (strlen($multidev) > 11) {
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/Multidev/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function deleteMultidev($site_env, $options = ['delete-branch' => false,]
return;
}

if ($options['delete-branch'] && $env->isEvcsSite()) {
$this->log()->warning(
'Cannot delete the branch for {env} because it is an external version control site.',
['env' => $env->getName()]
);
$options['delete-branch'] = false;
}

$workflow = $env->delete(['delete_branch' => $options['delete-branch'] ?? false]);
$this->processWorkflow($workflow);
$this->log()->notice(
Expand Down
6 changes: 6 additions & 0 deletions src/Commands/Remote/SSHBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ protected function prepareEnvironment($site_env)
{
$this->site = $this->getSiteById($site_env);
$this->environment = $this->getEnv($site_env);

if ($this->site->isNodejs()) {
throw new TerminusProcessException(
'This command is not supported for Node.js sites.'
);
}
}

/**
Expand Down
29 changes: 27 additions & 2 deletions src/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function connectionInfo()
);

// Can only Use Git on dev/multidev environments
if (!in_array($this->id, ['test', 'live',])) {
if (!in_array($this->id, ['test', 'live',]) && !$this->isEvcsSite()) {
$git_info = $this->gitConnectionInfo();
$info = array_merge(
array_combine(
Expand All @@ -271,6 +271,13 @@ public function connectionInfo()
);
}

if (empty($info)) {
throw new TerminusException(
'No connection information available for {env} environment for this site.',
['env' => $this->id,]
);
}

return $info;
}

Expand All @@ -281,6 +288,10 @@ public function connectionInfo()
*/
public function cacheserverConnectionInfo()
{
if ($this->getSite()->isNodejs()) {
// No database for Node.js sites
return [];
}
$env_vars = $this->fetchEnvironmentVars();
$port = $env_vars['CACHE_PORT'] ?? null;
$password = $env_vars['CACHE_PASSWORD'] ?? null;
Expand Down Expand Up @@ -327,6 +338,10 @@ public function fetchEnvironmentVars(): array
*/
public function databaseConnectionInfo()
{
if ($this->getSite()->isNodejs()) {
// No database for Node.js sites
return [];
}
$env_vars = $this->fetchEnvironmentVars();
$domain = "dbserver.{$this->id}.{$this->getSite()->id}.drush.in";
$port = $env_vars['DB_PORT'] ?? null;
Expand Down Expand Up @@ -965,6 +980,10 @@ public function setHttpsCertificate($certificate = [])
*/
public function sftpConnectionInfo()
{
if ($this->isEvcsSite()) {
// No SFTP for EVCS sites
return [];
}
$site = $this->getSite();
if (!empty($ssh_host = $this->getConfig()->get('ssh_host'))) {
$username = "appserver.{$this->id}.{$site->id}";
Expand Down Expand Up @@ -1021,12 +1040,18 @@ function ($domain) {
$success = false;
$lastError = null;

$wakeUrl = "https://{$domain->id}/pantheon_healthcheck";
if ($this->getSite()->isNodejs()) {
// For Node.js sites, we use the root path for the health check.
$wakeUrl = "https://{$domain->id}";
}

while ($attempt < $maxRetries && !$success) {
$lastError = null;
$attempt++;
try {
$response = $this->request()->request(
"https://{$domain->id}/pantheon_healthcheck"
$wakeUrl,
);
$success = ($response['status_code'] === 200);
if ($success) {
Expand Down
27 changes: 27 additions & 0 deletions src/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,31 @@ public function getWorkflowLogs(): WorkflowLogsCollection
->addArgument($this);
return $this->getContainer()->get($nickname)->fetch();
}

/**
* @return bool
* @throws TerminusException
*/
public function isEvcs(): bool
{
// We are using a variable that we retrieve at environment level,
// so we need to retrieve dev environment first.
$env = $this->getEnvironments()->get('dev');
if (empty($env)) {
throw new TerminusException(
'Site {site} does not have a dev environment.',
['site' => $this->getName()]
);
}
return $env->isEvcsSite();
}

/**
* @return bool
* @throws TerminusException
*/
public function isNodejs(): bool
{
return $this->get('framework') === 'nodejs';
}
}
Loading