Fix ListRecords again

This commit is contained in:
Alexander Bigga 2021-11-18 20:26:37 +01:00
parent 70f5cbd241
commit f9c2c7ac9b
2 changed files with 31 additions and 26 deletions

View File

@ -110,7 +110,7 @@ class OaiPmhController extends AbstractController
'oai_dc' => [
'schema' => 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
'namespace' => 'http://www.openarchives.org/OAI/2.0/oai_dc/',
'requiredFields' => ['recordId'],
'requiredFields' => ['record_id'],
],
'epicur' => [
'schema' => 'http://www.persistent-identifier.de/xepicur/version1.0/xepicur.xsd',
@ -221,7 +221,7 @@ class OaiPmhController extends AbstractController
$record[] = ['dc:type' => $record['Text']];
if (!empty($record['partof'])) {
$document = $this->documentRepository->findOneByPartOf($metadata['partof']);
$document = $this->documentRepository->findOneByPartof($metadata['partof']);
if ($document) {
$metadata[] = ['dc:relation' => $document->getRecordId()];
@ -354,43 +354,44 @@ class OaiPmhController extends AbstractController
$this->error = 'badArgument';
return;
}
if (!array_key_exists($this->parameters['metadataPrefix'], $this->formats)) {
$this->error = 'cannotDisseminateFormat';
return;
}
$resArray = $this->documentRepository->getOaiRecord($this->settings, $this->parameters);
$document = $this->documentRepository->getOaiRecord($this->settings, $this->parameters);
if (!$resArray['uid']) {
if (!$document['uid']) {
$this->error = 'idDoesNotExist';
return;
}
// Check for required fields.
foreach ($this->formats[$this->parameters['metadataPrefix']]['requiredFields'] as $required) {
if (empty($resArray[$required])) {
if (empty($document[$required])) {
$this->error = 'cannotDisseminateFormat';
return;
}
}
// we need the collections as array later
$resArray['collections'] = explode(' ', $resArray['collections']);
$document['collections'] = explode(' ', $document['collections']);
// Add metadata
switch ($this->parameters['metadataPrefix']) {
case 'oai_dc':
$resArray['metadata'] = $this->getDcData($resArray);
$document['metadata'] = $this->getDcData($document);
break;
case 'epicur':
$resArray['metadata'] = $resArray;
$document['metadata'] = $document;
break;
case 'mets':
$resArray['metadata'] = $this->getMetsData($resArray);
$document['metadata'] = $this->getMetsData($document);
break;
}
$this->view->assign('record', $resArray);
$this->view->assign('record', $document);
}
/**
@ -515,7 +516,7 @@ class OaiPmhController extends AbstractController
if (!empty($resArray)) {
// check, if all required fields are available for a given identifier
foreach ($details['requiredFields'] as $required) {
$methodName = 'get' . ucfirst(trim($required));
$methodName = 'get' . GeneralUtility::underscoredToUpperCamelCase($required);
if (empty($resArray->$methodName())) {
// Skip metadata formats whose requirements are not met.
continue 2;

View File

@ -300,41 +300,45 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
return $result;
}
public function getOaiRecord($settings, $parameters) {
/**
* Find one document by given settings and identifier
*
* @param array $settings
* @param array $parameters
*
* @return array The found document object
*/
public function getOaiRecord($settings, $parameters)
{
$where = '';
if (!$settings['show_userdefined']) {
$where .= 'AND tx_dlf_collections.fe_cruser_id=0 ';
}
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_dlf_documents');
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_dlf_documents');
$sql = 'SELECT `tx_dlf_documents`.*, GROUP_CONCAT(DISTINCT `tx_dlf_collections`.`oai_name` ORDER BY `tx_dlf_collections`.`oai_name` SEPARATOR " ") AS `collections` ' .
'FROM `tx_dlf_documents` ' .
'INNER JOIN `tx_dlf_relations` ON `tx_dlf_relations`.`uid_local` = `tx_dlf_documents`.`uid` ' .
'INNER JOIN `tx_dlf_collections` ON `tx_dlf_collections`.`uid` = `tx_dlf_relations`.`uid_foreign` ' .
'WHERE `tx_dlf_documents`.`record_id` = ? ' .
'AND `tx_dlf_documents`.`pid` = ? ' .
'AND `tx_dlf_collections`.`pid` = ? ' .
'AND `tx_dlf_relations`.`ident`="docs_colls" ' .
$where .
'AND ' . Helper::whereExpression('tx_dlf_collections');
$where;
$values = [
$parameters['identifier'],
$settings['pages'],
$settings['pages']
$parameters['identifier']
];
$types = [
Connection::PARAM_STR,
Connection::PARAM_INT,
Connection::PARAM_INT
Connection::PARAM_STR
];
// Create a prepared statement for the passed SQL query, bind the given params with their binding types and execute the query
$statement = $connection->executeQuery($sql, $values, $types);
$resArray = $statement->fetch();
return $resArray;
return $statement->fetch();
}
/**