This commit is contained in:
Jürgen Mummert
2025-12-25 15:15:11 +01:00
parent 497b46f113
commit 8f3b525563
4 changed files with 52 additions and 5 deletions
+6 -4
View File
@@ -7,8 +7,12 @@ use MummertMedia\ContaoMeilisearchBundle\Service\PdfIndexService;
class IndexPageListener
{
public function __construct(
private PdfIndexService $pdfIndexService
) {}
public function onIndexPage(string $content, array &$data, array &$set): void
{
$this->pdfIndexService->startCrawl();
// Marker vorhanden?
if (!str_contains($content, 'MEILISEARCH_JSON')) {
return;
@@ -100,11 +104,9 @@ class IndexPageListener
$pdfLinks = $this->findPdfLinks($content);
if ($pdfLinks !== []) {
$this->pdfIndexService->startCrawl();
error_log('PDF gefunden');
/** @var PdfIndexService $service */
$service = System::getContainer()->get(PdfIndexService::class);
$service->handlePdfLinks($pdfLinks);
$this->pdfIndexService->handlePdfLinks($pdfLinks);
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
use MummertMedia\ContaoMeilisearchBundle\Service\PdfIndexService;
class PdfCleanupListener
{
public function __construct(
private PdfIndexService $pdfIndexService
) {}
public function onLastChunk(): void
{
error_log('Crawler beendet → PDF Cleanup startet');
$this->pdfIndexService->cleanupRemovedPdfs();
}
}
+5 -1
View File
@@ -9,4 +9,8 @@ services:
# IndexPageListener als Contao-Hook registrieren
MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener:
tags:
- { name: contao.hook, hook: indexPage, method: onIndexPage }
- { name: contao.hook, hook: indexPage, method: onIndexPage }
MummertMedia\ContaoMeilisearchBundle\EventListener\PdfCleanupListener:
tags:
- { name: kernel.event_listener, event: terminal42.escargot.last_chunk, method: onLastChunk }
+23
View File
@@ -8,6 +8,29 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class PdfIndexService
{
private int $crawlStart = 0;
public function startCrawl(): void
{
if ($this->crawlStart === 0) {
$this->crawlStart = time();
error_log('PDF Crawl Start: ' . $this->crawlStart);
}
}
public function cleanupRemovedPdfs(): void
{
if ($this->crawlStart === 0) {
return;
}
Database::getInstance()
->prepare('DELETE FROM tl_search_pdf WHERE tstamp < ?')
->execute($this->crawlStart);
error_log('PDF Cleanup abgeschlossen');
}
private string $projectDir;
public function __construct(ParameterBagInterface $params)