Refactor query generation in UserSearchForm::search()
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Mar 2021 11:22:12 +0000 (12:22 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Mar 2021 11:22:12 +0000 (12:22 +0100)
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

wcfsetup/install/files/lib/form/UserSearchForm.class.php

index a1cf6043556d8a4521bf1cfa0e9b8307315062ba..68e5795f160f0d1d17eebc86a26a5747d2ed172c 100644 (file)
@@ -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);
     }