From 48a1fe5e5e8f7088e9f1b2d515f2355c8cfb8631 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 31 Aug 2026 11:33:13 +0930 Subject: [PATCH] Add verbose output to media:maintenance With -v, print per-row detail (media_id, original status_id, remote_media, profile_id, mime, size, path) as each orphaned row is processed instead of the progress bar, and expand the dry-run table with extra columns. Uses Laravel's built-in verbosity flag. --- .../Commands/Media/MediaMaintenance.php | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/Media/MediaMaintenance.php b/app/Console/Commands/Media/MediaMaintenance.php index cb34d7ad5..c93e8eb87 100644 --- a/app/Console/Commands/Media/MediaMaintenance.php +++ b/app/Console/Commands/Media/MediaMaintenance.php @@ -91,14 +91,28 @@ class MediaMaintenance extends Command $this->info('Found '.$total.' orphaned media row(s); processing '.$media->count().' this run (limit '.$limit.').'); if ($dryRun) { + $columns = $this->output->isVerbose() + ? ['media_id', 'status_id', 'remote_media', 'profile_id', 'mime', 'size', 'created_at', 'media_path'] + : ['media_id', 'status_id', 'remote_media', 'media_path']; + $this->table( - ['media_id', 'status_id', 'remote_media', 'media_path'], - $media->map(fn ($m) => [ - $m->id, - $m->status_id, - (bool) $m->remote_media ? 'true' : 'false', - $m->media_path, - ])->all() + $columns, + $media->map(function ($m) { + $base = [ + 'media_id' => $m->id, + 'status_id' => $m->status_id, + 'remote_media' => (bool) $m->remote_media ? 'true' : 'false', + 'profile_id' => $m->profile_id, + 'mime' => $m->mime, + 'size' => $m->size, + 'created_at' => optional($m->created_at)->toDateTimeString(), + 'media_path' => $m->media_path, + ]; + + return $this->output->isVerbose() + ? array_values($base) + : [$base['media_id'], $base['status_id'], $base['remote_media'], $base['media_path']]; + })->all() ); $this->comment('[dry-run] Would detach and delete the '.$media->count().' row(s) above.'); @@ -111,22 +125,43 @@ class MediaMaintenance extends Command return self::SUCCESS; } + $verbose = $this->output->isVerbose(); + $processed = 0; - $bar = $this->output->createProgressBar($media->count()); - $bar->start(); + $bar = $verbose ? null : $this->output->createProgressBar($media->count()); + $bar?->start(); foreach ($media as $m) { + $originalStatusId = $m->status_id; // Detach in the DB before dispatching so the delete job's guard // sees an orphaned row (the job re-fetches the model on unserialize). Media::whereId($m->id)->update(['status_id' => null]); $m->status_id = null; MediaStorageService::delete($m, true); $processed++; - $bar->advance(); + + if ($verbose) { + $this->line(sprintf( + ' [%d/%d] detached + dispatched delete: media_id=%d status_id=%s remote_media=%s profile_id=%s mime=%s size=%s path=%s', + $processed, + $media->count(), + $m->id, + $originalStatusId ?? 'null', + (bool) $m->remote_media ? 'true' : 'false', + $m->profile_id ?? 'null', + $m->mime ?? 'null', + $m->size ?? 'null', + $m->media_path ?? 'null' + )); + } else { + $bar->advance(); + } } - $bar->finish(); - $this->newLine(2); + $bar?->finish(); + if (! $verbose) { + $this->newLine(2); + } $this->info('Done. Detached and dispatched deletion for '.$processed.' orphaned media row(s).'); if ($total > $processed) {