Add diagnostics for unresolved org tag enrichment rows
This commit is contained in:
@@ -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,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -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 ($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;
|
||||
|
||||
Reference in New Issue
Block a user