Skip to content

Commit

Permalink
- feedback fixes.
Browse files Browse the repository at this point in the history
- MakeLunarAdminCommand is now in admin package.
- InstallLunar now checks is Staff model exists.
- InstallLunar now published filament assets in the last step.
- Back to void returns
  • Loading branch information
webpatser committed Feb 14, 2024
1 parent 5c12fd1 commit 80786ea
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace Lunar\Console\Commands;
namespace Lunar\Admin\Console\Commands;

use Filament\Facades\Filament;
use Illuminate\Console\Command;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Hash;
use Lunar\Admin\Models\Staff;

use function Laravel\Prompts\password;
use function Laravel\Prompts\text;

Expand Down Expand Up @@ -73,19 +72,11 @@ protected function sendSuccessMessage(Authenticatable $user): void
$this->components->info('Success! '.($user->getAttribute('email') ?? 'You')." may now log in at {$loginUrl}");
}

public function handle()
public function handle(): void
{
$this->options = $this->options();

if (! Filament::getCurrentPanel()) {
$this->error('Filament has not been installed yet: php artisan filament:install --panels');

return Command::INVALID;
}

$user = $this->createUser();
$this->sendSuccessMessage($user);

return Command::SUCCESS;
}
}
7 changes: 7 additions & 0 deletions packages/admin/src/LunarPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
use Lunar\Admin\Auth\Manifest;
use Lunar\Admin\Console\Commands\MakeLunarAdminCommand;
use Lunar\Admin\Database\State\EnsureBaseRolesAndPermissions;
use Lunar\Admin\Listeners\FilamentUpgradedListener;
use Lunar\Admin\Models\Staff;
Expand Down Expand Up @@ -65,6 +66,12 @@ public function boot(): void
$this->mergeConfigFrom("{$this->root}/config/$config.php", "lunar.$config");
});

if ($this->app->runningInConsole()) {
$this->commands([
MakeLunarAdminCommand::class,
]);
}

$this->publishes([
__DIR__.'/../public' => public_path('vendor/lunarpanel'),
], 'public');
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/Console/Commands/AddonsDiscover.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AddonsDiscover extends Command
/**
* Execute the console command.
*/
public function handle(Manifest $manifest)
public function handle(Manifest $manifest): void
{
$manifest->build();

Expand All @@ -33,7 +33,5 @@ public function handle(Manifest $manifest)
}

$this->components->info('Addon manifest generated successfully.');

return Command::SUCCESS;
}
}
6 changes: 1 addition & 5 deletions packages/core/src/Console/Commands/Import/AddressData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AddressData extends Command
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->components->info('Importing Countries and States');

Expand All @@ -47,8 +47,6 @@ public function handle()

if (! $newCountries->count()) {
$this->components->info('There are no new countries to import');

return Command::SUCCESS;
}

progress(
Expand Down Expand Up @@ -81,7 +79,5 @@ function ($country, Progress $progress) {
);

$this->components->info('Countries and States imported successfully');

return Command::SUCCESS;
}
}
4 changes: 1 addition & 3 deletions packages/core/src/Console/Commands/MigrateGetCandy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MigrateGetCandy extends Command
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$tableNames = collect(
DB::connection()->getDoctrineSchemaManager()->listTableNames()
Expand Down Expand Up @@ -113,8 +113,6 @@ public function handle()
),
]);
}

return Command::SUCCESS;
}

protected function migrateTableNames($tables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ class SyncNewCustomerOrders extends Command
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
Order::orderBy('id')->chunk(500, function ($orders) {
foreach ($orders as $order) {
MarkAsNewCustomer::dispatch($order->id);
}
});

return Command::SUCCESS;
}
}
8 changes: 1 addition & 7 deletions packages/core/src/Console/Commands/ScoutIndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ private function indexer(array $models): void
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
// Check if --refresh and --flush options has been passed
if ($this->option('flush') && $this->option('refresh')) {
$this->components->error('You can\'t use the [--refresh] and [--flush] options together.');

return Command::FAILURE;
}

// Return searchable models from config
Expand All @@ -79,8 +77,6 @@ public function handle()
// Error if option [--ignore] is passed and no model is informed
$this->components->error('No model passed on call');
$this->components->info('When using the [--ignore] option, you must provide at least one model to index.');

return Command::FAILURE;
} else {
// Run the indexer commands
$this->indexer($this->argument('models'));
Expand All @@ -93,7 +89,5 @@ public function handle()
// Run the indexer commands
$this->indexer($models);
}

return Command::SUCCESS;
}
}
9 changes: 5 additions & 4 deletions packages/core/src/Console/InstallLunar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class InstallLunar extends Command
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->components->info('Installing Lunar...');

Expand All @@ -65,7 +65,7 @@ public function handle()

DB::transaction(function () {

if (! Staff::whereAdmin(true)->exists()) {
if (class_exists(Staff::class) && ! Staff::whereAdmin(true)->exists()) {
$this->components->info('First create a lunar admin user');
$this->call('lunar:create-admin');
}
Expand Down Expand Up @@ -253,6 +253,9 @@ public function handle()
$this->call('lunar:hub:install');
}

$this->components->info('Publishing Filament assets');
$this->call('filament:assets');

$this->components->info('Lunar is now installed 🚀');

if (confirm('Would you like to show some love by giving us a star on GitHub?')) {
Expand All @@ -264,8 +267,6 @@ public function handle()

$this->components->info('Thank you!');
}

return Command::SUCCESS;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/LunarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Lunar\Base\TaxManagerInterface;
use Lunar\Console\Commands\AddonsDiscover;
use Lunar\Console\Commands\Import\AddressData;
use Lunar\Console\Commands\MakeLunarAdminCommand;
use Lunar\Console\Commands\MigrateGetCandy;
use Lunar\Console\Commands\Orders\SyncNewCustomerOrders;
use Lunar\Console\Commands\ScoutIndexerCommand;
Expand Down Expand Up @@ -211,7 +210,6 @@ public function boot(): void
ScoutIndexerCommand::class,
MigrateGetCandy::class,
SyncNewCustomerOrders::class,
MakeLunarAdminCommand::class,
]);
}

Expand Down

0 comments on commit 80786ea

Please sign in to comment.