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

[10.x] Prevent session:table command from creating duplicates #48602

Merged
merged 4 commits into from
Oct 2, 2023
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
18 changes: 18 additions & 0 deletions src/Illuminate/Session/Console/SessionTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public function __construct(Filesystem $files, Composer $composer)
*/
public function handle()
{
if ($this->migrationExists()) {
$this->components->error('Migration already exists.');

return 1;
}

$fullPath = $this->createBaseMigration();

$this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/database.stub'));
Expand All @@ -80,4 +86,16 @@ protected function createBaseMigration()

return $this->laravel['migration.creator']->create($name, $path);
}

/**
* Determine whether the session table migration already exists.
*
* @return bool
*/
protected function migrationExists()
{
return count($this->files->glob(
$this->laravel->joinPaths($this->laravel->databasePath('migrations'), '*_*_*_*_create_sessions_table.php')
)) !== 0;
}
}
1 change: 1 addition & 0 deletions tests/Session/SessionTableCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testCreateMakesMigration()
$command->setLaravel($app);
$path = __DIR__.'/migrations';
$creator->shouldReceive('create')->once()->with('create_sessions_table', $path)->andReturn($path);
$files->shouldReceive('glob')->once()->with($app->joinPaths($app->databasePath('migrations'), '*_*_*_*_create_sessions_table.php'))->andReturn([]);
$files->shouldReceive('get')->once()->andReturn('foo');
$files->shouldReceive('put')->once()->with($path, 'foo');

Expand Down