Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Fix broken db command code #27020

Merged
merged 1 commit into from
Jan 1, 2019
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
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Console/Migrations/FreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function handle()

$this->info('Dropped all tables successfully.');

$this->call('migrate', [
$this->call('migrate', array_filter([
'--database' => $database,
'--path' => $this->input->getOption('path'),
'--realpath' => $this->input->getOption('realpath'),
'--force' => true,
'--step' => $this->option('step'),
]);
]));

if ($this->needsSeeding()) {
$this->runSeeder($database);
Expand Down Expand Up @@ -104,11 +104,11 @@ protected function needsSeeding()
*/
protected function runSeeder($database)
{
$this->call('db:seed', [
$this->call('db:seed', array_filter([
'--database' => $database,
'--class' => $this->option('seeder') ?: 'DatabaseSeeder',
'--force' => $this->option('force'),
]);
'--force' => true,
]));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ protected function prepareDatabase()
$this->migrator->setConnection($this->option('database'));

if (! $this->migrator->repositoryExists()) {
$this->call(
'migrate:install', ['--database' => $this->option('database')]
);
$this->call('migrate:install', array_filter([
'--database' => $this->option('database'),
]));
}
}
}
38 changes: 17 additions & 21 deletions src/Illuminate/Database/Console/Migrations/RefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,26 @@ public function handle()

$path = $this->input->getOption('path');

$force = $this->input->getOption('force');

// If the "step" option is specified it means we only want to rollback a small
// number of migrations before migrating again. For example, the user might
// only rollback and remigrate the latest four migrations instead of all.
$step = $this->input->getOption('step') ?: 0;

if ($step > 0) {
$this->runRollback($database, $path, $step, $force);
$this->runRollback($database, $path, $step);
} else {
$this->runReset($database, $path, $force);
$this->runReset($database, $path);
}

// The refresh command is essentially just a brief aggregate of a few other of
// the migration commands and just provides a convenient wrapper to execute
// them in succession. We'll also see if we need to re-seed the database.
$this->call('migrate', [
$this->call('migrate', array_filter([
'--database' => $database,
'--path' => $path,
'--realpath' => $this->input->getOption('realpath'),
'--force' => $force,
]);
'--force' => true,
]));

if ($this->needsSeeding()) {
$this->runSeeder($database);
Expand All @@ -75,37 +73,35 @@ public function handle()
*
* @param string $database
* @param string $path
* @param bool $step
* @param bool $force
* @param int $step
* @return void
*/
protected function runRollback($database, $path, $step, $force)
protected function runRollback($database, $path, $step)
{
$this->call('migrate:rollback', [
$this->call('migrate:rollback', array_filter([
'--database' => $database,
'--path' => $path,
'--realpath' => $this->input->getOption('realpath'),
'--step' => $step,
'--force' => $force,
]);
'--force' => true,
]));
}

/**
* Run the reset command.
*
* @param string $database
* @param string $path
* @param bool $force
* @return void
*/
protected function runReset($database, $path, $force)
protected function runReset($database, $path)
{
$this->call('migrate:reset', [
$this->call('migrate:reset', array_filter([
'--database' => $database,
'--path' => $path,
'--realpath' => $this->input->getOption('realpath'),
'--force' => $force,
]);
'--force' => true,
]));
}

/**
Expand All @@ -126,11 +122,11 @@ protected function needsSeeding()
*/
protected function runSeeder($database)
{
$this->call('db:seed', [
$this->call('db:seed', array_filter([
'--database' => $database,
'--class' => $this->option('seeder') ?: 'DatabaseSeeder',
'--force' => $this->option('force'),
]);
'--force' => true,
]));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/DatabaseMigrationMigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testMigrationRepositoryCreatedWhenNecessary()
$migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(false);
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo(['--database' => null]));
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo([]));

$this->runCommand($command);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/DatabaseMigrationRefreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function testRefreshCommandCallsCommandsWithProperArguments()
$console->shouldReceive('find')->with('migrate')->andReturn($migrateCommand);

$quote = DIRECTORY_SEPARATOR == '\\' ? '"' : "'";
$resetCommand->shouldReceive('run')->with(new InputMatcher("--database --path --realpath --force {$quote}migrate:reset{$quote}"), m::any());
$migrateCommand->shouldReceive('run')->with(new InputMatcher('--database --path --realpath --force migrate'), m::any());
$resetCommand->shouldReceive('run')->with(new InputMatcher("--force=1 {$quote}migrate:reset{$quote}"), m::any());
$migrateCommand->shouldReceive('run')->with(new InputMatcher('--force=1 migrate'), m::any());

$this->runCommand($command);
}
Expand All @@ -61,8 +61,8 @@ public function testRefreshCommandCallsCommandsWithStep()
$console->shouldReceive('find')->with('migrate')->andReturn($migrateCommand);

$quote = DIRECTORY_SEPARATOR == '\\' ? '"' : "'";
$rollbackCommand->shouldReceive('run')->with(new InputMatcher("--database --path --realpath --step=2 --force {$quote}migrate:rollback{$quote}"), m::any());
$migrateCommand->shouldReceive('run')->with(new InputMatcher('--database --path --realpath --force migrate'), m::any());
$rollbackCommand->shouldReceive('run')->with(new InputMatcher("--step=2 --force=1 {$quote}migrate:rollback{$quote}"), m::any());
$migrateCommand->shouldReceive('run')->with(new InputMatcher('--force=1 migrate'), m::any());

$this->runCommand($command, ['--step' => 2]);
}
Expand Down