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>
66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Health\Checks;
|
|
|
|
use App\Filament\Resources\MissingUrls\MissingUrlResource;
|
|
use App\Models\MissingUrl;
|
|
use App\Support\Health\Check;
|
|
use App\Support\Health\Finding;
|
|
use App\Support\Health\Severity;
|
|
|
|
/**
|
|
* Addresses the frontend keeps being asked for and cannot answer.
|
|
*
|
|
* Every other check here reasons about what is stored; this one is the only
|
|
* one that knows what visitors actually did. A 404 is the one fault on the
|
|
* public site that nobody on this side can discover by looking — it happens to
|
|
* somebody else, on another machine, and then they leave.
|
|
*
|
|
* Counted from two hits upward. A single request is as likely to be a scanner
|
|
* as a person, and a number that never reaches zero stops being read.
|
|
*/
|
|
class UnresolvedMissingUrls implements Check
|
|
{
|
|
/**
|
|
* Below this, an address is a stray request rather than a broken link.
|
|
*/
|
|
protected const THRESHOLD = 2;
|
|
|
|
public function key(): string
|
|
{
|
|
return 'missing-urls';
|
|
}
|
|
|
|
public function permission(): ?string
|
|
{
|
|
// The same permission that governs doing something about it.
|
|
return 'redirects.view_any';
|
|
}
|
|
|
|
public function run(): Finding
|
|
{
|
|
$missing = MissingUrl::query()
|
|
->pending()
|
|
->where('hits', '>=', self::THRESHOLD)
|
|
->orderByDesc('hits')
|
|
->get(['path', 'hits', 'referrer']);
|
|
|
|
return Finding::problem(
|
|
$this->key(),
|
|
$missing->count(),
|
|
|
|
// An address our own site links to is a fault in what we publish,
|
|
// not somebody else's stale bookmark, and it will keep producing
|
|
// 404s until it is fixed here.
|
|
$missing->contains(fn (MissingUrl $url) => $url->isInternalReferrer())
|
|
? Severity::Error
|
|
: Severity::Warning,
|
|
|
|
url: MissingUrlResource::getUrl('index'),
|
|
samples: $missing->map(fn (MissingUrl $url) => "{$url->path} ({$url->hits})")->all(),
|
|
);
|
|
}
|
|
}
|