diff --git a/app/Classes/Bundle.php b/app/Classes/Bundle.php index 5587f84..f9d7db0 100644 --- a/app/Classes/Bundle.php +++ b/app/Classes/Bundle.php @@ -148,7 +148,7 @@ public function virtualMetadata(): Collection $mergedData = array_merge_recursive($mergedData, $this->metadata($additionalFile)->all() ?? []); } - $replacedData = array_replace_recursive($mergedData, $this->metadata('metadata')->all() ?? []); + $replacedData = array_merge_recursive($mergedData, $this->metadata('metadata')->all() ?? []); return collect($replacedData); } diff --git a/app/Services/Wikidata/WikidataExtractor.php b/app/Services/Wikidata/WikidataExtractor.php index a39f26b..9e8f007 100644 --- a/app/Services/Wikidata/WikidataExtractor.php +++ b/app/Services/Wikidata/WikidataExtractor.php @@ -202,28 +202,33 @@ private function parseSnak(array $data, bool $parentIncluded) $value = $data['datavalue']['value']; $valueType = $data['datavalue']['type']; + $dataType = $data['datatype']; - switch ($valueType) { - case 'wikibase-entityid': - $value = $this->replaceValue($value['id'], true, !$parentIncluded); - break; - case 'string': - $value = $this->replaceValue($value, true, !$parentIncluded); - break; - case 'time': - $value = $value['time']; - break; - case 'quantity': - $value = $value['amount']; - break; - case 'monolingualtext': - $value = $value['text']; - break; - case 'globecoordinate': - // Leave it as is - break; - default: - dd($data); + if ($dataType === 'external-id') { + $value = $this->replaceValue($value, true, !$parentIncluded, $data['property']); + } else { + switch ($valueType) { + case 'wikibase-entityid': + $value = $this->replaceValue($value['id'], true, !$parentIncluded); + break; + case 'string': + $value = $this->replaceValue($value, true, !$parentIncluded); + break; + case 'time': + $value = $value['time']; + break; + case 'quantity': + $value = $value['amount']; + break; + case 'monolingualtext': + $value = $value['text']; + break; + case 'globecoordinate': + // Leave it as is + break; + default: + dd($data); + } } return $value; @@ -249,7 +254,7 @@ private function replaceValue(string $value, bool $showCode = true, bool $showLa $both = $code !== $label ? sprintf('[%s] %s', $code, $label) : $value; - if (!empty($key)) { + if (!empty($key) && !empty($value)) { $template = $this->templates[$key]['template'] ?? null; if (!empty($template)) { @@ -306,9 +311,9 @@ private function includeProperties($includedData, $properties) $newSubKey = $key; if (is_string($newValues)) { - $newValues = $this->replaceValue($newValues, false, true, $propertyId); + $newValues = $this->replaceValue($newValues, false, true); } else { - $newSubKey = $this->replaceValue($key, false, true, $propertyId); + $newSubKey = $this->replaceValue($key, false, true); } unset($result[$newKey][$key]);