Compare commits

...

3 Commits

Author SHA1 Message Date
Jürgen Mummert 00f65ffd45 Fix nullable logger guard in organization listing listener 2026-02-22 17:12:29 +01:00
Jürgen Mummert 142cab2203 Broaden organization tag enrichment fallbacks for production data variants 2026-02-22 17:10:39 +01:00
Jürgen Mummert acf3d02d13 Add diagnostics for unresolved org tag enrichment rows 2026-02-22 17:06:08 +01:00
@@ -10,12 +10,14 @@ use Contao\Template;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Psr\Log\LoggerInterface;
#[AsHook('parseTemplate', method: 'onParseTemplate')]
class OrganizationListingTemplateDataListener
{
public function __construct(
private readonly Connection $connection,
private readonly ?LoggerInterface $logger = null,
) {
}
@@ -34,6 +36,10 @@ class OrganizationListingTemplateDataListener
$rowToOrganizationIdMap = [];
$rowToTitleMap = [];
$resolvedByRowIdCount = 0;
$resolvedByTitleToIdCount = 0;
$enrichedByTitleTagFallbackCount = 0;
foreach ($tbody as $rowIndex => $row) {
if (!\is_array($row)) {
continue;
@@ -43,6 +49,7 @@ class OrganizationListingTemplateDataListener
if ($organizationId > 0) {
$rowToOrganizationIdMap[(int) $rowIndex] = $organizationId;
++$resolvedByRowIdCount;
continue;
}
@@ -65,6 +72,7 @@ class OrganizationListingTemplateDataListener
if ($organizationId > 0) {
$rowToOrganizationIdMap[$rowIndex] = $organizationId;
++$resolvedByTitleToIdCount;
}
}
}
@@ -110,6 +118,44 @@ class OrganizationListingTemplateDataListener
$tbody[$rowIndex]['tag_labels']['content'] = implode(', ', $tagData['labels']);
$tbody[$rowIndex]['tag_slugs']['content'] = implode(',', $tagData['slugs']);
$tbody[$rowIndex]['tags']['content'] = implode(', ', $tagData['labels']);
++$enrichedByTitleTagFallbackCount;
}
$rowsWithoutTagSlugs = 0;
$sampleUnresolvedTitles = [];
foreach ($tbody as $row) {
if (!\is_array($row)) {
continue;
}
$tagSlugs = $this->extractRowFieldContent($row, 'tag_slugs');
if ('' !== $tagSlugs) {
continue;
}
++$rowsWithoutTagSlugs;
if (\count($sampleUnresolvedTitles) < 10) {
$title = $this->normalizeTitle($this->extractRowFieldContent($row, 'title'));
if ('' !== $title) {
$sampleUnresolvedTitles[] = $title;
}
}
}
if (null !== $this->logger && $rowsWithoutTagSlugs > 0) {
$this->logger->warning('Organization listing tag enrichment left rows without tag slugs.', [
'template' => (string) $template->getName(),
'totalRows' => \count($tbody),
'resolvedByRowId' => $resolvedByRowIdCount,
'resolvedByTitleToId' => $resolvedByTitleToIdCount,
'enrichedByTitleTagFallback' => $enrichedByTitleTagFallbackCount,
'rowsWithoutTagSlugs' => $rowsWithoutTagSlugs,
'sampleUnresolvedTitles' => array_values(array_unique($sampleUnresolvedTitles)),
]);
}
$template->tbody = $tbody;
@@ -266,6 +312,22 @@ class OrganizationListingTemplateDataListener
)->fetchAllAssociative();
}
if ([] === $rows) {
$rows = $this->connection->executeQuery(
'SELECT r.pid AS organization_id, r.tag_id, t.tag AS label FROM tl_tags_rel r INNER JOIN tl_tags t ON t.id = r.tag_id WHERE r.field = ? AND r.pid IN (?) ORDER BY r.pid ASC, r.tag_id ASC',
['tags', $organizationIds],
[ParameterType::STRING, ArrayParameterType::INTEGER],
)->fetchAllAssociative();
}
if ([] === $rows) {
$rows = $this->connection->executeQuery(
'SELECT r.pid AS organization_id, r.tag_id, t.tag AS label FROM tl_tags_rel r INNER JOIN tl_tags t ON t.id = r.tag_id WHERE r.pid IN (?) ORDER BY r.pid ASC, r.tag_id ASC',
[$organizationIds],
[ArrayParameterType::INTEGER],
)->fetchAllAssociative();
}
$map = [];
$seen = [];
@@ -315,6 +377,22 @@ class OrganizationListingTemplateDataListener
[ParameterType::STRING, ArrayParameterType::STRING],
)->fetchAllAssociative();
if ([] === $rows) {
$rows = $this->connection->executeQuery(
'SELECT o.title, r.tag_id, t.tag AS label FROM tl_organization o INNER JOIN tl_tags_rel r ON r.pid = o.id AND r.field = ? INNER JOIN tl_tags t ON t.id = r.tag_id WHERE o.title IN (?) ORDER BY o.title ASC, r.tag_id ASC',
['tags', $titles],
[ParameterType::STRING, ArrayParameterType::STRING],
)->fetchAllAssociative();
}
if ([] === $rows) {
$rows = $this->connection->executeQuery(
'SELECT o.title, r.tag_id, t.tag AS label FROM tl_organization o INNER JOIN tl_tags_rel r ON r.pid = o.id INNER JOIN tl_tags t ON t.id = r.tag_id WHERE o.title IN (?) ORDER BY o.title ASC, r.tag_id ASC',
[$titles],
[ArrayParameterType::STRING],
)->fetchAllAssociative();
}
$map = [];
$seen = [];