19 declare(strict_types=1);
52 $this->records_repository = $resource_status_repository;
55 $this->valid_md_prefix =
'oai_dc';
56 $this->default_set =
'default';
57 $this->max_list_size = 100;
62 if ($request->
verb() === Verb::NULL) {
63 return $this->writer->writeErrorResponse(
65 $this->writer->writeError(
67 'No valid OAI-PMH verb in request.' 72 return match ($request->
verb()) {
73 Verb::GET_RECORD => $this->
getRecord($request),
74 Verb::IDENTIFY => $this->
identify($request),
78 default => $this->writer->writeErrorResponse(
80 $this->writer->writeError(
82 'No valid OAI-PMH verb in request.' 102 $errors[] = $this->writer->writeError(
103 Error::CANNOT_DISSEMINATE_FORMAT,
104 'This repository only supports oai_dc as metadata format.' 112 $errors[] = $this->writer->writeError(
113 Error::ID_DOES_NOT_EXIST,
114 'Identifier "' . $identifier .
'" is invalid for this repository.' 116 } elseif (is_null($record = $this->records_repository->getRecordByIdentifier(
117 $this->removePrefixFromIdentifier($identifier)
119 $errors[] = $this->writer->writeError(
120 Error::ID_DOES_NOT_EXIST,
121 'This repository does not have a record with identifier "' . $identifier .
'".' 126 if (!empty($errors)) {
127 return $this->writer->writeErrorResponse($request, ...$errors);
129 return $this->writer->writeResponse(
131 $this->writer->writeRecord(
132 $this->settings->getOAIIdentifierPrefix() . $record->infos()->identfifier(),
133 $record->infos()->datestamp(),
142 return $this->writer->writeErrorResponse(
151 return $this->writer->writeResponse(
153 ...$this->writer->writeIdentifyElements(
154 $this->settings->getOAIRepositoryName(),
156 $this->records_repository->getEarliestDatestamp(),
157 $this->
settings->getOAIContactMail()
167 Verb::LIST_MD_FORMATS,
175 $errors[] = $this->writer->writeError(
176 Error::ID_DOES_NOT_EXIST,
177 'Identifier "' . $identifier .
'" is invalid for this repository.' 179 } elseif (!$this->records_repository->doesRecordWithIdentifierExist(
180 $this->removePrefixFromIdentifier($identifier)
182 $errors[] = $this->writer->writeError(
183 Error::ID_DOES_NOT_EXIST,
184 'This repository does not have a record with identifier "' . $identifier .
'".' 189 if (!empty($errors)) {
190 return $this->writer->writeErrorResponse($request, ...$errors);
192 return $this->writer->writeResponse(
194 $this->writer->writeMetadataFormat()
208 if ($request->
hasArgument(Argument::RESUMPTION_TOKEN)) {
209 $errors[] = $this->writer->writeError(
210 Error::BAD_RESUMTPION_TOKEN,
211 'ListSets does not issue resumption tokens.' 215 if (!empty($errors)) {
216 return $this->writer->writeErrorResponse($request, ...$errors);
218 return $this->writer->writeResponse(
220 $this->writer->writeSet($this->default_set, $this->default_set)
229 [Argument::MD_PREFIX],
231 [Argument::RESUMPTION_TOKEN]
234 Verb::LIST_IDENTIFIERS,
243 $errors[] = $this->writer->writeError(
244 Error::NO_RECORDS_MATCH,
245 "This repository only supports a trivial set named 'default'." 253 $errors[] = $this->writer->writeError(
254 Error::CANNOT_DISSEMINATE_FORMAT,
255 'This repository only supports oai_dc as metadata format.' 259 $effective_request = clone $request;
261 if ($request->hasArgument(Argument::RESUMPTION_TOKEN)) {
262 $token = $request->argumentValue(Argument::RESUMPTION_TOKEN);
263 if (!$this->token_handler->isTokenValid(
$token)) {
264 $errors[] = $this->writer->writeError(
265 Error::BAD_RESUMTPION_TOKEN,
266 'Invalid resumption token for this repository.' 268 return $this->writer->writeErrorResponse($effective_request, ...$errors);
270 $effective_request = $this->token_handler->appendArgumentsFromTokenToRequest($effective_request,
$token);
271 $offset = $this->token_handler->getOffsetFromToken(
$token);
275 if ($effective_request->hasArgument(Argument::FROM_DATE)) {
276 $from_date_string = $effective_request->argumentValue(Argument::FROM_DATE);
277 if ($this->isStringValidAsDate($from_date_string)) {
278 $from_date = $this->getDateFromString($from_date_string);
280 $errors[] = $this->writer->writeError(
282 'The date "' . $from_date_string .
'" is invalid for this repository.' 287 if ($effective_request->hasArgument(Argument::UNTIL_DATE)) {
288 $until_date_string = $effective_request->argumentValue(Argument::UNTIL_DATE);
289 if ($this->isStringValidAsDate($until_date_string)) {
290 $until_date = $this->getDateFromString($until_date_string);
292 $errors[] = $this->writer->writeError(
294 'The date "' . $until_date_string .
'" is invalid for this repository.' 300 if ($effective_request->verb() === Verb::LIST_IDENTIFIERS) {
301 $record_infos = $this->records_repository->getRecordInfos(
304 $this->max_list_size,
307 foreach ($record_infos as $info) {
308 $content_xmls[] = $this->writer->writeRecordHeader(
309 $this->
settings->getOAIIdentifierPrefix() . $info->identfifier(),
313 } elseif ($effective_request->verb() === Verb::LIST_RECORDS) {
314 $records = $this->records_repository->getRecords(
317 $this->max_list_size,
320 foreach ($records as $record) {
321 $content_xmls[] = $this->writer->writeRecord(
322 $this->
settings->getOAIIdentifierPrefix() . $record->infos()->identfifier(),
323 $record->infos()->datestamp(),
328 throw new \ilMDOERExposerException(
'Invalid verb handling.');
331 if (empty($content_xmls)) {
332 $errors[] = $this->writer->writeError(
333 Error::NO_RECORDS_MATCH,
334 'No matching records found.' 338 $count = $this->records_repository->getRecordCount($from_date, $until_date);
340 $request->hasArgument(Argument::RESUMPTION_TOKEN) ||
341 $this->max_list_size < $count
344 if ($offset + $this->max_list_size < $count) {
345 $new_token = $this->token_handler->generateToken(
346 $offset + $this->max_list_size,
351 $content_xmls[] = $this->writer->writeResumptionToken(
358 if (!empty($errors)) {
359 return $this->writer->writeErrorResponse($request, ...$errors);
361 return $this->writer->writeResponse(
369 if (empty($arguments)) {
370 $message = $verb->value .
' must come with additional arguments.';
373 foreach ($arguments as $argument) {
374 $arg_strings[] = $argument->value;
376 $message = implode(
', ', $arg_strings) .
377 ' is not a valid set of arguments for ' . $verb->value .
'.';
379 return $this->writer->writeError(
387 return str_starts_with($identifier, $this->
settings->getOAIIdentifierPrefix()) &&
388 substr($identifier, strlen($this->
settings->getOAIIdentifierPrefix())) !==
'';
393 if (str_starts_with($identifier, $this->
settings->getOAIIdentifierPrefix())) {
394 $identifier = substr($identifier, strlen($this->
settings->getOAIIdentifierPrefix()));
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null