Skip to content

Commit 0b5d94d

Browse files
Fixup and test PR. Working as expected.
1 parent 21f6046 commit 0b5d94d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/support/Database.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ public function getResourceUpdates($resource_id, $page, $sorting = null) {
137137
$page = $page == 1 ? 0 : 10 * ($page - 1);
138138

139139
// Default sorting option for this method.
140-
if($sorting == null) $sorting = 'asc';
140+
if (is_null($sorting)) $sorting = 'asc';
141141

142142
if (!is_null($this->conn)) {
143-
$updatesStmt = $this->conn->prepare($this->_resource_update('AND r.resource_id = :resource_id ORDER BY id :order LIMIT 10 OFFSET :offset'));
143+
// PDO tries to quote the sorting method. Can't bind it normally. Should be OK, sorting is enforced to be 'asc' or 'desc'.
144+
$querySuffix = sprintf("AND r.resource_id = :resource_id ORDER BY r.resource_update_id %s LIMIT 10 OFFSET :offset", $sorting);
145+
146+
$updatesStmt = $this->conn->prepare($this->_resource_update($querySuffix));
144147
$updatesStmt->bindParam(':resource_id', $resource_id);
145148
$updatesStmt->bindParam(':offset', $page, \PDO::PARAM_INT);
146-
$updatesStmt->bindParam(':order', $sorting, \PDO::PARAM_STR);
147149

148150
if ($updatesStmt->execute()) {
149151
return $updatesStmt->fetchAll();

src/util/RequestUtil.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ public static function sorting() {
7878
$value = $_GET['sort'] ?? null;
7979

8080
// Preconditions
81-
if($value == null || !is_string($value)) return;
81+
if (is_null($value) || !is_string($value)) return;
8282

8383
// Sorting methods
84-
if(strcasecmp($value, 'asc')) return 'asc';
85-
if(strcasecmp($value, 'desc')) return 'desc';
84+
if(strcasecmp($value, 'asc') == 0) {
85+
return 'asc';
86+
} else if (strcasecmp($value, 'desc') == 0) {
87+
return 'desc';
88+
}
8689

8790
// Return default null. This allows different defaults per method.
8891
return NULL;

0 commit comments

Comments
 (0)