Skip to content

Commit 0e8d8df

Browse files
authored
Feature/install (#827)
* MooxInstaller * Fix styling
1 parent 85df599 commit 0e8d8df

File tree

8 files changed

+696
-860
lines changed

8 files changed

+696
-860
lines changed

packages/core/src/Console/Commands/MooxInstaller.php

Lines changed: 228 additions & 123 deletions
Large diffs are not rendered by default.

packages/core/src/Console/Traits/CheckForFilament.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait CheckForFilament
1414
{
1515
protected string $providerPath = 'app/Providers/Filament/AdminPanelProvider.php';
1616

17-
public function checkForFilament(): bool
17+
public function checkForFilament(bool $silent = false): bool
1818
{
1919
if (! class_exists(\Filament\PanelProvider::class, false)) {
2020
$panelProviderPath = base_path('vendor/filament/filament/src/PanelProvider.php');
@@ -28,10 +28,14 @@ public function checkForFilament(): bool
2828
return false;
2929
}
3030

31-
info('📦 Running: composer require filament/filament...');
31+
if (! $silent) {
32+
info('📦 Running: composer require filament/filament...');
33+
}
3234
exec('composer require filament/filament:* 2>&1', $output, $returnVar);
3335
foreach ($output as $line) {
34-
info(' '.$line);
36+
if (! $silent) {
37+
info(' '.$line);
38+
}
3539
}
3640

3741
if ($returnVar !== 0) {
@@ -40,15 +44,24 @@ public function checkForFilament(): bool
4044
return false;
4145
}
4246

43-
info('✅ filament/filament successfully installed.');
47+
if (! $silent) {
48+
info('✅ filament/filament successfully installed.');
49+
}
4450
} else {
45-
info('✅ Filament is already installed.');
51+
if (! $silent) {
52+
info('✅ Filament is already installed.');
53+
}
4654
}
4755
} else {
48-
info('✅ Filament is already installed.');
56+
if (! $silent) {
57+
info('✅ Filament is already installed.');
58+
}
4959
}
5060

51-
$this->analyzeFilamentEnvironment();
61+
// Only analyze in panel generation flow. The packages flow should stay clean.
62+
if (! $silent && method_exists($this, 'isPanelGenerationMode') && $this->isPanelGenerationMode()) {
63+
$this->analyzeFilamentEnvironment();
64+
}
5265

5366
return true;
5467
}

packages/core/src/Console/Traits/CheckOrCreateFilamentUser.php

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,10 @@ public function checkOrCreateFilamentUser(): void
4242
return;
4343
}
4444

45-
alert("🚨 No users found in '{$table}'. Let's create the first Filament user.");
45+
alert("🚨 No users found. Let's create the first user");
4646
$this->createFilamentUser($userModel);
4747
}
4848

49-
public function hasFilamentUsers(): bool
50-
{
51-
/** @var class-string<Model> $userModel */
52-
$userModel = Config::get('filament.auth.providers.users.model') ?? \App\Models\User::class;
53-
54-
if (! class_exists($userModel)) {
55-
return false;
56-
}
57-
58-
$table = (new $userModel)->getTable();
59-
60-
if (! Schema::hasTable($table)) {
61-
return false;
62-
}
63-
64-
return $userModel::count() > 0;
65-
}
66-
6749
protected function createFilamentUser(string $userModel): void
6850
{
6951
info("🧑 Creating new admin user for model '{$userModel}'...");
@@ -80,4 +62,54 @@ protected function createFilamentUser(string $userModel): void
8062

8163
info("✅ User '{$user->email}' created successfully.");
8264
}
65+
66+
public function checkOrCreateWpUser(): void
67+
{
68+
$wpUserModel = \Moox\Press\Models\WpUser::class;
69+
70+
if (! class_exists($wpUserModel)) {
71+
warning("⚠️ WP User model '{$wpUserModel}' does not exist.");
72+
73+
return;
74+
}
75+
76+
$table = (new $wpUserModel)->getTable();
77+
78+
info("🔍 Checking WP user setup for Press Panel [Model: {$wpUserModel}]...");
79+
80+
if (! Schema::hasTable($table)) {
81+
warning("⚠️ Table '{$table}' not found. Did you run migrations?");
82+
83+
return;
84+
}
85+
86+
if ($wpUserModel::count() > 0) {
87+
info("✅ Found existing WP users in '{$table}'. Skipping user creation.");
88+
89+
return;
90+
}
91+
92+
alert("🚨 No WP users found. Let's create the first WP user");
93+
$this->createWpUser($wpUserModel);
94+
}
95+
96+
protected function createWpUser(string $wpUserModel): void
97+
{
98+
info("🧑 Creating new WP user for model '{$wpUserModel}'...");
99+
100+
$login = text('Enter login', default: 'wpadmin');
101+
$email = text('Enter email', default: '[email protected]');
102+
$password = password('Enter password', required: true);
103+
$displayName = text('Enter display name', default: $login);
104+
105+
$user = $wpUserModel::create([
106+
'user_login' => $login,
107+
'user_email' => $email,
108+
'user_pass' => $password,
109+
'display_name' => $displayName,
110+
'user_registered' => now(),
111+
]);
112+
113+
info("✅ WP user '{$user->user_login}' created successfully.");
114+
}
83115
}

0 commit comments

Comments
 (0)