diff --git a/app/Console/Commands/Migrations/MigrateTutorials.php b/app/Console/Commands/Migrations/MigrateTutorials.php new file mode 100644 index 0000000000..40159adc7e --- /dev/null +++ b/app/Console/Commands/Migrations/MigrateTutorials.php @@ -0,0 +1,56 @@ +chunk(5000, function ($users): void { + /** @var User $user */ + foreach ($users as $user) { + $this->count++; + $settings = $user->settings; + + foreach ($settings as $key => $setting) { + if (str_starts_with($key, 'tutorial_')) { + $tutorial = new Tutorial(); + $tutorial->user_id = $user->id; + $tutorial->code = substr($key, 9); + $tutorial->save(); + unset($settings[$key]); + } + } + $user->updateQuietly(['settings' => $settings]); + } + }); + + $this->info('Migrated ' . $this->count . ' user tutorials.'); + return Command::SUCCESS; + } +}