Skip to content

Commit 7bd3713

Browse files
committed
Fix for non-multitenant instances
1 parent 2e28e1a commit 7bd3713

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

ProcessMaker/Console/Commands/TenantsVerify.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace ProcessMaker\Console\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Contracts\Encryption\DecryptException;
67
use Illuminate\Support\Facades\Config;
8+
use Illuminate\Support\Facades\Crypt;
79
use Illuminate\Support\Facades\File;
810
use Illuminate\Support\Facades\Log;
911
use ProcessMaker\Models\EnvironmentVariable;
@@ -26,17 +28,6 @@ class TenantsVerify extends Command
2628
*/
2729
protected $description = 'Verify tenant configuration and storage paths';
2830

29-
/**
30-
* Strip protocol from URL
31-
*
32-
* @param string $url
33-
* @return string
34-
*/
35-
private function stripProtocol(string $url): string
36-
{
37-
return preg_replace('#^https?://#', '', $url);
38-
}
39-
4031
/**
4132
* Execute the console command.
4233
*
@@ -49,13 +40,13 @@ public function handle()
4940
$currentTenant = app('currentTenant');
5041
}
5142

52-
if (!$currentTenant) {
53-
$this->error('No current tenant found');
43+
if (config('app.multitenancy') && !$currentTenant) {
44+
$this->error('Multitenancy enabled but current tenant found.');
5445

5546
return;
5647
}
5748

58-
$this->info('Current Tenant ID: ' . $currentTenant->id);
49+
$this->info('Current Tenant ID: ' . ($currentTenant?->id ?? 'NONE'));
5950

6051
$paths = [
6152
['Storage Path', storage_path()],
@@ -88,14 +79,26 @@ public function handle()
8879
// Display configs in a nice table
8980
$this->table(['Config', 'Value'], $configs);
9081

82+
$env = EnvironmentVariable::first();
83+
if (!$env) {
84+
$decrypted = 'No environment variables found to test decryption';
85+
}
86+
$encryptedValue = $env->getAttributes()['value'];
87+
try {
88+
Crypt::decryptString($encryptedValue);
89+
$decrypted = 'OK';
90+
} catch (DecryptException $e) {
91+
$decrypted = 'FAILED! ' . $e->getMessage();
92+
}
93+
9194
$other = [
9295
['Landlord Config Cache Path', base_path('bootstrap/cache/config.php')],
9396
['Landlord Config Is Cached', File::exists(base_path('bootstrap/cache/config.php')) ? 'Yes' : 'No'],
9497
['Tenant Config Cache Path', app()->getCachedConfigPath()],
9598
['Tenant Config Is Cached', File::exists(app()->getCachedConfigPath()) ? 'Yes' : 'No'],
9699
['First username (database check)', User::first()->username],
97-
['First environment variable (decrypted check)', substr(EnvironmentVariable::first()->value, 0, 15)],
98-
['Original App URL (landlord)', $currentTenant->getOriginalValue('APP_URL')],
100+
['Decrypted check', substr($decrypted, 0, 50)],
101+
['Original App URL (landlord)', $currentTenant?->getOriginalValue('APP_URL') ?? config('app.url')],
99102
];
100103

101104
// Display other in a nice table

ProcessMaker/Multitenancy/TenantFinder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class TenantFinder extends DomainTenantFinder
1212
{
1313
public function findForRequest(Request $request): ?IsTenant
1414
{
15+
if (!config('app.multitenancy')) {
16+
return null;
17+
}
18+
1519
if ($tenant = Tenant::fromBootstrapper()) {
1620
return $tenant;
1721
}

ProcessMaker/Providers/ProcessMakerServiceProvider.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,21 +525,25 @@ private function setCurrentTenantForConsoleCommands(): void
525525
return;
526526
}
527527

528+
if (config('app.multitenancy') === false) {
529+
event(new TenantResolved(null));
530+
531+
return;
532+
}
533+
528534
if ($tenant = Tenant::fromBootstrapper()) {
529535
$tenant->makeCurrent();
530536

531537
return;
532538
}
533539

534540
$tenantId = Env::get('TENANT');
535-
if ($tenantId) {
536-
$tenant = Tenant::findOrFail($tenantId);
537-
$tenant->makeCurrent();
538-
} elseif (config('app.multitenancy') === false) {
539-
// This is expected if multitenancy is disabled.
540-
// Call the TenantResolved event with null to continue loading the app.
541-
event(new TenantResolved(null));
541+
if (!$tenantId) {
542+
throw new \Exception('Multitenancy is enabled but no tenant ID was found in the environment.');
542543
}
544+
545+
$tenant = Tenant::findOrFail($tenantId);
546+
$tenant->makeCurrent();
543547
}
544548

545549
/**

0 commit comments

Comments
 (0)