Skip to content

Commit

Permalink
Added support in DB::prohibitDestructiveCommands to preventing destru…
Browse files Browse the repository at this point in the history
…ctive Rollback… (#54238)

* Added support in DB::prohibitDestructiveCommands to prohibit RollbackCommand

Signed-off-by: Rainer Bendig <hexathos@gmail.com>

* fixed use of Illuminate\Console\Command;

Signed-off-by: Rainer Bendig <hexathos@gmail.com>

---------

Signed-off-by: Rainer Bendig <hexathos@gmail.com>
  • Loading branch information
hexathos authored Jan 18, 2025
1 parent ad20dd5 commit fffdd53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace Illuminate\Database\Console\Migrations;

use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

#[AsCommand('migrate:rollback')]
class RollbackCommand extends BaseCommand
{
use ConfirmableTrait;
use ConfirmableTrait, Prohibitable;

/**
* The console command name.
Expand Down Expand Up @@ -53,8 +55,9 @@ public function __construct(Migrator $migrator)
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return 1;
if ($this->isProhibited() ||
! $this->confirmToProceed()) {
return Command::FAILURE;
}

$this->migrator->usingConnection($this->option('database'), function () {
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Support/Facades/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Console\Migrations\FreshCommand;
use Illuminate\Database\Console\Migrations\RefreshCommand;
use Illuminate\Database\Console\Migrations\ResetCommand;
use Illuminate\Database\Console\Migrations\RollbackCommand;
use Illuminate\Database\Console\WipeCommand;

/**
Expand Down Expand Up @@ -132,6 +133,7 @@ public static function prohibitDestructiveCommands(bool $prohibit = true)
FreshCommand::prohibit($prohibit);
RefreshCommand::prohibit($prohibit);
ResetCommand::prohibit($prohibit);
RollbackCommand::prohibit($prohibit);
WipeCommand::prohibit($prohibit);
}

Expand Down

0 comments on commit fffdd53

Please sign in to comment.