91 lines
2.9 KiB
PHP
91 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Entity\Log;
|
|
use App\Entity\LogEntry;
|
|
use App\Repository\LogEntryRepository;
|
|
use App\Service\XmlDumpReader;
|
|
use Knp\Component\Pager\PaginatorInterface;
|
|
use League\Flysystem\FilesystemException;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class LogController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly LogEntryRepository $logEntryRepository,
|
|
private readonly PaginatorInterface $paginator,
|
|
private readonly XmlDumpReader $xmlDumpReader,
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/log', name: 'app_admin_log')]
|
|
public function index(Request $request): Response
|
|
{
|
|
$qb = $this
|
|
->logEntryRepository
|
|
->createQueryBuilder('log_entry')
|
|
;
|
|
|
|
$pagination = $this->paginator->paginate(
|
|
$qb,
|
|
$request->query->getInt('page', 1),
|
|
$request->query->getInt('limit', 50),
|
|
[
|
|
'defaultSortFieldName' => 'log_entry.createdAt',
|
|
'defaultSortDirection' => 'DESC',
|
|
]
|
|
);
|
|
|
|
return $this->render('admin/log/index.html.twig', [
|
|
'pagination' => $pagination,
|
|
]);
|
|
}
|
|
|
|
#[Route('/admin/log/{id}/xml-dumps', name: 'app_admin_log_xmldumps')]
|
|
public function xmlDumps(LogEntry $logEntry): Response
|
|
{
|
|
$dumps = [];
|
|
try {
|
|
$dumps = $this->xmlDumpReader->findDumpsForRequestId($logEntry->getRequestId());
|
|
} catch (FilesystemException) {
|
|
}
|
|
|
|
return $this->render('admin/log/xml_dumps.html.twig', [
|
|
'logEntry' => $logEntry,
|
|
'dumps' => $dumps,
|
|
]);
|
|
}
|
|
|
|
#[Route('/admin/log/download/{filename}', name: 'app_admin_log_xmldump_download', requirements: ['filename' => '.+'])]
|
|
public function downloadXmlDump(string $filename): Response
|
|
{
|
|
try {
|
|
if (false === $this->xmlDumpReader->fileExists($filename)) {
|
|
throw $this->createNotFoundException('Dump file not found. It may have been cleaned up.');
|
|
}
|
|
|
|
$content = $this->xmlDumpReader->getContent($filename);
|
|
} catch (FilesystemException $e) {
|
|
throw $this->createNotFoundException('Failed to read dump file: '.$e->getMessage());
|
|
}
|
|
|
|
$response = new Response($content);
|
|
$response->headers->set('Content-Type', 'application/xml');
|
|
|
|
$disposition = $response->headers->makeDisposition(
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
|
basename($filename)
|
|
);
|
|
$response->headers->set('Content-Disposition', $disposition);
|
|
|
|
return $response;
|
|
}
|
|
}
|