33namespace ProcessMaker \Console \Commands ;
44
55use Illuminate \Console \Command ;
6+ use Illuminate \Contracts \Encryption \DecryptException ;
67use Illuminate \Support \Facades \Config ;
8+ use Illuminate \Support \Facades \Crypt ;
9+ use Illuminate \Support \Facades \File ;
710use Illuminate \Support \Facades \Log ;
11+ use ProcessMaker \Models \EnvironmentVariable ;
12+ use ProcessMaker \Models \User ;
813use Spatie \Multitenancy \Models \Tenant ;
914
1015class TenantsVerify extends Command
@@ -14,7 +19,7 @@ class TenantsVerify extends Command
1419 *
1520 * @var string
1621 */
17- protected $ signature = 'tenants:verify {--verify-against= : The tenant ID to verify against} ' ;
22+ protected $ signature = 'tenants:verify ' ;
1823
1924 /**
2025 * The console command description.
@@ -23,17 +28,6 @@ class TenantsVerify extends Command
2328 */
2429 protected $ description = 'Verify tenant configuration and storage paths ' ;
2530
26- /**
27- * Strip protocol from URL
28- *
29- * @param string $url
30- * @return string
31- */
32- private function stripProtocol (string $ url ): string
33- {
34- return preg_replace ('#^https?://# ' , '' , $ url );
35- }
36-
3731 /**
3832 * Execute the console command.
3933 *
@@ -46,85 +40,72 @@ public function handle()
4640 $ currentTenant = app ('currentTenant ' );
4741 }
4842
49- $ verifyAgainstId = $ this ->option ('verify-against ' );
50-
51- if (!$ currentTenant ) {
52- $ this ->error ('No current tenant found ' );
43+ if (config ('app.multitenancy ' ) && !$ currentTenant ) {
44+ $ this ->error ('Multitenancy enabled but no current tenant found. ' );
5345
5446 return ;
5547 }
5648
57- $ this ->info ('Current Tenant ID: ' . $ currentTenant ->id );
58- $ this ->line ('---------------------------------------- ' );
49+ $ this ->info ('Current Tenant ID: ' . ($ currentTenant ?->id ?? 'NONE ' ));
5950
60- // Expected paths and configurations
61- $ expectedStoragePath = base_path ('storage/tenant_ ' . $ currentTenant ->id );
62- $ actualConfigs = [
63- 'filesystems.disks.local.root ' => storage_path ('app ' ),
64- 'cache.prefix ' => config ('cache.prefix ' ),
65- 'app.url ' => config ('app.url ' ),
66- 'script-runner-microservice.callback ' => config ('script-runner-microservice.callback ' ),
51+ $ paths = [
52+ ['Storage Path ' , storage_path ()],
53+ ['Config Cache Path ' , app ()->getCachedConfigPath ()],
54+ ['Lang Path ' , lang_path ()],
6755 ];
6856
69- // Display current values
70- $ this ->info ('Current Storage Path: ' . storage_path ());
71- $ this ->line ('---------------------------------------- ' );
72-
73- $ this ->info ('Current Configuration Values: ' );
74- foreach ($ actualConfigs as $ key => $ expectedValue ) {
75- $ currentValue = config ($ key );
76- $ this ->line ("{$ key }: {$ currentValue }" );
77- }
78-
79- // If verify-against is specified, perform verification
80- if ($ verifyAgainstId ) {
81- $ this ->line ('---------------------------------------- ' );
82- $ this ->info ("Verifying against tenant ID: {$ verifyAgainstId }" );
57+ // Display paths in a nice table
58+ $ this ->table (['Path ' , 'Value ' ], $ paths );
59+
60+ $ configs = [
61+ 'app.key ' ,
62+ 'app.url ' ,
63+ 'app.instance ' ,
64+ 'cache.prefix ' ,
65+ 'database.redis.options.prefix ' ,
66+ 'cache.stores.cache_settings.prefix ' ,
67+ 'script-runner-microservice.callback ' ,
68+ 'database.connections.processmaker.database ' ,
69+ 'logging.channels.daily.path ' ,
70+ 'filesystems.disks.public.root ' ,
71+ 'filesystems.disks.local.root ' ,
72+ 'filesystems.disks.lang.root ' ,
73+ ];
8374
84- $ expectedStoragePath = base_path ('storage/tenant_ ' . $ verifyAgainstId );
85- $ expectedConfigs = [
86- 'filesystems.disks.local.root ' => $ expectedStoragePath . '/app ' ,
87- 'cache.prefix ' => 'tenant_id_ ' . $ verifyAgainstId ,
88- 'app.url ' => config ('app.url ' ),
75+ $ configs = array_map (function ($ config ) {
76+ return [
77+ $ config ,
78+ config ($ config ),
8979 ];
90-
91- $ hasMismatch = false ;
92-
93- // Verify storage path
94- if (storage_path () !== $ expectedStoragePath ) {
95- $ this ->error ('Storage path mismatch! ' );
96- $ this ->line ("Expected: {$ expectedStoragePath }" );
97- $ this ->line ('Current: ' . storage_path ());
98- $ hasMismatch = true ;
99- }
100-
101- // Verify tenant URL if tenant exists
102- $ verifyTenant = Tenant::find ($ verifyAgainstId );
103- if ($ verifyTenant && $ verifyTenant ->domain !== $ this ->stripProtocol (config ('app.url ' ))) {
104- $ this ->error ('Tenant URL mismatch! ' );
105- $ this ->line ("Expected: {$ verifyTenant ->domain }" );
106- $ this ->line ('Current: ' . config ('app.url ' ));
107- $ hasMismatch = true ;
108- }
109-
110- // Verify config values
111- foreach ($ expectedConfigs as $ key => $ expectedValue ) {
112- $ currentValue = config ($ key );
113- if ($ currentValue !== $ expectedValue ) {
114- $ this ->error ("Config mismatch for {$ key }! " );
115- $ this ->line ("Expected: {$ expectedValue }" );
116- $ this ->line ("Current: {$ currentValue }" );
117- $ hasMismatch = true ;
118- }
80+ }, $ configs );
81+
82+ // Display configs in a nice table
83+ $ this ->table (['Config ' , 'Value ' ], $ configs );
84+
85+ $ env = EnvironmentVariable::first ();
86+ if (!$ env ) {
87+ $ decrypted = 'No environment variables found to test decryption ' ;
88+ } else {
89+ $ encryptedValue = $ env ->getAttributes ()['value ' ];
90+ try {
91+ Crypt::decryptString ($ encryptedValue );
92+ $ decrypted = 'OK ' ;
93+ } catch (DecryptException $ e ) {
94+ $ decrypted = 'FAILED! ' . $ e ->getMessage ();
11995 }
120-
121- if (!$ hasMismatch ) {
122- $ this ->info ('All configurations match as expected! ' );
123- }
124-
125- return $ hasMismatch ? Command::FAILURE : Command::SUCCESS ;
12696 }
12797
128- return Command::SUCCESS ;
98+ $ other = [
99+ ['Landlord Config Cache Path ' , base_path ('bootstrap/cache/config.php ' )],
100+ ['Landlord Config Is Cached ' , File::exists (base_path ('bootstrap/cache/config.php ' )) ? 'Yes ' : 'No ' ],
101+ ['Tenant Config Cache Path ' , app ()->getCachedConfigPath ()],
102+ ['Tenant Config Is Cached ' , File::exists (app ()->getCachedConfigPath ()) ? 'Yes ' : 'No ' ],
103+ ['First username (database check) ' , User::first ()?->username ?? 'No users found ' ],
104+ ['Decrypted check ' , substr ($ decrypted , 0 , 50 )],
105+ ['Original App URL (landlord) ' , $ currentTenant ?->getOriginalValue('APP_URL ' ) ?? config ('app.url ' )],
106+ ];
107+
108+ // Display other in a nice table
109+ $ this ->table (['Other ' , 'Value ' ], $ other );
129110 }
130111}
0 commit comments