- OAI RequestController with time granularity for 'until' and 'from' parameter

This commit is contained in:
Arno Kaimbacher 2022-01-18 17:33:24 +01:00
parent 25ea8d40e1
commit 76b351fb73
2 changed files with 788 additions and 662 deletions

View File

@ -13,7 +13,8 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use \Exception; use \Exception;
use Carbon\Carbon; // use Carbon\Carbon;
use \Illuminate\Support\Carbon;
class RequestController extends Controller class RequestController extends Controller
{ {
@ -439,23 +440,29 @@ 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); $fromDate = Carbon::parse($from);
$until = $oaiRequest['until']; $until = $oaiRequest['until'];
$untilDate = \Illuminate\Support\Carbon::parse($until); $untilDate = \Illuminate\Support\Carbon::parse($until);
if (strlen($from) != strlen($until)) { if (strlen($from) != strlen($until)) {
throw new OaiModelException( throw new OaiModelException(
'The request has different granularities for the from and until parameters.', 'The request has different granularities for the from and until parameters.',
OaiModelError::BADARGUMENT OaiModelError::BADARGUMENT
); );
} }
$finder->whereDate('server_date_published', '>=', $fromDate) if ($fromDate->hour == 0) {
->whereDate('server_date_published', '<=', $untilDate); $fromDate = $fromDate->startOfDay();
$untilDate = $untilDate->endOfDay();
}
$finder->where('server_date_published', '>=', $fromDate)
->where('server_date_published', '<=', $untilDate);
$test = $finder->toSql(); $test = $finder->toSql();
} elseif (array_key_exists('until', $oaiRequest) && !array_key_exists('from', $oaiRequest)) { } elseif (array_key_exists('until', $oaiRequest) && !array_key_exists('from', $oaiRequest)) {
$until = $oaiRequest['until']; $until = $oaiRequest['until'];
try { try {
$untilDate = \Illuminate\Support\Carbon::parse($until); $untilDate = \Illuminate\Support\Carbon::parse($until);
if ($untilDate->hour == 0) {
$untilDate = $untilDate->endOfDay();
}
// if (strtotime($untilDate) > 0) { // if (strtotime($untilDate) > 0) {
$earliestPublicationDate = Dataset::earliestPublicationDate()->server_date_published; $earliestPublicationDate = Dataset::earliestPublicationDate()->server_date_published;
if ($earliestPublicationDate->gt($untilDate)) { if ($earliestPublicationDate->gt($untilDate)) {
@ -482,6 +489,9 @@ class RequestController extends Controller
$from = $oaiRequest['from']; $from = $oaiRequest['from'];
try { try {
$fromDate = \Illuminate\Support\Carbon::parse($from); $fromDate = \Illuminate\Support\Carbon::parse($from);
if ($fromDate->hour == 0) {
$fromDate = $fromDate->startOfDay();
}
// if (strtotime($fromDate) > 0) { // if (strtotime($fromDate) > 0) {
$now = new Carbon(); $now = new Carbon();
if ($fromDate->gt($now)) { if ($fromDate->gt($now)) {
@ -720,7 +730,7 @@ class RequestController extends Controller
$identify->addChild('protocolVersion', '2.0'); $identify->addChild('protocolVersion', '2.0');
$identify->addChild('adminEmail', 'repository@geologie.ac.at'); $identify->addChild('adminEmail', 'repository@geologie.ac.at');
//$identify->addChild('earliestDatestamp', '2017-04-07'); //$identify->addChild('earliestDatestamp', '2017-04-07');
$identify->addChild('earliestDatestamp', $earliestDateFromDb); $identify->addChild('earliestDatestamp', $earliestDateFromDb->toDateString());
$identify->addChild('deletedRecord', 'persistent'); $identify->addChild('deletedRecord', 'persistent');
//$description = $identify->addChild('description'); //$description = $identify->addChild('description');

1424
composer.lock generated

File diff suppressed because it is too large Load Diff