98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Admin\Field\JsonDataField;
|
|
use App\Entity\LogEntry;
|
|
use App\Repository\LogEntryRepository;
|
|
use App\Service\XmlDumpService;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
|
use League\Flysystem\FilesystemException;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class LogEntryCrudController extends AbstractCrudController
|
|
{
|
|
public function __construct(
|
|
private readonly LogEntryRepository $logEntryRepository,
|
|
) {
|
|
}
|
|
|
|
public static function getEntityFqcn(): string
|
|
{
|
|
return LogEntry::class;
|
|
}
|
|
|
|
public function configureActions(Actions $actions): Actions
|
|
{
|
|
$viewDumps = Action::new('viewDumps', 'XML Dumps', 'fa fa-file-code')
|
|
->linkToCrudAction('xmlDumps')
|
|
->displayIf(static fn (LogEntry $entity): bool => 'bpn' === $entity->getChannel());
|
|
|
|
return $actions
|
|
->add(Crud::PAGE_INDEX, Action::DETAIL)
|
|
->add(Crud::PAGE_INDEX, $viewDumps)
|
|
->add(Crud::PAGE_DETAIL, $viewDumps)
|
|
->remove(Crud::PAGE_INDEX, Action::NEW)
|
|
->remove(Crud::PAGE_INDEX, Action::EDIT)
|
|
->remove(Crud::PAGE_INDEX, Action::DELETE)
|
|
->remove(Crud::PAGE_DETAIL, Action::EDIT)
|
|
->remove(Crud::PAGE_DETAIL, Action::DELETE)
|
|
;
|
|
}
|
|
|
|
public function configureCrud(Crud $crud): Crud
|
|
{
|
|
return $crud
|
|
->setEntityLabelInSingular('Logeintrag')
|
|
->setEntityLabelInPlural('Logeinträge')
|
|
->setDefaultSort(['createdAt' => 'DESC'])
|
|
->setSearchFields(['errorCode', 'message', 'channel', 'extra']);
|
|
}
|
|
|
|
public function configureFields(string $pageName): iterable
|
|
{
|
|
yield DateTimeField::new('createdAt', 'Zeitstempel');
|
|
yield TextField::new('errorCode', 'Fehlercode')
|
|
->formatValue(static fn (?string $value): string => $value ?? '-');
|
|
yield TextField::new('username', 'Benutzer');
|
|
yield TextField::new('message', 'Aktion');
|
|
yield TextField::new('requestId', 'Request ID');
|
|
yield TextField::new('uri', 'URI');
|
|
yield JsonDataField::new('context', 'Kontext')->onlyOnDetail();
|
|
yield JsonDataField::new('extra', 'Extra')->onlyOnDetail();
|
|
}
|
|
|
|
public function xmlDumps(Request $request, XmlDumpService $xmlDumpService): Response
|
|
{
|
|
$entityId = $request->query->getInt('entityId');
|
|
if ($entityId <= 0) {
|
|
throw $this->createNotFoundException('Log entry not found.');
|
|
}
|
|
|
|
$entity = $this->logEntryRepository->find($entityId);
|
|
if (!$entity instanceof LogEntry) {
|
|
throw $this->createNotFoundException('Log entry not found.');
|
|
}
|
|
|
|
$dumps = [];
|
|
try {
|
|
$dumps = $xmlDumpService->findDumpsForRequestId($entity->getRequestId());
|
|
} catch (FilesystemException) {
|
|
}
|
|
|
|
return $this->render('admin/xml_dump/list.html.twig', [
|
|
'logEntry' => $entity,
|
|
'requestId' => $entity->getRequestId(),
|
|
'dumps' => $dumps,
|
|
]);
|
|
}
|
|
}
|