Skip to content

Commit

Permalink
Handle metadata formats as entities
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jan 6, 2024
1 parent 152bc90 commit 1e27542
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ public function getMetadataFormats(?string $identifier = null): Result
* Get a single record.
*
* @param string $identifier The record identifier
* @param string $metadataPrefix The metadata prefix
* @param Format $format The metadata format
*
* @return ?Record The record or NULL on failure
*/
public function getRecord(string $identifier, string $metadataPrefix): ?Record
public function getRecord(string $identifier, Format $format): ?Record
{
return $this->entityManager->find(
Record::class,
[
'identifier' => $identifier,
'format' => $metadataPrefix
'format' => $format
]
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Middleware/GetRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCC\OaiPmh2\Middleware;

use OCC\OaiPmh2\Database;
use OCC\OaiPmh2\Database\Format;
use OCC\OaiPmh2\Document;
use OCC\OaiPmh2\Middleware;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -46,7 +47,9 @@ class GetRecord extends Middleware
protected function prepareResponse(ServerRequestInterface $request): void
{
$params = $request->getAttributes();
$oaiRecord = Database::getInstance()->getRecord($params['identifier'], $params['metadataPrefix']);
/** @var Format */
$format = Database::getInstance()->getEntityManager()->getReference(Format::class, $params['metadataPrefix']);
$oaiRecord = Database::getInstance()->getRecord($params['identifier'], $format);

if (!isset($oaiRecord)) {
if (Database::getInstance()->idDoesExist($params['identifier'])) {
Expand Down

0 comments on commit 1e27542

Please sign in to comment.