@@ -92,7 +92,7 @@ public function install(string $repoUrl, ?string $branch = null, ?string $tag =
9292 $ this ->logRunning ('Running plugin install command... ' , $ repoName , $ userId );
9393 $ this ->runCommand ($ installCommand , $ repoName , $ userId );
9494
95- $ this ->rebuildRouteCache ($ repoName , $ userId );
95+ $ this ->refreshRuntimeAfterPluginChange ($ repoName , $ userId );
9696
9797 $ this ->logDone ('Plugin installed successfully ' , $ repoName , $ userId );
9898 }
@@ -127,7 +127,7 @@ public function uninstall(string $pluginName, ?int $userId = null): void
127127 $ this ->logRunning ('Removing plugin directory... ' , $ pluginName , $ userId );
128128 $ this ->deleteDirectory ($ pluginPath , $ pluginName , $ userId );
129129
130- $ this ->rebuildRouteCache ($ pluginName , $ userId );
130+ $ this ->refreshRuntimeAfterPluginChange ($ pluginName , $ userId );
131131
132132 $ this ->logDone ('Plugin uninstalled successfully ' , $ pluginName , $ userId );
133133 }
@@ -145,18 +145,24 @@ private function runCommand(string $command, string $pluginName, ?int $userId =
145145
146146 if (!$ result ->successful ()) {
147147 if (str_contains ($ result ->output (), 'is not defined ' )) {
148- \Log::info ("Plugin does not have a {$ command } command " , ['output ' => $ result ->output ()]);
149148 $ this ->logRunning ("Plugin does not have a {$ command } command " , $ pluginName , $ userId );
150149 } else {
151- \Log::info ("Plugin {$ command } command failed. Got output: \n\n{$ result ->output ()}" , ['output ' => $ result ->output ()]);
152150 $ this ->logError ("Plugin {$ command } command failed. Got output: \n\n{$ result ->output ()}" , $ pluginName , $ userId );
153151 }
154152 } else {
155- \Log::info ("Plugin {$ command } command output: \n\n{$ result ->output ()}" , ['output ' => $ result ->output ()]);
156153 $ this ->logRunning ("Plugin {$ command } command output: \n\n{$ result ->output ()}" , $ pluginName , $ userId );
157154 }
158155 }
159156
157+ /**
158+ * Refresh routes and queue workers after plugin code changes.
159+ */
160+ private function refreshRuntimeAfterPluginChange (string $ pluginName , ?int $ userId = null ): void
161+ {
162+ $ this ->rebuildRouteCache ($ pluginName , $ userId );
163+ $ this ->terminateHorizon ($ pluginName , $ userId );
164+ }
165+
160166 /**
161167 * Rebuild the tenant's route cache in a fresh artisan process.
162168 *
@@ -172,6 +178,15 @@ private function rebuildRouteCache(string $pluginName, ?int $userId = null): voi
172178 $ this ->reloadCachedRoutes ();
173179 }
174180
181+ /**
182+ * Always stop current Horizon workers so a new process picks up plugin code.
183+ */
184+ private function terminateHorizon (string $ pluginName , ?int $ userId = null ): void
185+ {
186+ $ this ->logRunning ('Restarting queue workers... ' , $ pluginName , $ userId );
187+ $ this ->runCommand ('horizon:terminate ' , $ pluginName , $ userId );
188+ }
189+
175190 /**
176191 * Environment variables for artisan subprocesses started from a web request.
177192 */
@@ -273,7 +288,7 @@ public function installFromZip(string $zipPath, ?int $userId = null): void
273288 $ this ->logRunning ('Running plugin install command... ' , $ repoName , $ userId );
274289 $ this ->runCommand ($ installCommand , $ repoName , $ userId );
275290
276- $ this ->rebuildRouteCache ($ repoName , $ userId );
291+ $ this ->refreshRuntimeAfterPluginChange ($ repoName , $ userId );
277292
278293 $ this ->logDone ('Plugin installed successfully ' , $ repoName , $ userId );
279294 } finally {
@@ -311,7 +326,7 @@ public function toggle(string $pluginName, ?int $userId = null): bool
311326 throw new RuntimeException ("Failed to disable plugin: {$ pluginName }" );
312327 }
313328
314- $ this ->rebuildRouteCache ($ pluginName , $ userId );
329+ $ this ->refreshRuntimeAfterPluginChange ($ pluginName , $ userId );
315330
316331 return false ;
317332 }
@@ -325,7 +340,7 @@ public function toggle(string $pluginName, ?int $userId = null): bool
325340 throw new RuntimeException ("Failed to enable plugin: {$ pluginName }" );
326341 }
327342
328- $ this ->rebuildRouteCache ($ enabledName , $ userId );
343+ $ this ->refreshRuntimeAfterPluginChange ($ enabledName , $ userId );
329344
330345 return true ;
331346 }
@@ -775,16 +790,14 @@ protected function logDone(string $message, string $pluginName, ?int $userId = n
775790 */
776791 protected function log (string $ message , string $ type , string $ pluginName , ?int $ userId = null ): void
777792 {
793+ if ($ type === 'error ' ) {
794+ \Log::error ($ message );
795+ } else {
796+ \Log::info ($ message );
797+ }
798+
778799 if ($ userId ) {
779800 event (new PluginLog ($ message , $ type , $ pluginName , $ userId ));
780- } else {
781- if ($ type === 'done ' ) {
782- \Log::info ($ message );
783- } elseif ($ type === 'error ' ) {
784- \Log::error ($ message );
785- } else {
786- \Log::info ($ message );
787- }
788801 }
789802 }
790803}
0 commit comments