Skip to content

Commit fffdd53

Browse files
authored
Added support in DB::prohibitDestructiveCommands to preventing destructive Rollback… (#54238)
* Added support in DB::prohibitDestructiveCommands to prohibit RollbackCommand Signed-off-by: Rainer Bendig <[email protected]> * fixed use of Illuminate\Console\Command; Signed-off-by: Rainer Bendig <[email protected]> --------- Signed-off-by: Rainer Bendig <[email protected]>
1 parent ad20dd5 commit fffdd53

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Illuminate/Database/Console/Migrations/RollbackCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
namespace Illuminate\Database\Console\Migrations;
44

5+
use Illuminate\Console\Command;
56
use Illuminate\Console\ConfirmableTrait;
7+
use Illuminate\Console\Prohibitable;
68
use Illuminate\Database\Migrations\Migrator;
79
use Symfony\Component\Console\Attribute\AsCommand;
810
use Symfony\Component\Console\Input\InputOption;
911

1012
#[AsCommand('migrate:rollback')]
1113
class RollbackCommand extends BaseCommand
1214
{
13-
use ConfirmableTrait;
15+
use ConfirmableTrait, Prohibitable;
1416

1517
/**
1618
* The console command name.
@@ -53,8 +55,9 @@ public function __construct(Migrator $migrator)
5355
*/
5456
public function handle()
5557
{
56-
if (! $this->confirmToProceed()) {
57-
return 1;
58+
if ($this->isProhibited() ||
59+
! $this->confirmToProceed()) {
60+
return Command::FAILURE;
5861
}
5962

6063
$this->migrator->usingConnection($this->option('database'), function () {

src/Illuminate/Support/Facades/DB.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Console\Migrations\FreshCommand;
66
use Illuminate\Database\Console\Migrations\RefreshCommand;
77
use Illuminate\Database\Console\Migrations\ResetCommand;
8+
use Illuminate\Database\Console\Migrations\RollbackCommand;
89
use Illuminate\Database\Console\WipeCommand;
910

1011
/**
@@ -132,6 +133,7 @@ public static function prohibitDestructiveCommands(bool $prohibit = true)
132133
FreshCommand::prohibit($prohibit);
133134
RefreshCommand::prohibit($prohibit);
134135
ResetCommand::prohibit($prohibit);
136+
RollbackCommand::prohibit($prohibit);
135137
WipeCommand::prohibit($prohibit);
136138
}
137139

0 commit comments

Comments
 (0)