Some bugfixes inspired by @antennaio

This commit is contained in:
Sebastian Meyer 2017-05-13 13:23:24 +02:00
parent 008d5599c4
commit 98144a2c4a
2 changed files with 11 additions and 10 deletions

View File

@ -129,7 +129,7 @@ class OAI2Server {
}
public function GetRecord() {
if (!isset($this->args['metadataPrefix'])) {
if (!isset($this->args['identifier']) || !isset($this->args['metadataPrefix'])) {
$this->errors[] = new OAI2Exception('badArgument');
} else {
$metadataFormats = call_user_func($this->listMetadataFormatsCallback);
@ -137,9 +137,6 @@ class OAI2Server {
$this->errors[] = new OAI2Exception('cannotDisseminateFormat');
}
}
if (!isset($this->args['identifier'])) {
$this->errors[] = new OAI2Exception('badArgument');
}
if (empty($this->errors)) {
try {
if ($record = call_user_func($this->getRecordCallback, $this->args['identifier'], $this->args['metadataPrefix'])) {
@ -208,7 +205,9 @@ class OAI2Server {
}
if (empty($this->errors)) {
try {
$records_count = call_user_func($this->listRecordsCallback, $metadataPrefix, $this->formatTimestamp($from), $this->formatTimestamp($until), true);
if (!($records_count = call_user_func($this->listRecordsCallback, $metadataPrefix, $this->formatTimestamp($from), $this->formatTimestamp($until), true))) {
throw new OAI2Exception('noRecordsMatch');
}
$records = call_user_func($this->listRecordsCallback, $metadataPrefix, $this->formatTimestamp($from), $this->formatTimestamp($until), false, $deliveredRecords, $maxItems);
foreach ($records as $record) {
if ($this->verb == 'ListRecords') {
@ -230,7 +229,7 @@ class OAI2Server {
$expirationDatetime = null;
}
if (isset($restoken)) {
$this->response->createResumptionToken($restoken, $expirationDatetime, $records_count, $deliveredRecords);
$this->response->createResumptionToken($restoken, $expirationDatetime, $records_count, $deliveredRecords-$maxItems);
}
} catch (OAI2Exception $e) {
$this->errors[] = $e;

View File

@ -34,13 +34,12 @@ class OAI2XMLResponse {
$this->addChild($oai_node, 'responseDate', gmdate('Y-m-d\TH:i:s\Z'));
$this->doc->appendChild($oai_node);
$request = $this->addChild($this->doc->documentElement, 'request', $uri);
if (!empty($this->verb)) {
$request->setAttribute('verb', $this->verb);
}
foreach($request_args as $key => $value) {
$request->setAttribute($key, $value);
}
if (!empty($this->verb)) {
$this->verbNode = $this->addChild($this->doc->documentElement, $this->verb);
}
}
/**
@ -67,6 +66,9 @@ class OAI2XMLResponse {
* @param $value Type: string. The content of appending node.
*/
function addToVerbNode($nodeName, $value = null) {
if (!isset($this->verbNode) && !empty($this->verb)) {
$this->verbNode = $this->addChild($this->doc->documentElement, $this->verb);
}
return $this->addChild($this->verbNode, $nodeName, $value);
}