Skip to content

Commit

Permalink
[MAINTENANCE] Simplify usage of metadata sections (#1255)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
beatrycze-volk and sebastian-meyer authored Jul 5, 2024
1 parent 84a35c0 commit a6d244c
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ private function processMetadataSections(string $id, int $cPid, array $metadata)
// There is no metadata section for this structure node.
return [];
}
// Associative array used as set of available section types (dmdSec, techMD, ...)
$hasMetadataSection = [];
// Array used as set of available section types (dmdSec, techMD, ...)
$metadataSections = [];
// Load available metadata formats and metadata sections.
$this->loadFormats();
$this->magicGetMdSec();
Expand All @@ -513,19 +513,19 @@ private function processMetadataSections(string $id, int $cPid, array $metadata)
foreach ($mdIds as $dmdId) {
$mdSectionType = $this->mdSec[$dmdId]['section'];

if ($mdSectionType === 'dmdSec' && isset($hasMetadataSection['dmdSec'])) {
if ($this->hasMetadataSection($metadataSections, $mdSectionType, 'dmdSec')) {
continue;
}

if (!$this->extractAndProcessMetadata($dmdId, $mdSectionType, $metadata, $cPid, $hasMetadataSection)) {
if (!$this->extractAndProcessMetadata($dmdId, $mdSectionType, $metadata, $cPid, $metadataSections)) {
continue;
}

$hasMetadataSection[$mdSectionType] = true;
$metadataSections[] = $mdSectionType;
}

// Files are not expected to reference a dmdSec
if (isset($this->fileInfos[$id]) || isset($hasMetadataSection['dmdSec'])) {
if (isset($this->fileInfos[$id]) || in_array('dmdSec', $metadataSections)) {
return $metadata;
} else {
$this->logger->warning('No supported descriptive metadata found for logical structure with @ID "' . $id . '"');
Expand Down Expand Up @@ -564,13 +564,13 @@ private function getLogicalUnitType(string $id): array
* @param string $mdSectionType
* @param array $metadata
* @param integer $cPid
* @param array $hasMetadataSection
* @param array $metadataSections
*
* @return boolean
*/
private function extractAndProcessMetadata(string $dmdId, string $mdSectionType, array &$metadata, int $cPid, array $hasMetadataSection): bool
private function extractAndProcessMetadata(string $dmdId, string $mdSectionType, array &$metadata, int $cPid, array $metadataSections): bool
{
if ($mdSectionType === 'dmdSec' && isset($hasMetadataSection['dmdSec'])) {
if ($this->hasMetadataSection($metadataSections, $mdSectionType, 'dmdSec')) {
return true;
}

Expand All @@ -591,6 +591,22 @@ private function extractAndProcessMetadata(string $dmdId, string $mdSectionType,
return true;
}

/**
* Check if searched metadata section is stored in the array.
*
* @access private
*
* @param array $metadataSections
* @param string $currentMetadataSection
* @param string $searchedMetadataSection
*
* @return boolean
*/
private function hasMetadataSection(array $metadataSections, string $currentMetadataSection, string $searchedMetadataSection): bool
{
return $currentMetadataSection === $searchedMetadataSection && in_array($searchedMetadataSection, $metadataSections);
}

/**
* Process additional metadata.
*
Expand Down

0 comments on commit a6d244c

Please sign in to comment.