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>
80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?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;
|
|
|
|
/**
|
|
* A record translated into a language but with no slug in it.
|
|
*
|
|
* This is already broken on the public site: the API builds `alternates` from
|
|
* the slugs, so the language with the missing one is either absent from the
|
|
* hreflang set or announced at a URL that 404s. Nothing here shows the
|
|
* problem, which is exactly why it needs a check.
|
|
*/
|
|
class MissingSlugs implements Check
|
|
{
|
|
public function key(): string
|
|
{
|
|
return 'missing-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) {
|
|
foreach ($this->publicRecords($model) as $record) {
|
|
foreach ($locales as $locale) {
|
|
$hasTitle = filled($record->getTranslation('title', $locale, false));
|
|
$hasSlug = filled($record->getTranslation('slug', $locale, false));
|
|
|
|
if ($hasTitle && ! $hasSlug) {
|
|
$count++;
|
|
$samples[] = $record->getTranslation('title', $locale, false)." ({$locale})";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return Finding::problem(
|
|
$this->key(),
|
|
$count,
|
|
Severity::Error,
|
|
samples: $samples,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Only what the public can reach: a draft with half its slugs filled in is
|
|
* work in progress, not a fault.
|
|
*
|
|
* @param class-string<Model> $model
|
|
* @return iterable<int, Model>
|
|
*/
|
|
protected function publicRecords(string $model): iterable
|
|
{
|
|
$query = $model::query();
|
|
|
|
return match ($model) {
|
|
Call::class => $query->open()->get(['id', 'title', 'slug']),
|
|
default => $query->published()->get(['id', 'title', 'slug']),
|
|
};
|
|
}
|
|
}
|