Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ private function getAdditionalMetadataFromDatabase(string $dmdId): array
// Exclude metadata with subentries, we will fetch them later.
$resultWithFormat = $this->metadataRepository->findWithFormat($this->configPid, $this->mdSec[$dmdId]['type']);
// Get all metadata without a format, but with a default value next.
$resultWithoutFormat = $this->metadataRepository->findWithoutFormat($this->configPid);
$resultWithoutFormat = $this->metadataRepository->findWithoutFormat();
// Merge both result sets.
$allResults = array_merge($resultWithFormat, $resultWithoutFormat);

Expand Down
44 changes: 25 additions & 19 deletions Classes/Domain/Repository/MetadataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,37 +173,43 @@ public function findWithFormat(int $pid, string $type): array
$queryBuilder->expr()->eq('tx_dlf_formats_joins.type', $queryBuilder->createNamedParameter($type))
);

$this->debugQueryBuilder($query);

return $query->executeQuery()->fetchAllAssociative();
}

/**
* Finds all metadata without a format, but with a default value.
*
* @param int $pid
*
* @return list<array<string,mixed>>
*
* @throws Exception
*/
public function findWithoutFormat(int $pid): array
public function findWithoutFormat(): array
{
$queryBuilder = $this->getQueryBuilder();
$query = $queryBuilder
->select(
self::TABLE . '.index_name AS index_name',
self::TABLE . '.is_sortable AS is_sortable',
self::TABLE . '.default_value AS default_value',
self::TABLE . '.format AS format'
)
->from(self::TABLE)
->where(
$queryBuilder->expr()->eq(self::TABLE . '.pid', $pid),
$queryBuilder->expr()->eq(self::TABLE . '.l18n_parent', 0),
$queryBuilder->expr()->eq(self::TABLE . '.format', 0),
$queryBuilder->expr()->neq(self::TABLE . '.default_value', $queryBuilder->createNamedParameter(''))
);
$query = $this->createQuery();

return $query->executeQuery()->fetchAllAssociative();
$constraints = [];
$constraints[] = $query->equals('l18nParent', 0);
$constraints[] = $query->equals('format', 0);
$constraints[] = $query->logicalNot($query->equals('defaultValue', ''));

$query->matching($query->logicalAnd(...$constraints));

$this->debugQuery($query);

$result = $query->execute();

$rows = [];
foreach ($result as $metadata) {
$rows[] = [
'index_name' => $metadata->getIndexName(),
'is_sortable' => $metadata->getIsSortable(),
'default_value' => $metadata->getDefaultValue(),
];
}

return $rows;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions Tests/Fixtures/Repository/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
,"uid","pid","tstamp","crdate","cruser_id","deleted","sys_language_uid","l18n_parent","l18n_diffsource","hidden","sorting","label","index_name","format","default_value","wrap","index_tokenized","index_stored","index_indexed","index_boost","is_sortable","is_facet","is_listed","index_autocomplete","status"
,5001,20000,1638557803,1631532810,1,0,0,0,,0,32,"Titel","title",1,,,0,1,1,1,1,0,1,1,0
,5002,20000,1638557803,1631532810,1,0,0,0,,0,31,"Sammlungen","collection",1,,,1,0,1,1,0,1,0,1,0
,5003,20000,1638557803,1631532810,1,0,0,0,,0,30,"Untertitel","untertitel",1,,,0,1,1,1,1,0,0,1,0
,5004,20000,1638557803,1631532810,1,0,0,0,,0,29,"Ort",place,1,,,0,1,1,1,1,0,0,1,0
,5005,20000,1638557803,1631532810,1,0,0,0,,0,30,"Autor",author,1,,,0,1,1,1,1,0,1,1,0
,5006,20000,1638557803,1631532810,1,0,0,0,,0,30,"Institution","institution",1,,,0,1,1,1,0,0,1,1,0
,5007,20000,1638557803,1631532810,1,0,0,0,,0,32,PURL,purl,1,,,0,0,0,0,0,0,0,0,0
,5003,20000,1638557803,1631532810,1,0,0,0,,0,30,"Untertitel","untertitel",0,,,0,1,1,1,1,0,0,1,0
,5004,20000,1638557803,1631532810,1,0,0,0,,0,29,"Ort","place",0,,,0,1,1,1,1,0,0,1,0
,5005,20000,1638557803,1631532810,1,0,0,0,,0,30,"Autor","author",0,xyz,,0,1,1,1,1,0,1,1,0
,5006,20000,1638557803,1631532810,1,0,0,0,,0,30,"Institution","institution",0,xyz,,0,1,1,1,0,0,1,1,0
,5007,20000,1638557803,1631532810,1,0,0,0,,0,32,"PURL","purl",0,xyz,,0,0,0,0,0,0,0,0,0
"tx_dlf_metadataformat",,,,,,,,,,,,,,
,"uid","pid","tstamp","crdate","cruser_id","deleted","parent_id","encoded","xpath","xpath_sorting","mandatory"
,5101,20000,1638557803,1631532810,1,0,5001,5202,"concat(./mods:titleInfo/mods:nonSort,"" "",./mods:titleInfo/mods:title)","./mods:titleInfo/mods:title",0
Expand Down
32 changes: 32 additions & 0 deletions Tests/Functional/Repository/MetadataRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,36 @@ public function canFindIndexedFields(): void
$metadata = $this->metadataRepository->findIndexedFields();
self::assertEquals(6, $metadata->count());
}

/**
* @test
* @group find
*/
public function canFindWithFormat(): void
{
$metadata = $this->metadataRepository->findWithFormat(20000, 'mods');
self::assertCount(2, $metadata);
self::assertEquals('title', $metadata[0]['index_name']);
self::assertEquals('collection', $metadata[1]['index_name']);

$metadata = $this->metadataRepository->findWithFormat(20000, 'alto');
self::assertEmpty($metadata);

$metadata = $this->metadataRepository->findWithFormat(20000, 'xyz');
self::assertEmpty($metadata);
}

/**
* @test
* @group find
*/
public function canFindWithoutFormat(): void
{
$metadata = $this->metadataRepository->findWithoutFormat();
self::assertCount(3, $metadata);
self::assertCount(3, $metadata[0]);
self::assertEquals('author', $metadata[0]['index_name']);
self::assertEquals('institution', $metadata[1]['index_name']);
self::assertEquals('purl', $metadata[2]['index_name']);
}
}
Loading