Skip to content

Commit ee062b0

Browse files
committed
Fix OAI-PMH resumptionToken dates, refs #13574
This also fixes issue #13025 by correctly converting OAI-PMH UTC "from" and "until" dates to local MySQL dates for ORM queries. - Use ISO 8601 UTC format to represent from & until dates internally and in OAI-PMH output (e.g. "2021-10-08T21:53:17Z") - Pass datetimes to MySQL in MySQL date format using local app time (e.g. "2021-10-08 14:53:17" for default_timezone="America/Vancouver")
1 parent 2b1dc75 commit ee062b0

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

lib/oai/QubitOai.class.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static function isValidOaiKey($key)
147147
}
148148

149149
/**
150-
* Returns formated date.
150+
* Returns ISO 8601 formatted UTC date.
151151
*
152152
* @param string $date optional date value
153153
*
@@ -162,6 +162,22 @@ public static function getDate($date = '')
162162
return gmdate('Y-m-d\TH:i:s\Z', strtotime($date));
163163
}
164164

165+
/**
166+
* Returns a MySQL formatted date using local AtoM timezone.
167+
*
168+
* @param string $date in ISO 8601 UTC format
169+
*
170+
* @return null|string a MySQL formatted local datetime, or null
171+
*/
172+
public static function mysqlDate($date)
173+
{
174+
if (empty($date)) {
175+
return;
176+
}
177+
178+
return date('Y-m-d H:i:s', strtotime($date));
179+
}
180+
165181
/**
166182
* Returns MetadataPrefixes.
167183
*

plugins/arOaiPlugin/lib/arOaiPluginComponent.class.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function setUpdateParametersFromRequest($request)
5050
if (!isset($request->from)) {
5151
$this->from = '';
5252
} else {
53-
$this->from = strtotime($request->from);
53+
$this->from = $request->from;
5454
}
5555

5656
if (!isset($request->until)) {
5757
$this->until = '';
5858
} else {
59-
$this->until = strtotime($request->until);
59+
$this->until = $request->until;
6060
}
6161

6262
if (!isset($request->set)) {
@@ -87,8 +87,8 @@ public function setUpdateParametersFromRequest($request)
8787
public function getUpdates(array $options = [])
8888
{
8989
$presetOptions = [
90-
'from' => $this->from,
91-
'until' => $this->until,
90+
'from' => QubitOai::mysqlDate($this->from),
91+
'until' => QubitOai::mysqlDate($this->until),
9292
'offset' => $this->cursor,
9393
'limit' => QubitSetting::getByName('resumption_token_limit')->__toString(),
9494
];
@@ -106,13 +106,18 @@ public function getUpdates(array $options = [])
106106
$this->publishedRecords = $update['data'];
107107
$this->remaining = $update['remaining'];
108108
$this->recordsCount = count($this->publishedRecords);
109-
$resumptionCursor = $this->cursor + $options['limit'];
110-
$this->resumptionToken = base64_encode(json_encode(['from' => $this->from,
111-
'until' => $this->until,
112-
'cursor' => $resumptionCursor,
113-
'metadataPrefix' => $this->metadataPrefix,
114-
'set' => $this->set,
115-
]));
109+
110+
$this->resumptionToken = base64_encode(
111+
json_encode(
112+
[
113+
'from' => $this->from,
114+
'until' => $this->until,
115+
'cursor' => $this->cursor + $options['limit'],
116+
'metadataPrefix' => $this->metadataPrefix,
117+
'set' => $this->set,
118+
]
119+
)
120+
);
116121
}
117122

118123
public function setRequestAttributes($request)

0 commit comments

Comments
 (0)