From: Tim Düsterhus Date: Mon, 15 Mar 2021 11:22:12 +0000 (+0100) Subject: Refactor query generation in UserSearchForm::search() X-Git-Tag: 5.4.0_Alpha_1~158 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d707135491aa8d94ca8acba02b67908f3643eb7e;p=GitHub%2FWoltLab%2FWCF.git Refactor query generation in UserSearchForm::search() The `$sql` can easily be moved down, as it is only used in a single place. This allows us to directly embed the condition. see dec19b25cdf21b81d73c5897cd3c885d5ec62ef4 see #4078 --- diff --git a/wcfsetup/install/files/lib/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/form/UserSearchForm.class.php index a1cf604355..68e5795f16 100644 --- a/wcfsetup/install/files/lib/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/form/UserSearchForm.class.php @@ -171,10 +171,6 @@ class UserSearchForm extends UserOptionListForm protected function search() { $this->matches = []; - $sql = "SELECT user_table.userID - FROM wcf" . WCF_N . "_user user_table - LEFT JOIN wcf" . WCF_N . "_user_option_value option_value - ON option_value.userID = user_table.userID"; // build search condition $this->conditions = new PreparedStatementConditionBuilder(); @@ -190,8 +186,13 @@ class UserSearchForm extends UserOptionListForm return; } - // do search - $statement = WCF::getDB()->prepareStatement($sql . "\n". $this->conditions, $this->maxResults); + // perform search + $sql = "SELECT user_table.userID + FROM wcf" . WCF_N . "_user user_table + LEFT JOIN wcf" . WCF_N . "_user_option_value option_value + ON option_value.userID = user_table.userID + {$this->conditions}"; + $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute($this->conditions->getParameters()); $this->matches = $statement->fetchAll(\PDO::FETCH_COLUMN); }