- throws an error if oai request has different granularities for the from and until parameters
This commit is contained in:
parent
77fb177f5e
commit
9d736aa2b7
|
@ -350,18 +350,6 @@ class RequestController extends Controller
|
||||||
$this->proc->setParameter('', 'oai_error_message', 'The verb provided in the request is illegal.');
|
$this->proc->setParameter('', 'oai_error_message', 'The verb provided in the request is illegal.');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkmydate($date)
|
|
||||||
{
|
|
||||||
$tempDate = explode('-', $date);
|
|
||||||
return checkdate($tempDate[1], $tempDate[2], $tempDate[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validateDate($date, $format = 'Y-m-d H:i:s')
|
|
||||||
{
|
|
||||||
$d = \DateTime::createFromFormat($format, $date);
|
|
||||||
return $d && $d->format($format) == $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for handling lists.
|
* Helper method for handling lists.
|
||||||
*
|
*
|
||||||
|
@ -437,18 +425,24 @@ class RequestController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (array_key_exists('from', $oaiRequest) && array_key_exists('until', $oaiRequest)) {
|
if (array_key_exists('from', $oaiRequest) && array_key_exists('until', $oaiRequest)) {
|
||||||
// $from = $oaiRequest['from'];
|
$from = $oaiRequest['from'];
|
||||||
// $fromDate = \Illuminate\Support\Carbon::parse($from);
|
$until = $oaiRequest['until'];
|
||||||
// $until = $oaiRequest['until'];
|
|
||||||
// }
|
if (strlen($from) != strlen($until)) {
|
||||||
|
throw new OaiModelException(
|
||||||
|
'The request has different granularities for the from and until parameters.',
|
||||||
|
OaiModelError::BADARGUMENT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists('until', $oaiRequest)) {
|
if (array_key_exists('until', $oaiRequest)) {
|
||||||
$until = $oaiRequest['until'];
|
$until = $oaiRequest['until'];
|
||||||
try {
|
try {
|
||||||
$untilDate = \Illuminate\Support\Carbon::parse($until);
|
$untilDate = \Illuminate\Support\Carbon::parse($until);
|
||||||
// if (strtotime($untilDate) > 0) {
|
// if (strtotime($untilDate) > 0) {
|
||||||
$earliestPublicationDate = Dataset::earliestPublicationDate()->server_date_published;//->format('Y-m-d\TH:i:s\Z');
|
$earliestPublicationDate = Dataset::earliestPublicationDate()->server_date_published;
|
||||||
if ($earliestPublicationDate->gt($untilDate)) {
|
if ($earliestPublicationDate->gt($untilDate)) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
"earliestDatestamp is greater than given until date. The given values results in an empty list.",
|
"earliestDatestamp is greater than given until date. The given values results in an empty list.",
|
||||||
|
@ -458,25 +452,24 @@ class RequestController extends Controller
|
||||||
$finder->where('server_date_published', '<=', $untilDate);
|
$finder->where('server_date_published', '<=', $untilDate);
|
||||||
$test = $finder->toSql();
|
$test = $finder->toSql();
|
||||||
}
|
}
|
||||||
}
|
} catch (OaiModelException $e) {
|
||||||
catch (OaiModelException $e) {
|
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
"earliestDatestamp is greater than given until date. The given values results in an empty list.",
|
"earliestDatestamp is greater than given until date. The given values results in an empty list.",
|
||||||
OaiModelError::NORECORDSMATCH
|
OaiModelError::NORECORDSMATCH
|
||||||
);
|
);
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (\Exception $e) {
|
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
'The until date argument is not valid.',
|
'The until date argument is not valid.',
|
||||||
OaiModelError::BADARGUMENT
|
OaiModelError::BADARGUMENT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('from', $oaiRequest)) {
|
if (array_key_exists('from', $oaiRequest)) {
|
||||||
$from = $oaiRequest['from'];
|
$from = $oaiRequest['from'];
|
||||||
try {
|
try {
|
||||||
$fromDate = \Illuminate\Support\Carbon::parse($from);
|
$fromDate = \Illuminate\Support\Carbon::parse($from);
|
||||||
// if (strtotime($fromDate) > 0) {
|
// if (strtotime($fromDate) > 0) {
|
||||||
$now = new Carbon();
|
$now = new Carbon();
|
||||||
if ($fromDate->gt($now)) {
|
if ($fromDate->gt($now)) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
|
@ -486,14 +479,12 @@ class RequestController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$finder->where('server_date_published', '>=', $fromDate);
|
$finder->where('server_date_published', '>=', $fromDate);
|
||||||
}
|
}
|
||||||
}
|
} catch (OaiModelException $e) {
|
||||||
catch (OaiModelException $e) {
|
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
"Given from date is greater than now. The given values results in an empty list.",
|
"Given from date is greater than now. The given values results in an empty list.",
|
||||||
OaiModelError::NORECORDSMATCH
|
OaiModelError::NORECORDSMATCH
|
||||||
);
|
);
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (\Exception $e) {
|
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
'The from date argument is not valid.',
|
'The from date argument is not valid.',
|
||||||
OaiModelError::BADARGUMENT
|
OaiModelError::BADARGUMENT
|
||||||
|
@ -501,6 +492,7 @@ class RequestController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$totalIds = $finder->count();
|
$totalIds = $finder->count();
|
||||||
$reldocIds = $finder->orderBy('publish_id')->pluck('publish_id')->toArray();
|
$reldocIds = $finder->orderBy('publish_id')->pluck('publish_id')->toArray();
|
||||||
}
|
}
|
||||||
|
@ -539,6 +531,7 @@ class RequestController extends Controller
|
||||||
$this->setParamResumption($res, $cursor, $totalIds);
|
$this->setParamResumption($res, $cursor, $totalIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set parameters for resumptionToken-line.
|
* Set parameters for resumptionToken-line.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user