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:
81
app/Support/Health/Checks/StaleTranslations.php
Normal file
81
app/Support/Health/Checks/StaleTranslations.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support\Health\Checks;
|
||||
|
||||
use App\Models\Call;
|
||||
use App\Models\Page;
|
||||
use App\Models\Project;
|
||||
use App\Models\Service;
|
||||
use App\Support\ContentTypes;
|
||||
use App\Support\Health\Check;
|
||||
use App\Support\Health\Finding;
|
||||
use App\Support\TranslationFreshness;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Translations the original has moved on without.
|
||||
*
|
||||
* The sibling of the missing-translations check, and the one that finds what
|
||||
* nobody would: a language that *has* the text, so every screen in the panel
|
||||
* calls that record finished, while the version visitors read in it says
|
||||
* something the source stopped saying months ago.
|
||||
*
|
||||
* It is the failure that only ever surfaces when somebody who speaks both
|
||||
* languages happens to compare two pages, which is to say almost never.
|
||||
*/
|
||||
class StaleTranslations implements Check
|
||||
{
|
||||
/**
|
||||
* @var array<int, class-string<Model>>
|
||||
*/
|
||||
protected const TRANSLATED = [Page::class, Project::class, Call::class, Service::class];
|
||||
|
||||
public function key(): string
|
||||
{
|
||||
return 'stale-translations';
|
||||
}
|
||||
|
||||
public function permission(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function run(): Finding
|
||||
{
|
||||
$count = 0;
|
||||
$samples = [];
|
||||
|
||||
foreach (self::TRANSLATED as $model) {
|
||||
$records = $model::query()
|
||||
->when($model === Call::class, fn (Builder $q) => $q->open())
|
||||
->unless($model === Call::class, fn (Builder $q) => $q->published())
|
||||
// Loaded here rather than one record at a time: working this
|
||||
// out means reading the change history, and a check that costs
|
||||
// a query per record is one that gets switched off.
|
||||
->with('revisions')
|
||||
->get();
|
||||
|
||||
foreach ($records as $record) {
|
||||
$stale = TranslationFreshness::for($record);
|
||||
|
||||
if ($stale === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
||||
// Which languages, and how long they have been drifting —
|
||||
// "since March" is what decides whether this is urgent.
|
||||
$samples[] = ContentTypes::title($record)
|
||||
.' ('.collect($stale)
|
||||
->map(fn ($since, string $locale) => "{$locale}, ".$since->diffForHumans())
|
||||
->implode('; ').')';
|
||||
}
|
||||
}
|
||||
|
||||
return Finding::problem($this->key(), $count, samples: $samples);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user