@@ -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