Skip to content

Commit

Permalink
fix: areabrick detection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jdreesen committed Nov 13, 2024
1 parent 1af3e2c commit a7b1ec5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Bricks/Populator/BrickPagePopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 IN ("area", "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);
}
}
Expand Down

0 comments on commit a7b1ec5

Please sign in to comment.