Skip to content

Commit e45fcb3

Browse files
authored
[FINNA-3637] Split merging of component parts to its own method (#178)
1 parent bbc26ce commit e45fcb3

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/RecordManager/Base/Solr/SolrUpdater.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,16 +1982,12 @@ protected function createSolrArray(
19821982
}
19831983

19841984
if ($hasComponentParts && null !== $components) {
1985-
$changeDate = null;
1986-
$mergedComponents += $metadataRecord->mergeComponentParts(
1985+
$mergedComponents += $this->mergeComponentParts(
1986+
$metadataRecord,
1987+
$record,
19871988
$components,
1988-
$changeDate
1989+
$source
19891990
);
1990-
// Use latest date as the host record date
1991-
// @phpstan-ignore-next-line
1992-
if (null !== $changeDate && $changeDate > $record['date']) {
1993-
$record['date'] = $changeDate;
1994-
}
19951991
}
19961992
if (isset($settings['solrTransformationXSLT'])) {
19971993
$params = [
@@ -2164,6 +2160,34 @@ protected function createSolrArray(
21642160
return $data;
21652161
}
21662162

2163+
/**
2164+
* Merge component parts to record
2165+
*
2166+
* @param AbstractRecord $metadataRecord Record to merge component parts to
2167+
* @param array $record Database record
2168+
* @param \Traversable $components Component parts to merge
2169+
* @param string $source Source ID
2170+
*
2171+
* @return int Amount of merged component parts
2172+
*/
2173+
protected function mergeComponentParts(
2174+
AbstractRecord $metadataRecord,
2175+
array &$record,
2176+
\Traversable $components,
2177+
string $source
2178+
): int {
2179+
$changeDate = null;
2180+
$mergedComponents = $metadataRecord->mergeComponentParts(
2181+
$components,
2182+
$changeDate
2183+
);
2184+
// Use latest date as the host record date
2185+
if (null !== $changeDate && $changeDate > $record['date']) {
2186+
$record['date'] = $changeDate;
2187+
}
2188+
return $mergedComponents;
2189+
}
2190+
21672191
/**
21682192
* Add work identification keys
21692193
*

tests/RecordManagerTest/Base/Solr/SolrUpdaterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace RecordManagerTest\Base\Solr;
3131

32+
use ArrayIterator;
3233
use RecordManager\Base\Database\DatabaseInterface;
3334
use RecordManager\Base\Database\MongoDatabase;
3435
use RecordManager\Base\Enrichment\PluginManager as EnrichmentPluginManager;
@@ -187,14 +188,14 @@ public function testMergedComponents(): void
187188
'suppressed' => ['$in' => [null, false]],
188189
'source_id' => 'test',
189190
];
190-
$records = [
191+
$records = new ArrayIterator([
191192
[
192193
'_id' => 'test.2',
193194
],
194195
[
195196
'_id' => 'test.3',
196197
],
197-
];
198+
]);
198199
$recordMap = [
199200
[$params, [], $records[0]],
200201
];

0 commit comments

Comments
 (0)