From e1a47e302975825618b4b1c84700e5c6735f376e Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Fri, 23 Jun 2023 15:30:09 +0000 Subject: [PATCH] minor edits for #153 --- controllers/ApiController.php | 2 +- model/Items.inc.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 4e343bf0..ef039c53 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -482,7 +482,7 @@ public function init($extra) { // Sorting by Item Type or Added By currently require writing to shard tables, so don't // send those to the read replicas - if ($this->queryParams['sort'] == 'itemType' || $this->queryParams['sort'] == 'addedBy' || $this->queryParams['sort'] == 'editedBy') { + if (in_array($this->queryParams['sort'], ['itemType', 'addedBy', 'editedBy'])) { Zotero_DB::readOnly(false); } diff --git a/model/Items.inc.php b/model/Items.inc.php index ad5d8fc0..bc95b19b 100644 --- a/model/Items.inc.php +++ b/model/Items.inc.php @@ -275,10 +275,10 @@ public static function search($libraryID, $onlyTopLevel = false, array $params = $sql .= "JOIN tmpItemTypeNames TITN ON (TITN.itemTypeID=$itemTypeIDSelector) "; break; - case 'editedBy': case 'addedBy': + case 'editedBy': $isGroup = Zotero_Libraries::getType($libraryID) == 'group'; - $userParameter = $params['sort'] == "editedBy" ? 'lastModifiedByUserID' : 'createdByUserID'; + $userParameter = $params['sort'] == "addedBy" ? 'createdByUserID' : 'lastModifiedByUserID'; if ($isGroup) { $sql2 = "SELECT DISTINCT $userParameter FROM items JOIN groupItems USING (itemID) WHERE @@ -551,9 +551,9 @@ public static function search($libraryID, $onlyTopLevel = false, array $params = case 'date': $orderSQL = "$sortTable.value"; break; - - case 'editedBy': + case 'addedBy': + case 'editedBy': if ($isGroup && $createdByUserIDs) { $orderSQL = "TCBU.username"; }