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.x] Improvements to the install:eloquent-driver command #10910

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Changes from 4 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
66 changes: 41 additions & 25 deletions src/Console/Commands/InstallEloquentDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class InstallEloquentDriver extends Command
*
* @var string
*/
protected $signature = 'statamic:install:eloquent-driver';
protected $signature = 'statamic:install:eloquent-driver
{ --all : Configures all repositories to use the database }
{ --import : Whether existing data should be imported }';

/**
* The console command description.
Expand Down Expand Up @@ -69,21 +71,30 @@ public function handle()
return $this->components->warn("No repositories left to migrate. You're already using the Eloquent Driver for all repositories.");
}

$repositories = multiselect(
label: 'Which repositories would you like to migrate?',
hint: 'You can always import other repositories later.',
options: $this->availableRepositories()->all(),
validate: fn (array $values) => count($values) === 0
? 'You must select at least one repository to migrate.'
: null
);
$repositories = $this->repositories();

foreach ($repositories as $repository) {
$method = 'migrate'.Str::studly($repository);
$this->$method();
}
}

protected function repositories(): array
{
if ($this->option('all')) {
return $this->availableRepositories()->keys()->all();
}

return multiselect(
label: 'Which repositories would you like to migrate?',
options: $this->availableRepositories()->all(),
validate: fn (array $values) => count($values) === 0
? 'You must select at least one repository to migrate.'
: null,
hint: 'You can always import other repositories later.'
);
}

protected function availableRepositories(): Collection
{
return collect([
Expand Down Expand Up @@ -179,7 +190,7 @@ protected function migrateAssetContainers(): void

$this->components->info('Configured asset containers');

if (confirm('Would you like to import existing asset containers?')) {
if ($this->shouldImport('asset containers')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-assets --force --only-asset-containers'),
message: 'Importing existing asset containers...'
Expand All @@ -203,7 +214,7 @@ protected function migrateAssets(): void

$this->components->info('Configured assets');

if (confirm('Would you like to import existing assets?')) {
if ($this->shouldImport('assets')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-assets --force --only-assets'),
message: 'Importing existing assets...'
Expand All @@ -227,7 +238,7 @@ protected function migrateBlueprints(): void

$this->components->info('Configured blueprints');

if (confirm('Would you like to import existing blueprints?')) {
if ($this->shouldImport('blueprints')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-blueprints --force --only-blueprints'),
message: 'Importing existing blueprints...'
Expand All @@ -251,7 +262,7 @@ protected function migrateCollections(): void

$this->components->info('Configured collections');

if (confirm('Would you like to import existing collections?')) {
if ($this->shouldImport('collections')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-collections --force --only-collections'),
message: 'Importing existing collections...'
Expand All @@ -275,7 +286,7 @@ protected function migrateCollectionTrees(): void

$this->components->info('Configured collection trees');

if (confirm('Would you like to import existing collection trees?')) {
if ($this->shouldImport('collection trees')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-collections --force --only-collection-trees'),
message: 'Importing existing collections...'
Expand All @@ -287,7 +298,7 @@ protected function migrateCollectionTrees(): void

protected function migrateEntries(): void
{
$shouldImportEntries = confirm('Would you like to import existing entries?');
$shouldImportEntries = $this->shouldImport('entries');

spin(
callback: function () use ($shouldImportEntries) {
Expand Down Expand Up @@ -346,7 +357,7 @@ protected function migrateFieldsets(): void

$this->components->info('Configured fieldsets');

if (confirm('Would you like to import existing fieldsets?')) {
if ($this->shouldImport('fieldsets')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-blueprints --force --only-fieldsets'),
message: 'Importing existing fieldsets...'
Expand All @@ -370,7 +381,7 @@ protected function migrateForms(): void

$this->components->info('Configured forms');

if (confirm('Would you like to import existing forms?')) {
if ($this->shouldImport('forms')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-forms --only-forms'),
message: 'Importing existing forms...'
Expand All @@ -394,7 +405,7 @@ protected function migrateFormSubmissions(): void

$this->components->info('Configured form submissions');

if (confirm('Would you like to import existing form submissions?')) {
if ($this->shouldImport('form submissions')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-forms --only-form-submissions'),
message: 'Importing existing form submissions...'
Expand All @@ -418,7 +429,7 @@ protected function migrateGlobals(): void

$this->components->info('Configured globals');

if (confirm('Would you like to import existing globals?')) {
if ($this->shouldImport('globals')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-globals --only-global-sets'),
message: 'Importing existing globals...'
Expand All @@ -442,7 +453,7 @@ protected function migrateGlobalVariables(): void

$this->components->info('Configured global variables');

if (confirm('Would you like to import existing global variables?')) {
if ($this->shouldImport('global variables')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-globals --only-global-variables'),
message: 'Importing existing global variables...'
Expand All @@ -466,7 +477,7 @@ protected function migrateNavs(): void

$this->components->info('Configured navs');

if (confirm('Would you like to import existing navs?')) {
if ($this->shouldImport('navs')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-navs --force --only-navs'),
message: 'Importing existing navs...'
Expand All @@ -490,7 +501,7 @@ protected function migrateNavTrees(): void

$this->components->info('Configured nav trees');

if (confirm('Would you like to import existing nav trees?')) {
if ($this->shouldImport('nav trees')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-navs --force --only-nav-trees'),
message: 'Importing existing nav trees...'
Expand All @@ -513,7 +524,7 @@ protected function migrateRevisions(): void

$this->components->info('Configured revisions');

if (confirm('Would you like to import existing revisions?')) {
if ($this->shouldImport('revisions')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-revisions'),
message: 'Importing existing revisions...'
Expand Down Expand Up @@ -554,7 +565,7 @@ protected function migrateTaxonomies(): void

$this->components->info('Configured taxonomies');

if (confirm('Would you like to import existing taxonomies?')) {
if ($this->shouldImport('taxonomies')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-taxonomies --force --only-taxonomies'),
message: 'Importing existing taxonomies...'
Expand All @@ -578,7 +589,7 @@ protected function migrateTerms(): void

$this->components->info('Configured terms');

if (confirm('Would you like to import existing terms?')) {
if ($this->shouldImport('terms')) {
spin(
callback: fn () => $this->runArtisanCommand('statamic:eloquent:import-taxonomies --force --only-terms'),
message: 'Importing existing terms...'
Expand All @@ -603,6 +614,11 @@ protected function migrateTokens(): void
$this->components->info('Configured tokens');
}

private function shouldImport(string $repository): bool
{
return $this->option('import') || confirm("Would you like to import existing {$repository}?");
}

private function switchToEloquentDriver(string $repository): void
{
File::put(
Expand Down
Loading