Add CLI audit command docs
This commit is contained in:
36
app/Console/Commands/CheckArtworkUserIdsCommand.php
Normal file
36
app/Console/Commands/CheckArtworkUserIdsCommand.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
final class CheckArtworkUserIdsCommand extends Command
|
||||
{
|
||||
protected $signature = 'artworks:check-user-ids
|
||||
{--chunk=1000 : Number of artworks to process per chunk}
|
||||
{--show-missing=25 : Maximum number of missing references to print}
|
||||
{--artwork-id= : Only check this specific artwork ID}
|
||||
{--json : Output the summary as JSON}';
|
||||
|
||||
protected $description = 'Check whether every artworks.user_id exists in the users table.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$options = [
|
||||
'--chunk' => (string) max(1, (int) $this->option('chunk')),
|
||||
'--show-missing' => (string) max(0, (int) $this->option('show-missing')),
|
||||
];
|
||||
|
||||
if ($this->option('artwork-id') !== null) {
|
||||
$options['--artwork-id'] = (string) (int) $this->option('artwork-id');
|
||||
}
|
||||
|
||||
if ((bool) $this->option('json')) {
|
||||
$options['--json'] = true;
|
||||
}
|
||||
|
||||
return $this->call('artworks:check-user-refs', $options);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ final class CheckArtworkUserReferencesCommand extends Command
|
||||
/**
|
||||
* @return array{
|
||||
* summary: array{checked:int, valid:int, missing:int, null_user_ids:int},
|
||||
* sample_missing: array<int, array{artwork_id:int, user_id:string, title:string}>,
|
||||
* sample_missing: array<int, array{artwork_id:int, user_id:string, title:string, active:string, published:string, artwork_status:string}>,
|
||||
* missing_user_ids: array<int, true>
|
||||
* }
|
||||
*/
|
||||
@@ -120,6 +120,9 @@ final class CheckArtworkUserReferencesCommand extends Command
|
||||
'artworks.id',
|
||||
'artworks.user_id',
|
||||
'artworks.title',
|
||||
'artworks.is_public',
|
||||
'artworks.published_at',
|
||||
'artworks.artwork_status',
|
||||
DB::raw('users.id as matched_user_id'),
|
||||
])
|
||||
->when($artworkId !== null, fn ($q) => $q->where('artworks.id', $artworkId))
|
||||
@@ -146,6 +149,9 @@ final class CheckArtworkUserReferencesCommand extends Command
|
||||
'artwork_id' => (int) $artwork->id,
|
||||
'user_id' => $artwork->user_id === null ? '[null]' : (string) $artwork->user_id,
|
||||
'title' => (string) ($artwork->title ?? ''),
|
||||
'active' => (bool) ($artwork->is_public ?? false) ? 'yes' : 'no',
|
||||
'published' => $artwork->published_at !== null ? 'yes' : 'no',
|
||||
'artwork_status' => (string) ($artwork->artwork_status ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -478,8 +484,15 @@ final class CheckArtworkUserReferencesCommand extends Command
|
||||
if ($sampleRows !== []) {
|
||||
$this->newLine();
|
||||
$this->warn('Sample missing references:');
|
||||
$this->table(['Artwork ID', 'user_id', 'Title'], array_map(
|
||||
static fn (array $row): array => [$row['artwork_id'], $row['user_id'], $row['title']],
|
||||
$this->table(['Artwork ID', 'user_id', 'Title', 'Active', 'Published', 'Status'], array_map(
|
||||
static fn (array $row): array => [
|
||||
$row['artwork_id'],
|
||||
$row['user_id'],
|
||||
$row['title'],
|
||||
$row['active'],
|
||||
$row['published'],
|
||||
$row['artwork_status'],
|
||||
],
|
||||
$sampleRows,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user