option('dry-run'); $on = $this->option('on') ? \Carbon\Carbon::parse($this->option('on'))->startOfDay() : now()->startOfDay(); $this->warn('Backdated dates are estimates: profile completeness has no recorded history.'); $this->line('Only rows stamped on ' . $on->toDateString() . ' are touched.'); $changed = 0; $skipped = 0; foreach (self::TYPES as $type) { $table = (new $type)->getTable(); if (!\Schema::hasColumn($table, 'incomplete_at')) { continue; } $type::query() ->whereNotNull('incomplete_at') ->whereBetween('incomplete_at', [$on, $on->copy()->endOfDay()]) ->chunkById(500, function ($profiles) use (&$changed, &$skipped, $dryRun) { foreach ($profiles as $profile) { $estimate = $profile->created_at; // Nothing to move it to, or it would land in the // future: leave the bulk stamp alone. if (!$estimate || $estimate->gte($profile->incomplete_at)) { $skipped++; continue; } if (!$dryRun) { $profile->incomplete_at = $estimate; $profile->saveQuietly(); } $changed++; } }); } $this->info($dryRun ? "Dry run: {$changed} profiles would be backdated, {$skipped} left as they are." : "Backdated {$changed} profiles, left {$skipped} as they are."); return self::SUCCESS; } }