Skip to content
Merged
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
351 changes: 228 additions & 123 deletions packages/core/src/Console/Commands/MooxInstaller.php

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions packages/core/src/Console/Traits/CheckForFilament.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait CheckForFilament
{
protected string $providerPath = 'app/Providers/Filament/AdminPanelProvider.php';

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

info('📦 Running: composer require filament/filament...');
if (! $silent) {
info('📦 Running: composer require filament/filament...');
}
exec('composer require filament/filament:* 2>&1', $output, $returnVar);
foreach ($output as $line) {
info(' '.$line);
if (! $silent) {
info(' '.$line);
}
}

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

info('✅ filament/filament successfully installed.');
if (! $silent) {
info('✅ filament/filament successfully installed.');
}
} else {
info('✅ Filament is already installed.');
if (! $silent) {
info('✅ Filament is already installed.');
}
}
} else {
info('✅ Filament is already installed.');
if (! $silent) {
info('✅ Filament is already installed.');
}
}

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

return true;
}
Expand Down
70 changes: 51 additions & 19 deletions packages/core/src/Console/Traits/CheckOrCreateFilamentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,10 @@ public function checkOrCreateFilamentUser(): void
return;
}

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

public function hasFilamentUsers(): bool
{
/** @var class-string<Model> $userModel */
$userModel = Config::get('filament.auth.providers.users.model') ?? \App\Models\User::class;

if (! class_exists($userModel)) {
return false;
}

$table = (new $userModel)->getTable();

if (! Schema::hasTable($table)) {
return false;
}

return $userModel::count() > 0;
}

protected function createFilamentUser(string $userModel): void
{
info("🧑 Creating new admin user for model '{$userModel}'...");
Expand All @@ -80,4 +62,54 @@ protected function createFilamentUser(string $userModel): void

info("✅ User '{$user->email}' created successfully.");
}

public function checkOrCreateWpUser(): void
{
$wpUserModel = \Moox\Press\Models\WpUser::class;

if (! class_exists($wpUserModel)) {
warning("⚠️ WP User model '{$wpUserModel}' does not exist.");

return;
}

$table = (new $wpUserModel)->getTable();

info("🔍 Checking WP user setup for Press Panel [Model: {$wpUserModel}]...");

if (! Schema::hasTable($table)) {
warning("⚠️ Table '{$table}' not found. Did you run migrations?");

return;
}

if ($wpUserModel::count() > 0) {
info("✅ Found existing WP users in '{$table}'. Skipping user creation.");

return;
}

alert("🚨 No WP users found. Let's create the first WP user");
$this->createWpUser($wpUserModel);
}

protected function createWpUser(string $wpUserModel): void
{
info("🧑 Creating new WP user for model '{$wpUserModel}'...");

$login = text('Enter login', default: 'wpadmin');
$email = text('Enter email', default: '[email protected]');
$password = password('Enter password', required: true);
$displayName = text('Enter display name', default: $login);

$user = $wpUserModel::create([
'user_login' => $login,
'user_email' => $email,
'user_pass' => $password,
'display_name' => $displayName,
'user_registered' => now(),
]);

info("✅ WP user '{$user->user_login}' created successfully.");
}
}
Loading
Loading