Bugfix
This commit is contained in:
@@ -7,12 +7,10 @@ use MummertMedia\ContaoMeilisearchBundle\Service\PdfIndexService;
|
|||||||
|
|
||||||
class IndexPageListener
|
class IndexPageListener
|
||||||
{
|
{
|
||||||
public function __construct(
|
private ?PdfIndexService $pdfIndexService = null;
|
||||||
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;
|
||||||
@@ -98,18 +96,27 @@ class IndexPageListener
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* =====================
|
* =====================
|
||||||
* PDF-ERKENNUNG (DEBUG)
|
* PDF-ERKENNUNG
|
||||||
* =====================
|
* =====================
|
||||||
*/
|
*/
|
||||||
$pdfLinks = $this->findPdfLinks($content);
|
$pdfLinks = $this->findPdfLinks($content);
|
||||||
|
|
||||||
if ($pdfLinks !== []) {
|
if ($pdfLinks !== []) {
|
||||||
$this->pdfIndexService->startCrawl();
|
|
||||||
error_log('PDF gefunden');
|
error_log('PDF gefunden');
|
||||||
|
|
||||||
|
// PdfIndexService lazy aus dem Container holen
|
||||||
|
if ($this->pdfIndexService === null) {
|
||||||
|
$this->pdfIndexService = System::getContainer()->get(PdfIndexService::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdfIndexService->startCrawl();
|
||||||
$this->pdfIndexService->handlePdfLinks($pdfLinks);
|
$this->pdfIndexService->handlePdfLinks($pdfLinks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* =====================================================
|
||||||
|
* JSON aus Marker extrahieren
|
||||||
|
* ===================================================== */
|
||||||
private function extractMeilisearchJson(string $content): ?array
|
private function extractMeilisearchJson(string $content): ?array
|
||||||
{
|
{
|
||||||
if (!preg_match('/<!--\s*MEILISEARCH_JSON\s*(\{.*?\})\s*-->/s', $content, $m)) {
|
if (!preg_match('/<!--\s*MEILISEARCH_JSON\s*(\{.*?\})\s*-->/s', $content, $m)) {
|
||||||
@@ -122,6 +129,9 @@ class IndexPageListener
|
|||||||
return is_array($data) ? $data : null;
|
return is_array($data) ? $data : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* =====================================================
|
||||||
|
* PDF-Links im Markup finden
|
||||||
|
* ===================================================== */
|
||||||
private function findPdfLinks(string $content): array
|
private function findPdfLinks(string $content): array
|
||||||
{
|
{
|
||||||
if (!preg_match_all(
|
if (!preg_match_all(
|
||||||
@@ -132,6 +142,8 @@ class IndexPageListener
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_unique(array_map('html_entity_decode', $matches[1]));
|
return array_unique(
|
||||||
|
array_map('html_entity_decode', $matches[1])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user