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 class IndexPageListener
{ {
public function __construct(
private PdfIndexService $pdfIndexService
) {}
public function onIndexPage(string $content, array &$data, array &$set): void public function onIndexPage(string $content, array &$data, array &$set): void
{ {
$this->pdfIndexService->startCrawl();
// Marker vorhanden? // Marker vorhanden?
if (!str_contains($content, 'MEILISEARCH_JSON')) { if (!str_contains($content, 'MEILISEARCH_JSON')) {
return; return;
@@ -100,11 +104,9 @@ class IndexPageListener
$pdfLinks = $this->findPdfLinks($content); $pdfLinks = $this->findPdfLinks($content);
if ($pdfLinks !== []) { if ($pdfLinks !== []) {
$this->pdfIndexService->startCrawl();
error_log('PDF gefunden'); error_log('PDF gefunden');
$this->pdfIndexService->handlePdfLinks($pdfLinks);
/** @var PdfIndexService $service */
$service = System::getContainer()->get(PdfIndexService::class);
$service->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();
}
}
+4
View File
@@ -10,3 +10,7 @@ services:
MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener: MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener:
tags: 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 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; private string $projectDir;
public function __construct(ParameterBagInterface $params) public function __construct(ParameterBagInterface $params)