Files
ntspi-app/app/Ship/Providers/EventServiceProvider.php
F4ilji 7ff860feca feat: block destructive DB commands in production
Listen for CommandStarting event and throw RuntimeException for
migrate:fresh, migrate:refresh, migrate:reset, db:wipe, db:seed
when APP_ENV=production. Prevents accidental data loss even with --force.

Also removes old non-functional closure-based override in routes/console.php.
2026-09-18 02:54:42 +05:00

50 lines
1.4 KiB
PHP
Executable File

<?php
namespace App\Ship\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use App\Ship\Abstracts\Providers\EventServiceProvider as AbstractEventServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends AbstractEventServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
if (app()->environment('production')) {
Event::listen(\Illuminate\Console\Events\CommandStarting::class, function ($event) {
$blocked = ['migrate:fresh', 'migrate:refresh', 'migrate:reset', 'db:wipe', 'db:seed'];
if (in_array($event->command, $blocked)) {
throw new \RuntimeException("BLOCKED: {$event->command} is disabled in production.");
}
});
}
}
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}