File tree Expand file tree Collapse file tree 2 files changed +24
-25
lines changed
Expand file tree Collapse file tree 2 files changed +24
-25
lines changed Original file line number Diff line number Diff line change @@ -23,30 +23,7 @@ class RefreshArtisanCaches implements ShouldQueue
2323 */
2424 public function handle ()
2525 {
26- // Skip in testing environment because this reconnects the database
27- // meaning we loose transactions, and sets the console output verbosity
28- // to quiet so we loose expectsOutput assertions.
29- if (app ()->environment ('testing ' )) {
30- return ;
31- }
32-
33- $ options = [
34- '--no-interaction ' => true ,
35- '--quiet ' => true ,
36- ];
37-
38- if (app ()->configurationIsCached ()) {
39- // Run in a separate process to avoid the tenant being set.
40- // We do not use a tenant-specific config cache file.
41- Process::path (base_path ())
42- ->env (['TENANT ' => false , 'APP_URL ' => false ])
43- ->run (Application::formatCommandString ('config:cache ' ))->throw ();
44- } else {
45- Artisan::call ('queue:restart ' , $ options );
46-
47- // We call this manually here since this job is dispatched
48- // automatically when the config *is* cached
49- RestartMessageConsumers::dispatchSync ();
50- }
26+ // Do not rebuild the cache and restart the queue any more.
27+ // This is no longer needed.
5128 }
5229}
Original file line number Diff line number Diff line change 1616use Illuminate \Support \Arr ;
1717use Illuminate \Support \Env ;
1818use Illuminate \Support \Facades ;
19+ use Illuminate \Support \Facades \Artisan ;
1920use Illuminate \Support \Facades \Context ;
2021use Illuminate \Support \Facades \DB ;
2122use Illuminate \Support \Facades \Log ;
@@ -99,6 +100,9 @@ public function boot(): void
99100 parent ::boot ();
100101
101102 Route::pushMiddlewareToGroup ('api ' , HandleEtag::class);
103+
104+ $ this ->checkConfigCache ();
105+
102106 // Hook after service providers boot
103107 self ::$ bootTime = (microtime (true ) - self ::$ bootStart ) * 1000 ; // Convert to milliseconds
104108 }
@@ -577,4 +581,22 @@ private static function actuallyRunningInConsole(): bool
577581 {
578582 return PHP_SAPI === 'cli ' || PHP_SAPI === 'phpdbg ' ;
579583 }
584+
585+ /**
586+ * Ensure that config:cache is not run for tenant instances.
587+ */
588+ private function checkConfigCache (): void
589+ {
590+ // Only if app is running in console
591+ if (!app ()->runningInConsole ()) {
592+ return ;
593+ }
594+
595+ // Safety check to prevent config:cache from being run for tenant instances.
596+ if (config ('app.multitenancy ' ) && app ('currentTenant ' )) {
597+ Artisan::command ('config:cache ' , function () {
598+ throw new \Exception ('Cannot cache config for tenant instance. Must be run from landlord instance. ' );
599+ });
600+ }
601+ }
580602}
You can’t perform that action at this time.
0 commit comments