Fix 5 broken FQCN references (runtime errors) where core pages referenced non-existent MintyPHP\Service\Audit\AuditMetadataEnricher and SystemAuditService. Add AuditMetadataEnricherInterface with NullAuditMetadataEnricher fallback so deactivating the audit module no longer crashes core edit pages. Move audit search resources from core Search*Provider files into the module via a new AuditSearchResourceProvider implementing the existing SearchResourceProvider contract. Add module-specific purge permissions (audit.api.purge, audit.imports.purge) replacing core ABILITY_ADMIN_SETTINGS_UPDATE. Also fixes: session key prefix convention, hardcoded English string, $_SERVER superglobal fallback, and manifest schema drift (i18n_path, group in ui_slots). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
109 lines
4.6 KiB
PHP
109 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Support\Search;
|
|
|
|
class SearchItemMapperProvider
|
|
{
|
|
public static function mapPreviewItem(string $key, array $data, string $query): ?array
|
|
{
|
|
if ($key === 'users') {
|
|
$label = trim(($data['first_name'] ?? '') . ' ' . ($data['last_name'] ?? ''));
|
|
$email = trim((string) ($data['email'] ?? ''));
|
|
if ($email !== '') {
|
|
$label = $label === '' ? $email : ($label . ' — ' . $email);
|
|
}
|
|
$url = lurl('admin/users/edit/' . ($data['uuid'] ?? '')) . '?search=' . urlencode($query);
|
|
} elseif ($key === 'permissions') {
|
|
$label = (string) ($data['description'] ?? '');
|
|
$url = lurl('admin/permissions/edit/' . ($data['id'] ?? '')) . '?search=' . urlencode($query);
|
|
} elseif ($key === 'scheduled-jobs') {
|
|
$jobLabel = trim((string) ($data['label'] ?? ''));
|
|
$jobKey = trim((string) ($data['job_key'] ?? ''));
|
|
$status = trim((string) ($data['last_run_status'] ?? ''));
|
|
$label = $jobLabel !== '' ? $jobLabel : $jobKey;
|
|
if ($status !== '') {
|
|
$label = trim($label . ' — ' . strtoupper($status));
|
|
}
|
|
$url = lurl('admin/scheduled-jobs/edit/' . ($data['id'] ?? '')) . '?search=' . urlencode($query);
|
|
} elseif ($key === 'mail-log') {
|
|
$toEmail = trim((string) ($data['to_email'] ?? ''));
|
|
$subject = trim((string) ($data['subject'] ?? ''));
|
|
$status = trim((string) ($data['status'] ?? ''));
|
|
$label = $subject !== '' ? $subject : $toEmail;
|
|
if ($status !== '') {
|
|
$label = trim($label . ' — ' . strtoupper($status));
|
|
}
|
|
$url = lurl('admin/mail-log/view/' . ($data['id'] ?? '')) . '?search=' . urlencode($query);
|
|
} elseif ($key === 'pages') {
|
|
$label = (string) ($data['slug'] ?? '');
|
|
$url = lurl('page/' . $label) . '?search=' . urlencode($query);
|
|
} else {
|
|
$label = (string) ($data['description'] ?? '');
|
|
$url = lurl('admin/' . $key . '/edit/' . ($data['uuid'] ?? '')) . '?search=' . urlencode($query);
|
|
}
|
|
|
|
if ($label === '') {
|
|
return null;
|
|
}
|
|
|
|
return ['label' => $label, 'url' => $url];
|
|
}
|
|
|
|
public static function mapResultItem(string $key, string $label, array $data): ?array
|
|
{
|
|
$title = '';
|
|
$description = '';
|
|
$url = '';
|
|
$image = '';
|
|
|
|
if ($key === 'users') {
|
|
$title = trim(($data['first_name'] ?? '') . ' ' . ($data['last_name'] ?? ''));
|
|
$description = (string) ($data['email'] ?? '');
|
|
$url = lurl('admin/users/edit/' . ($data['uuid'] ?? ''));
|
|
} elseif ($key === 'permissions') {
|
|
$title = (string) ($data['key'] ?? '');
|
|
$description = (string) ($data['description'] ?? '');
|
|
$url = lurl('admin/permissions/edit/' . ($data['id'] ?? ''));
|
|
} elseif ($key === 'scheduled-jobs') {
|
|
$jobLabel = trim((string) ($data['label'] ?? ''));
|
|
$jobKey = trim((string) ($data['job_key'] ?? ''));
|
|
$title = $jobLabel !== '' ? $jobLabel : $jobKey;
|
|
$status = trim((string) ($data['last_run_status'] ?? ''));
|
|
$description = $status !== '' ? strtoupper($status) : ($jobKey !== '' ? $jobKey : '');
|
|
$url = lurl('admin/scheduled-jobs/edit/' . ($data['id'] ?? ''));
|
|
} elseif ($key === 'pages') {
|
|
$title = (string) ($data['slug'] ?? '');
|
|
$description = t('Page');
|
|
$url = lurl('page/' . $title);
|
|
} elseif ($key === 'mail-log') {
|
|
$title = trim((string) ($data['subject'] ?? ''));
|
|
if ($title === '') {
|
|
$title = trim((string) ($data['to_email'] ?? ''));
|
|
}
|
|
$status = trim((string) ($data['status'] ?? ''));
|
|
$toEmail = trim((string) ($data['to_email'] ?? ''));
|
|
$description = trim(($status !== '' ? strtoupper($status) : '') . ($toEmail !== '' ? ' — ' . $toEmail : ''));
|
|
$url = lurl('admin/mail-log/view/' . ($data['id'] ?? ''));
|
|
} else {
|
|
$title = (string) ($data['description'] ?? '');
|
|
$description = $label;
|
|
$url = lurl('admin/' . $key . '/edit/' . ($data['uuid'] ?? ''));
|
|
}
|
|
|
|
if ($title === '' || $url === '') {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'type' => $label,
|
|
'title' => $title,
|
|
'description' => $description,
|
|
'url' => $url,
|
|
'image' => $image,
|
|
'icon' => SearchUiMetaProvider::iconForKey($key),
|
|
];
|
|
}
|
|
|
|
|
|
}
|