Skip to content

Commit

Permalink
[BUGFIX] Record the creation of new records to process all relevant r…
Browse files Browse the repository at this point in the history
…ecords for the buildRecordTree request

Resolves: https://projekte.in2code.de/issues/63386
  • Loading branch information
vertexvaar committed May 2, 2024
1 parent 6fba47e commit 63c1c1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
32 changes: 32 additions & 0 deletions Classes/Component/Core/RecordIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

use In2code\In2publishCore\Component\Core\Record\Model\Record;

use function array_keys;

class RecordIndex
{
/**
* @var RecordCollection<int, Record>
*/
private RecordCollection $records;
/** @var array<RecordCollection> */
private array $recordings = [];

public function __construct()
{
Expand All @@ -20,6 +24,9 @@ public function __construct()

public function addRecord(Record $record): void
{
foreach (array_keys($this->recordings) as $recordingName) {
$this->recordings[$recordingName]->addRecord($record);
}
$this->records->addRecord($record);
}

Expand All @@ -46,4 +53,29 @@ public function getRecordCollection(): RecordCollection
{
return $this->records;
}

/**
* @return array<Record>
*/
public function getRecordsByProperties(string $classification, array $properties)
{
return $this->records->getRecordsByProperties($classification, $properties);
}

public function startRecordingNewRecords(string $name): void
{
$this->recordings[$name] = new RecordCollection();
}

public function getRecording(string $name): RecordCollection
{
return $this->recordings[$name];
}

public function stopRecordingAndGetRecords(string $name): RecordCollection
{
$records = $this->recordings[$name];
unset($this->recordings[$name]);
return $records;
}
}
14 changes: 9 additions & 5 deletions Classes/Component/Core/RecordTree/RecordTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class RecordTreeBuilder

public function buildRecordTree(RecordTreeBuildRequest $request): RecordTree
{
$this->recordIndex->startRecordingNewRecords('buildRecordTree');

$recordTree = new RecordTree([], $request);

$recordCollection = new RecordCollection();
Expand All @@ -50,13 +52,15 @@ public function buildRecordTree(RecordTreeBuildRequest $request): RecordTree

$this->findPagesRecursively($defaultIdRequest, $recordCollection);

$this->findAllRecordsOnPages($recordCollection);

$this->findRecordsByTca($recordCollection, $request);
$pagesCollection = $this->recordIndex->getRecording('buildRecordTree');
$this->findAllRecordsOnPages($pagesCollection);

$recordCollection->connectTranslations();
$allRecordsCollection = $this->recordIndex->getRecording('buildRecordTree');
$this->findRecordsByTca($allRecordsCollection, $request);

$recordCollection->processDependencies(
$allNewRecords = $this->recordIndex->stopRecordingAndGetRecords('buildRecordTree');
$allNewRecords->connectTranslations();
$allNewRecords->processDependencies(
$request,
$this->demandsFactory,
$this->demandResolver,
Expand Down

0 comments on commit 63c1c1f

Please sign in to comment.