diff --git a/app/Console/Commands/fictionalize.php b/app/Console/Commands/fictionalize.php index 4ad0984..cc1e0c4 100644 --- a/app/Console/Commands/fictionalize.php +++ b/app/Console/Commands/fictionalize.php @@ -8,48 +8,80 @@ use App\Models\User; use Faker\Factory; use Illuminate\Console\Command; -/** - * @codeCoverageIgnore - */ class fictionalize extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'audition:fictionalize'; + protected $signature = 'audition:fictionalize + {--students : Fictionalize student names} + {--schools : Fictionalize school names} + {--users : Fictionalize user data} + {--all : Fictionalize all data types}'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'Command description'; + protected $description = 'Replace real names with fictional data for specified entity types'; - /** - * Execute the console command. - */ public function handle() { $faker = Factory::create(); - foreach (Student::all() as $student) { - $student->first_name = $faker->firstName(); - $student->last_name = $faker->lastName(); - $student->save(); + + // If no options are specified or --all is used, process everything + $processAll = $this->option('all') || + (! $this->option('students') && ! $this->option('schools') && ! $this->option('users')); + + if ($processAll || $this->option('students')) { + $this->info('Fictionalizing students...'); + $bar = $this->output->createProgressBar(Student::count()); + + Student::chunk(100, function ($students) use ($faker, $bar) { + foreach ($students as $student) { + $student->update([ + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } - foreach (School::all() as $school) { - $school->name = $faker->city().' High School'; - $school->save(); + if ($processAll || $this->option('schools')) { + $this->info('Fictionalizing schools...'); + $bar = $this->output->createProgressBar(School::count()); + + School::chunk(100, function ($schools) use ($faker, $bar) { + foreach ($schools as $school) { + $school->update([ + 'name' => $faker->city().' High School', + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } - foreach (User::where('email', '!=', 'matt@mattyoung.us')->get() as $user) { - $user->email = $faker->email(); - $user->first_name = $faker->firstName(); - $user->last_name = $faker->lastName(); - $user->cell_phone = $faker->phoneNumber(); - $user->save(); + if ($processAll || $this->option('users')) { + $this->info('Fictionalizing users...'); + $bar = $this->output->createProgressBar(User::where('email', '!=', 'matt@mattyoung.us')->count()); + + User::where('email', '!=', 'matt@mattyoung.us') + ->chunk(100, function ($users) use ($faker, $bar) { + foreach ($users as $user) { + $user->update([ + 'email' => $faker->unique()->email(), + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + 'cell_phone' => $faker->phoneNumber(), + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } + + $this->info('Fictionalization complete!'); } } diff --git a/resources/views/monitor/index.blade.php b/resources/views/monitor/index.blade.php index de645e8..1103f8c 100644 --- a/resources/views/monitor/index.blade.php +++ b/resources/views/monitor/index.blade.php @@ -30,7 +30,7 @@ @foreach($entries as $entry)