From 0fd0f0253716eede5949d5a01d3c43b121d9134e Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Thu, 5 Mar 2020 16:03:34 +0100 Subject: [PATCH] - bug: error if dataset table is empty --- app/Http/Controllers/Oai/RequestController.php | 2 +- app/Models/Dataset.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Oai/RequestController.php b/app/Http/Controllers/Oai/RequestController.php index e5b77aa..0162bec 100644 --- a/app/Http/Controllers/Oai/RequestController.php +++ b/app/Http/Controllers/Oai/RequestController.php @@ -149,7 +149,7 @@ class RequestController extends Controller $repositoryName = "Tethys RDR"; $repIdentifier = "tethys.geologie.ac.at"; $sampleIdentifier = "oai:" . $repIdentifier . ":27";//$this->_configuration->getSampleIdentifier(); - $earliestDateFromDb = optional(Dataset::earliestPublicationDate())->server_date_published; + $earliestDateFromDb = Dataset::earliestPublicationDate() != null ? Dataset::earliestPublicationDate()->server_date_published: null; // set parameters for oai-pmh.xslt $this->_proc->setParameter('', 'email', $email); diff --git a/app/Models/Dataset.php b/app/Models/Dataset.php index 3d741c5..238b1b8 100644 --- a/app/Models/Dataset.php +++ b/app/Models/Dataset.php @@ -258,17 +258,18 @@ class Dataset extends Model * * @return \Carbon\Carbon\Date */ - public function scopeEarliestPublicationDate($query, string $column = null) + public static function earliestPublicationDate(string $column = null) { if (!$column) { $column = self::PUBLISHED_AT; } - return $query->select('server_date_published') + $result = Dataset::select('server_date_published') ->where('server_date_published', '<>', null) ->where('server_state', 'published') ->orderBy('server_date_published', 'asc') ->first(); //->server_date_published; + return $result; } public function setServerState($targetType)