Skip to content
Draft
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
4 changes: 3 additions & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function coverage($file = null)
public function updateDependenciesversion()
{
$this->say('Checking Terminus plugins dependencies version...');
$hash = substr(sha1_file($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.lock'), 0, 10);
$composerLockHash = sha1_file($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.lock');
$phpVersionHash = sha1(PHP_VERSION);
$hash = substr(sha1($composerLockHash . $phpVersionHash), 0, 10);
$binFileContents = file_get_contents(
$this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'terminus'
);
Expand Down
2 changes: 1 addition & 1 deletion bin/terminus
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSI

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = 'c788000802';
$terminusPluginsDependenciesVersion = '3963905812';

// Cannot use $_SERVER superglobal since that's empty during phpunit testing
// getenv('HOME') isn't set on Windows and generates a Notice.
Expand Down
32 changes: 24 additions & 8 deletions src/Terminus.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,17 @@ public function hasPlugins(): bool
return count($dependencies) > 0;
}

/**
* Automatically reload plugins when dependencies are missing.
*/
public function autoReloadPlugins(): void
{
$reloadCommand = new \Pantheon\Terminus\Commands\Self\Plugin\ReloadCommand();
$reloadCommand->setConfig($this->getConfig());
$reloadCommand->setLogger($this->logger);
$reloadCommand->reload();
}

public static function factory($dependencies_version = null): Terminus
{
$input = new ArgvInput($_SERVER['argv']);
Expand All @@ -626,27 +637,32 @@ public static function factory($dependencies_version = null): Terminus
$terminus = new static($config, $input, $output);

if ($dependencies_folder_absent && $terminus->hasPlugins()) {
$omit_reload_warning = false;

$input_string = (string) $input;
$plugin_reload_command_names = [
'self:plugin:reload',
'self:plugin:refresh',
'plugin:reload',
'plugin:refresh',
];

$is_reload_command = false;
foreach ($plugin_reload_command_names as $command_name) {
if (strpos($input_string, $command_name) !== false) {
$omit_reload_warning = true;
$is_reload_command = true;
break;
}
}

if (!$omit_reload_warning) {
$terminus->logger->warning(
'Could not load plugins because Terminus was upgraded. ' .
'Please run terminus self:plugin:reload to refresh.',
);
if (!$is_reload_command) {
$terminus->logger->notice('Plugins need to be reloaded due to version change. Running plugin reload...');
try {
$terminus->autoReloadPlugins();
} catch (\Exception $e) {
$terminus->logger->warning(
'Could not automatically reload plugins: ' . $e->getMessage() . '. ' .
'Please run terminus self:plugin:reload manually.'
);
}
}
}
return $terminus;
Expand Down
Loading