Skip to content

Commit 6995c83

Browse files
authored
Merge pull request #216 from fleetbase/dev-v1.6.49
v1.6.49 - Updated to support new installer method
2 parents 20a7b67 + e17f095 commit 6995c83

11 files changed

Lines changed: 375 additions & 216 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fleetbase/core-api",
3-
"version": "1.6.48",
3+
"version": "1.6.49",
44
"description": "Core Framework and Resources for Fleetbase API",
55
"keywords": [
66
"fleetbase",

seeders/Concerns/ResolvesSeedCompany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait ResolvesSeedCompany
88
{
99
protected function resolveSeedCompany(?string $fallbackUuidEnv = null, ?string $fallbackPublicIdEnv = null): ?Company
1010
{
11-
$companyUuid = env('SEED_COMPANY_UUID') ?: ($fallbackUuidEnv ? env($fallbackUuidEnv) : null);
11+
$companyUuid = env('SEED_COMPANY_UUID') ?: ($fallbackUuidEnv ? env($fallbackUuidEnv) : null);
1212
$companyPublicId = env('SEED_COMPANY_PUBLIC_ID') ?: ($fallbackPublicIdEnv ? env($fallbackPublicIdEnv) : null);
1313

1414
if ($companyUuid) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Fleetbase\Console\Commands;
4+
5+
use Fleetbase\Support\SocketCluster\SocketClusterService;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Log;
8+
9+
class NotifyInstalled extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'fleetbase:notify-installed {--channel=fleetbase.install}';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Notify open install pages that Fleetbase setup has completed';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return int
29+
*/
30+
public function handle()
31+
{
32+
$channel = $this->option('channel') ?: 'fleetbase.install';
33+
$payload = [
34+
'event' => 'fleetbase.installed',
35+
'installed' => true,
36+
'timestamp' => now()->toIso8601String(),
37+
];
38+
39+
try {
40+
$socketClusterClient = new SocketClusterService();
41+
$sent = $socketClusterClient->send($channel, $payload);
42+
43+
if (!$sent) {
44+
$message = $socketClusterClient->error() ?: 'SocketCluster did not acknowledge the install notification.';
45+
$this->warn('Install notification was not sent: ' . $message);
46+
Log::warning('Fleetbase install notification was not sent.', [
47+
'channel' => $channel,
48+
'error' => $message,
49+
]);
50+
51+
return 0;
52+
}
53+
54+
$this->info('Install notification sent.');
55+
} catch (\Throwable $e) {
56+
$this->warn('Install notification failed: ' . $e->getMessage());
57+
Log::warning('Fleetbase install notification failed.', [
58+
'channel' => $channel,
59+
'error' => $e->getMessage(),
60+
]);
61+
}
62+
63+
return 0;
64+
}
65+
}

src/Http/Controllers/Internal/v1/AuthController.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Illuminate\Http\Request;
2929
use Illuminate\Support\Carbon;
3030
use Illuminate\Support\Facades\Cache;
31-
use Illuminate\Support\Facades\DB;
3231
use Illuminate\Support\Facades\Mail;
3332
use Illuminate\Support\Facades\Redis;
3433
use Illuminate\Support\Str;
@@ -218,37 +217,9 @@ public function bootstrap(Request $request)
218217
->distinct()
219218
->get();
220219

221-
// Get installer status (cached separately)
222-
$installer = Cache::remember('installer_status', now()->addHour(), function () {
223-
$shouldInstall = false;
224-
$shouldOnboard = false;
225-
226-
try {
227-
DB::connection()->getPdo();
228-
if (DB::connection()->getDatabaseName()) {
229-
if (\Illuminate\Support\Facades\Schema::hasTable('companies')) {
230-
$shouldOnboard = !DB::table('companies')->exists();
231-
} else {
232-
$shouldInstall = true;
233-
}
234-
} else {
235-
$shouldInstall = true;
236-
}
237-
} catch (\Exception $e) {
238-
$shouldInstall = true;
239-
}
240-
241-
return [
242-
'shouldInstall' => $shouldInstall,
243-
'shouldOnboard' => $shouldOnboard,
244-
'defaultTheme' => \Fleetbase\Models\Setting::lookup('branding.default_theme', 'dark'),
245-
];
246-
});
247-
248220
return [
249221
'session' => $session,
250222
'organizations' => Organization::collection($organizations),
251-
'installer' => $installer,
252223
];
253224
});
254225

src/Http/Controllers/Internal/v1/InstallerController.php

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Fleetbase\Http\Middleware;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
class EnsureFleetbaseConfigured
10+
{
11+
/**
12+
* Core tables required before the API can serve Fleetbase requests.
13+
*
14+
* @var array<int, string>
15+
*/
16+
protected array $requiredTables = [
17+
'settings',
18+
'users',
19+
'companies',
20+
];
21+
22+
protected static bool $configured = false;
23+
24+
public function handle(Request $request, \Closure $next)
25+
{
26+
if (!$this->shouldCheck($request)) {
27+
return $next($request);
28+
}
29+
30+
if (!$this->isConfigured()) {
31+
return response()->json([
32+
'error' => 'fleetbase_not_configured',
33+
'errors' => ['fleetbase_not_configured'],
34+
'message' => 'Fleetbase is not installed or configured. Complete setup from the CLI or application container, then reload the console.',
35+
], 503);
36+
}
37+
38+
return $next($request);
39+
}
40+
41+
protected function shouldCheck(Request $request): bool
42+
{
43+
if ($request->isMethod('OPTIONS')) {
44+
return false;
45+
}
46+
47+
return $request->is('int/*')
48+
|| $request->is('*/int/*')
49+
|| $request->is('v1/*')
50+
|| $request->is('*/v1/*');
51+
}
52+
53+
protected function isConfigured(): bool
54+
{
55+
if (static::$configured) {
56+
return true;
57+
}
58+
59+
try {
60+
DB::connection()->getPdo();
61+
62+
if (!DB::connection()->getDatabaseName()) {
63+
return false;
64+
}
65+
66+
foreach ($this->requiredTables as $table) {
67+
if (!Schema::hasTable($table)) {
68+
return false;
69+
}
70+
}
71+
72+
static::$configured = true;
73+
74+
return true;
75+
} catch (\Throwable $e) {
76+
return false;
77+
}
78+
}
79+
}

src/Providers/CoreServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CoreServiceProvider extends ServiceProvider
4242
\Fleetbase\Http\Middleware\RequestTimer::class,
4343
\Fleetbase\Http\Middleware\ResetJsonResourceWrap::class,
4444
\Fleetbase\Http\Middleware\MergeConfigFromSettings::class,
45+
\Fleetbase\Http\Middleware\EnsureFleetbaseConfigured::class,
4546
\Fleetbase\Http\Middleware\AttachCacheHeaders::class,
4647
];
4748

@@ -85,6 +86,7 @@ class CoreServiceProvider extends ServiceProvider
8586
\Fleetbase\Console\Commands\InitializeSandboxKeyColumn::class,
8687
\Fleetbase\Console\Commands\SyncSandbox::class,
8788
\Fleetbase\Console\Commands\CreatePermissions::class,
89+
\Fleetbase\Console\Commands\NotifyInstalled::class,
8890
\Fleetbase\Console\Commands\FixUserCompanies::class,
8991
\Fleetbase\Console\Commands\PurgeApiLogs::class,
9092
\Fleetbase\Console\Commands\PurgeWebhookLogs::class,

0 commit comments

Comments
 (0)