diff --git a/ProcessMaker/Application.php b/ProcessMaker/Application.php index b459358dd3..87f85281df 100644 --- a/ProcessMaker/Application.php +++ b/ProcessMaker/Application.php @@ -3,6 +3,7 @@ namespace ProcessMaker; use Igaster\LaravelTheme\Facades\Theme; +use Illuminate\Container\Container; use Illuminate\Filesystem\Filesystem; use Illuminate\Foundation\Application as IlluminateApplication; use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Config; +use ProcessMaker\Console\Kernel; use ProcessMaker\Multitenancy\Tenant; use ProcessMaker\Multitenancy\TenantBootstrapper; @@ -112,4 +114,11 @@ public function bootstrapWith(array $bootstrappers) return parent::bootstrapWith($bootstrappers); } + + public function reactivateConsoleApp() + { + Container::setInstance($this); + $this->hasBeenBootstrapped = false; + $this->make(Kernel::class)->bootstrap(); + } } diff --git a/ProcessMaker/Multitenancy/TenantBootstrapper.php b/ProcessMaker/Multitenancy/TenantBootstrapper.php index 7475dfef13..7ab897f0e8 100644 --- a/ProcessMaker/Multitenancy/TenantBootstrapper.php +++ b/ProcessMaker/Multitenancy/TenantBootstrapper.php @@ -26,21 +26,6 @@ class TenantBootstrapper private $app = null; - public static $landlordKeysToSave = [ - 'APP_URL', - 'APP_KEY', - 'LOG_PATH', - 'DB_USERNAME', - 'DB_PASSWORD', - 'DB_HOSTNAME', - 'DB_PORT', - 'LANDLORD_DB_DATABASE', - 'REDIS_PREFIX', - 'CACHE_SETTING_PREFIX', - 'SCRIPT_MICROSERVICE_CALLBACK', - 'CACHE_PREFIX', - ]; - public function bootstrap(Application $app) { try { @@ -116,6 +101,14 @@ private function setTenantEnvironmentVariables($tenantData) $this->set('LOG_PATH', $this->app->storagePath('logs/processmaker.log')); } + // Used for debugging + public static function log($message) + { + $message = '[TenantBootstrapper] ' . $message; + $today = date('Y-m-d'); + file_put_contents(base_path('storage/logs/processmaker-' . $today . '.log'), date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL, FILE_APPEND); + } + private function getOriginalValue($key, $default = '') { if (self::$landlordValues === []) { diff --git a/ProcessMaker/Providers/ProcessMakerServiceProvider.php b/ProcessMaker/Providers/ProcessMakerServiceProvider.php index bcc66fbba8..355953c1eb 100644 --- a/ProcessMaker/Providers/ProcessMakerServiceProvider.php +++ b/ProcessMaker/Providers/ProcessMakerServiceProvider.php @@ -258,51 +258,19 @@ private static function bootstrapTenantApp(JobProcessing|JobRetryRequested $even return; } - // Save the landlord's config values so we can reset them later - if (self::$landlordValues === null) { - foreach (TenantBootstrapper::$landlordKeysToSave as $key) { - self::$landlordValues[$key] = $_SERVER[$key] ?? ''; - } - } - // Create a new tenant app instance $_SERVER['TENANT'] = $tenantId; - $_ENV['TENANT'] = $tenantId; if (!isset(self::$tenantAppContainers[$tenantId])) { - $tenantApp = require app()->bootstrapPath('app.php'); - $tenantApp->instance('landlordValues', self::$landlordValues); - $tenantApp->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); - self::$tenantAppContainers[$tenantId] = $tenantApp; + self::$tenantAppContainers[$tenantId] = require base_path('bootstrap/app.php'); } + self::$tenantAppContainers[$tenantId]->reactivateConsoleApp(); // Change the job's app service container to the tenant app $event->job->getRedisQueue()->setContainer(self::$tenantAppContainers[$tenantId]); } } - private static function resetTenantApp($event): void - { - if (!method_exists($event->job, 'getRedisQueue')) { - // Not a redis job - return; - } - - unset($_SERVER['TENANT']); - unset($_ENV['TENANT']); - - if (!self::$landlordValues) { - return; - } - - // Restore the original values since the tenant boostrapper modified them - foreach (self::$landlordValues as $key => $value) { - $_SERVER[$key] = $value; - $_ENV[$key] = $value; - putenv("$key=$value"); - } - } - /** * Register app-level events. */ @@ -316,10 +284,6 @@ protected static function registerEvents(): void self::bootstrapTenantApp($event); }); - Facades\Event::listen(JobAttempted::class, function (JobAttempted $event) { - self::resetTenantApp($event); - }); - // Listen to the events for our core screen // types and add our javascript Facades\Event::listen(ScreenBuilderStarting::class, function ($event) { diff --git a/composer.json b/composer.json index 3289e29ee2..22e7c0bb99 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "guzzlehttp/guzzle": "^7.9", "igaster/laravel-theme": "^2.0", "jenssegers/agent": "^2.6", - "laravel/framework": "^11.0", + "laravel/framework": "^11.44.1", "laravel/horizon": "^5.30", "laravel/pail": "^1.2", "laravel/passport": "^12.3", @@ -33,6 +33,7 @@ "laravel/ui": "^4.6", "lavary/laravel-menu": "^1.8", "lcobucci/jwt": "^4.2", + "league/commonmark": "^2.7", "league/flysystem-aws-s3-v3": "^3.29", "mateusjunges/laravel-kafka": "^2.4", "mittwald/vault-php": "^2.1", @@ -63,6 +64,7 @@ "spatie/laravel-multitenancy": "^4.0", "spomky-labs/otphp": "^11.3", "symfony/expression-language": "^7.2", + "symfony/http-foundation": "^7.3", "teamtnt/laravel-scout-tntsearch-driver": "^14.0", "twilio/sdk": "^8.3", "typo3/class-alias-loader": "^1.2", @@ -229,4 +231,4 @@ "tbachert/spi": true } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index ebeba822fb..e254da25b5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "515c98c58265bbe08807b0cca8f55a8c", + "content-hash": "7b1bd0f76a6238e4f322305dee717161", "packages": [ { "name": "aws/aws-crt-php", @@ -2806,16 +2806,16 @@ }, { "name": "laravel/framework", - "version": "v11.43.2", + "version": "v11.44.7", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "99d1573698abc42222f04d25fcd5b213d0eedf21" + "reference": "00bc6ac91a6d577bf051c18ddaa638c0d221e1c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/99d1573698abc42222f04d25fcd5b213d0eedf21", - "reference": "99d1573698abc42222f04d25fcd5b213d0eedf21", + "url": "https://api.github.com/repos/laravel/framework/zipball/00bc6ac91a6d577bf051c18ddaa638c0d221e1c7", + "reference": "00bc6ac91a6d577bf051c18ddaa638c0d221e1c7", "shasum": "" }, "require": { @@ -2923,7 +2923,7 @@ "league/flysystem-read-only": "^3.25.1", "league/flysystem-sftp-v3": "^3.25.1", "mockery/mockery": "^1.6.10", - "orchestra/testbench-core": "^9.9.4", + "orchestra/testbench-core": "^9.11.2", "pda/pheanstalk": "^5.0.6", "php-http/discovery": "^1.15", "phpstan/phpstan": "^2.0", @@ -3017,7 +3017,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2025-02-19T21:53:48+00:00" + "time": "2025-04-25T12:40:47+00:00" }, { "name": "laravel/horizon", @@ -3848,16 +3848,16 @@ }, { "name": "league/commonmark", - "version": "2.6.1", + "version": "2.7.1", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "d990688c91cedfb69753ffc2512727ec646df2ad" + "reference": "10732241927d3971d28e7ea7b5712721fa2296ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d990688c91cedfb69753ffc2512727ec646df2ad", - "reference": "d990688c91cedfb69753ffc2512727ec646df2ad", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/10732241927d3971d28e7ea7b5712721fa2296ca", + "reference": "10732241927d3971d28e7ea7b5712721fa2296ca", "shasum": "" }, "require": { @@ -3886,7 +3886,7 @@ "symfony/process": "^5.4 | ^6.0 | ^7.0", "symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 | ^7.0", "unleashedtech/php-coding-standard": "^3.1.1", - "vimeo/psalm": "^4.24.0 || ^5.0.0" + "vimeo/psalm": "^4.24.0 || ^5.0.0 || ^6.0.0" }, "suggest": { "symfony/yaml": "v2.3+ required if using the Front Matter extension" @@ -3894,7 +3894,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.7-dev" + "dev-main": "2.8-dev" } }, "autoload": { @@ -3951,7 +3951,7 @@ "type": "tidelift" } ], - "time": "2024-12-29T14:10:59+00:00" + "time": "2025-07-20T12:47:49+00:00" }, { "name": "league/config", @@ -10006,16 +10006,16 @@ }, { "name": "symfony/http-foundation", - "version": "v7.2.3", + "version": "v7.3.7", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "ee1b504b8926198be89d05e5b6fc4c3810c090f0" + "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/ee1b504b8926198be89d05e5b6fc4c3810c090f0", - "reference": "ee1b504b8926198be89d05e5b6fc4c3810c090f0", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/db488a62f98f7a81d5746f05eea63a74e55bb7c4", + "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4", "shasum": "" }, "require": { @@ -10032,6 +10032,7 @@ "doctrine/dbal": "^3.6|^4", "predis/predis": "^1.1|^2.0", "symfony/cache": "^6.4.12|^7.1.5", + "symfony/clock": "^6.4|^7.0", "symfony/dependency-injection": "^6.4|^7.0", "symfony/expression-language": "^6.4|^7.0", "symfony/http-kernel": "^6.4|^7.0", @@ -10064,7 +10065,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v7.2.3" + "source": "https://github.com/symfony/http-foundation/tree/v7.3.7" }, "funding": [ { @@ -10075,12 +10076,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-01-17T10:56:55+00:00" + "time": "2025-11-08T16:41:12+00:00" }, { "name": "symfony/http-kernel", @@ -15214,5 +15219,5 @@ "php": "^8.3" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" }