Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ProcessMaker/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
23 changes: 8 additions & 15 deletions ProcessMaker/Multitenancy/TenantBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 === []) {
Expand Down
40 changes: 2 additions & 38 deletions ProcessMaker/Providers/ProcessMakerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,51 +254,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.
*/
Expand All @@ -312,10 +280,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) {
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -229,4 +231,4 @@
"tbachert/spi": true
}
}
}
}
51 changes: 28 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading