Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
74
app/Support/Health/Checks/DuplicateSlugs.php
Normal file
74
app/Support/Health/Checks/DuplicateSlugs.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support\Health\Checks;
|
||||
|
||||
use App\Models\Call;
|
||||
use App\Models\Page;
|
||||
use App\Models\Project;
|
||||
use App\Support\Health\Check;
|
||||
use App\Support\Health\Finding;
|
||||
use App\Support\Health\Severity;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Two records answering at the same URL in the same language.
|
||||
*
|
||||
* `UniqueTranslatedSlug` prevents this on write, but a slug lives inside a
|
||||
* JSON column, so it can never be a database constraint — which means data
|
||||
* that arrived any other way (a seeder, an import, a manual fix) can still
|
||||
* collide. When it does, the public API resolves the URL to whichever row it
|
||||
* happens to reach first.
|
||||
*
|
||||
* Detected in PHP rather than with a GROUP BY on a JSON path, because that
|
||||
* expression is written differently in every database and these tables hold
|
||||
* hundreds of rows, not millions.
|
||||
*/
|
||||
class DuplicateSlugs implements Check
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'duplicate-slugs';
|
||||
}
|
||||
|
||||
public function permission(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function run(): Finding
|
||||
{
|
||||
$locales = array_keys((array) config('locales.supported'));
|
||||
$samples = [];
|
||||
$count = 0;
|
||||
|
||||
foreach ([Page::class, Project::class, Call::class] as $model) {
|
||||
/** @var array<int, Model> $records */
|
||||
$records = $model::query()->get(['id', 'slug'])->all();
|
||||
|
||||
foreach ($locales as $locale) {
|
||||
$seen = [];
|
||||
|
||||
foreach ($records as $record) {
|
||||
$slug = $record->getTranslation('slug', $locale, false);
|
||||
|
||||
if (blank($slug)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($seen[$slug])) {
|
||||
$count++;
|
||||
$samples[] = "{$slug} ({$locale})";
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[$slug] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Finding::problem($this->key(), $count, Severity::Error, samples: $samples);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user