Skip to content

Commit 931c6e4

Browse files
Automatically plugin:reload when necessary
1 parent 2896200 commit 931c6e4

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

RoboFile.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public function coverage($file = null)
6868
public function updateDependenciesversion()
6969
{
7070
$this->say('Checking Terminus plugins dependencies version...');
71-
$hash = substr(sha1_file($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.lock'), 0, 10);
71+
$composerLockHash = sha1_file($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.lock');
72+
$phpVersionHash = sha1(PHP_VERSION);
73+
$hash = substr(sha1($composerLockHash . $phpVersionHash), 0, 10);
7274
$binFileContents = file_get_contents(
7375
$this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'terminus'
7476
);

bin/terminus

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSI
3232

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

3737
// Cannot use $_SERVER superglobal since that's empty during phpunit testing
3838
// getenv('HOME') isn't set on Windows and generates a Notice.

src/Terminus.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,17 @@ public function hasPlugins(): bool
603603
return count($dependencies) > 0;
604604
}
605605

606+
/**
607+
* Automatically reload plugins when dependencies are missing.
608+
*/
609+
public function autoReloadPlugins(): void
610+
{
611+
$reloadCommand = new \Pantheon\Terminus\Commands\Self\Plugin\ReloadCommand();
612+
$reloadCommand->setConfig($this->getConfig());
613+
$reloadCommand->setLogger($this->logger);
614+
$reloadCommand->reload();
615+
}
616+
606617
public static function factory($dependencies_version = null): Terminus
607618
{
608619
$input = new ArgvInput($_SERVER['argv']);
@@ -626,27 +637,32 @@ public static function factory($dependencies_version = null): Terminus
626637
$terminus = new static($config, $input, $output);
627638

628639
if ($dependencies_folder_absent && $terminus->hasPlugins()) {
629-
$omit_reload_warning = false;
630-
631640
$input_string = (string) $input;
632641
$plugin_reload_command_names = [
633642
'self:plugin:reload',
634643
'self:plugin:refresh',
635644
'plugin:reload',
636645
'plugin:refresh',
637646
];
647+
648+
$is_reload_command = false;
638649
foreach ($plugin_reload_command_names as $command_name) {
639650
if (strpos($input_string, $command_name) !== false) {
640-
$omit_reload_warning = true;
651+
$is_reload_command = true;
641652
break;
642653
}
643654
}
644655

645-
if (!$omit_reload_warning) {
646-
$terminus->logger->warning(
647-
'Could not load plugins because Terminus was upgraded. ' .
648-
'Please run terminus self:plugin:reload to refresh.',
649-
);
656+
if (!$is_reload_command) {
657+
$terminus->logger->notice('Plugins need to be reloaded due to version change. Running plugin reload...');
658+
try {
659+
$terminus->autoReloadPlugins();
660+
} catch (\Exception $e) {
661+
$terminus->logger->warning(
662+
'Could not automatically reload plugins: ' . $e->getMessage() . '. ' .
663+
'Please run terminus self:plugin:reload manually.'
664+
);
665+
}
650666
}
651667
}
652668
return $terminus;

0 commit comments

Comments
 (0)