From 2addb22b1af355bba38051d5e6ee58ee6f100e28 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Wed, 13 Nov 2024 13:38:42 +0100 Subject: [PATCH] fix: areabrick detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way of checking if a page had certain areabricks was too imprecise. It only checked if the brick identifier was in the `data` column of the `documents_editables` table. However, if the identifier is searched for without a delimiter, it will erroneously be found as a substring in longer identifiers (for example, “buttons” and “shortcut-buttons”). Therefore, we should only check whether the identifier occurs exactly as a type of an areablock. --- src/Bricks/Populator/BrickPagePopulator.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bricks/Populator/BrickPagePopulator.php b/src/Bricks/Populator/BrickPagePopulator.php index 494c7cc..05c25a3 100644 --- a/src/Bricks/Populator/BrickPagePopulator.php +++ b/src/Bricks/Populator/BrickPagePopulator.php @@ -28,20 +28,22 @@ public function __construct( public function populate(object $target, object $source, ?object $ctx = null): void { - $editableUsages = $this->connection->createQueryBuilder() + $areabrickName = $source->getId(); + $documentIds = $this->connection->createQueryBuilder() ->select('documentId') ->distinct() ->from('documents_editables') - ->where('data LIKE :data') - ->setParameter('data', '%' . $source->getId() . '%') + ->where('type = "areablock"') + ->andWhere('data LIKE :data') + ->setParameter('data', sprintf('%%"type";s:%d:"%s";%%', strlen($areabrickName), $areabrickName)) ->execute(); // Todo: remove after upgrade to doctrine/dbal >=3.9 - \assert($editableUsages instanceof Result); + \assert($documentIds instanceof Result); $target->pages = []; - foreach ($editableUsages->fetchFirstColumn() as $docId) { - if ($page = Page::getById($docId)) { + foreach ($documentIds->fetchFirstColumn() as $id) { + if ($page = Page::getById($id)) { $target->pages[] = $this->pageConverter->convert($page); } }