From 948a86882c4850cafc636036d98db9f62e2651e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Mon, 10 Aug 2026 18:47:18 -0400 Subject: [PATCH 1/2] FOUR-32618 Command TENANT= php artisan route:cache is not working --- ProcessMaker/Multitenancy/SwitchTenant.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ProcessMaker/Multitenancy/SwitchTenant.php b/ProcessMaker/Multitenancy/SwitchTenant.php index f2b955e7b0..5205b5451e 100644 --- a/ProcessMaker/Multitenancy/SwitchTenant.php +++ b/ProcessMaker/Multitenancy/SwitchTenant.php @@ -46,10 +46,10 @@ public function makeCurrent(IsTenant $tenant): void return new TenantAwareBroadcastManager($app, $tenant->id); }); - // Setup tenant-specific route cache. This is needed for plugins. - if ($app->routesAreCached()) { - Env::getRepository()->set('APP_ROUTES_CACHE', storage_path('routes-v7.php')); - } + // Configure the tenant-specific route cache before Laravel checks whether it + // exists. This lets `TENANT= php artisan route:cache` create the cache + // for a tenant that does not have one yet. + Env::getRepository()->set('APP_ROUTES_CACHE', storage_path('routes-v7.php')); } /** @@ -61,6 +61,7 @@ public function forgetCurrent(): void { $app = app(); $app->useStoragePath(base_path('storage')); + Env::getRepository()->clear('APP_ROUTES_CACHE'); $this->setConfig('logging.channels.daily.path', storage_path('logs/processmaker.log')); $app->make('log')->reset(); From 2df16dede98783f34247b72e0259dfd807ea3fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Wed, 12 Aug 2026 11:33:51 -0400 Subject: [PATCH 2/2] FOUR-32618 Command TENANT= php artisan route:cache is not working - Added nolan suggestion for Octane --- ProcessMaker/Multitenancy/SwitchTenant.php | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ProcessMaker/Multitenancy/SwitchTenant.php b/ProcessMaker/Multitenancy/SwitchTenant.php index 5205b5451e..2cd9d46023 100644 --- a/ProcessMaker/Multitenancy/SwitchTenant.php +++ b/ProcessMaker/Multitenancy/SwitchTenant.php @@ -50,6 +50,7 @@ public function makeCurrent(IsTenant $tenant): void // exists. This lets `TENANT= php artisan route:cache` create the cache // for a tenant that does not have one yet. Env::getRepository()->set('APP_ROUTES_CACHE', storage_path('routes-v7.php')); + $this->reloadRouteCache($app); } /** @@ -91,6 +92,29 @@ private function setEnvironmentVariable($key, $value) $_ENV[$key] = $value; } + /** + * Reload the tenant's cached routes when the router can persist in memory. + * + * Octane keeps the router in memory between requests. The console and test + * environments may also initialize the router before a tenant is made + * current. Updating APP_ROUTES_CACHE alone is insufficient in those cases. + */ + private function reloadRouteCache(Application $app): void + { + if (!$app->routesAreCached() || !$this->shouldReinitializeRouter()) { + return; + } + + require $app->getCachedRoutesPath(); + } + + private function shouldReinitializeRouter(): bool + { + return isset($_SERVER['LARAVEL_OCTANE']) + || app()->runningInConsole() + || app()->runningUnitTests(); + } + private function overrideConfigs(Application $app, IsTenant $tenant) { $this->setEnvironmentVariable('APP_URL', $tenant->config['app.url']);