Bugfix
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user