From: Matthias Schmidt Date: Sun, 5 Jul 2015 09:39:36 +0000 (+0200) Subject: Use condition system for user search X-Git-Tag: 3.0.0_Beta_1~2219^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a5f8fd9f508fef86c0240f0c5731ad1805cc6be4;p=GitHub%2FWoltLab%2FWCF.git Use condition system for user search --- diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd8274080..88d2f19873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,3 +26,4 @@ * Abstract bulk processing system added. * Replaced old user bulk processing with new implementation using the abstract bulk processing system. * `conditionContainers` template event in template `noticeAdd.tpl` added. +* Use condition system for user search. diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index cc1534a73c..dc9c8000aa 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1122,5 +1122,78 @@ userOptions + + + + com.woltlab.wcf.username + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.email + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.userGroup + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.languages + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.registrationDate + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.registrationDateInterval + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.avatar + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.state + com.woltlab.wcf.condition.userSearch + + general + + + com.woltlab.wcf.activityPoints + com.woltlab.wcf.condition.userSearch + + contents + activityPoints + 0 + + + com.woltlab.wcf.likesReceived + com.woltlab.wcf.condition.userSearch + + contents + likesReceived + 0 + + + com.woltlab.wcf.userOptions + com.woltlab.wcf.condition.userSearch + + userOptions + + diff --git a/com.woltlab.wcf/objectTypeDefinition.xml b/com.woltlab.wcf/objectTypeDefinition.xml index c2e7b7ee10..bbb27a7e1f 100644 --- a/com.woltlab.wcf/objectTypeDefinition.xml +++ b/com.woltlab.wcf/objectTypeDefinition.xml @@ -164,6 +164,11 @@ + + com.woltlab.wcf.condition.userSearch + + + com.woltlab.wcf.adLocation diff --git a/wcfsetup/install/files/acp/templates/userSearch.tpl b/wcfsetup/install/files/acp/templates/userSearch.tpl index b18b97d1e4..7ef384fc1c 100644 --- a/wcfsetup/install/files/acp/templates/userSearch.tpl +++ b/wcfsetup/install/files/acp/templates/userSearch.tpl @@ -41,201 +41,87 @@
-
- - -
diff --git a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php index ab5bcdb4c9..57c0770ec6 100755 --- a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php @@ -1,21 +1,20 @@ * @package com.woltlab.wcf @@ -34,100 +33,16 @@ class UserSearchForm extends UserOptionListForm { public $neededPermissions = array('admin.user.canSearchUser'); /** - * username - * @var string - */ - public $username = ''; - - /** - * email address - * @var string - */ - public $email = ''; - - /** - * user id - * @var integer - */ - public $userID = null; - - /** - * group ids - * @var array - */ - public $groupIDs = array(); - - /** - * true to invert the given group ids - * @var boolean - */ - public $invertGroupIDs = 0; - - /** - * language ids - * @var array - */ - public $languageIDs = array(); - - /** - * registration start date - * @var string - */ - public $registrationDateStart = ''; - - /** - * registration start date - * @var string - */ - public $registrationDateEnd = ''; - - /** - * banned state - * @var boolean + * list of grouped user group assignment condition object types + * @var array */ - public $banned = 0; + public $conditions = array(); /** - * not banned state - * @var boolean + * list with searched users + * @var \wcf\data\user\UserList */ - public $notBanned = 0; - - /** - * last activity start time - * @var string - */ - public $lastActivityTimeStart = ''; - - /** - * last activity end time - * @var string - */ - public $lastActivityTimeEnd = ''; - - /** - * enabled state - * @var boolean - */ - public $enabled = 0; - - /** - * disabled state - * @var boolean - */ - public $disabled = 0; - - /** - * matches - * @var array - */ - public $matches = array(); - - /** - * condtion builder object - * @var \wcf\system\database\condition\PreparedStatementConditionBuilder - */ - public $conditions = null; + public $userList = null; /** * search id @@ -196,20 +111,11 @@ class UserSearchForm extends UserOptionListForm { public function readFormParameters() { parent::readFormParameters(); - if (isset($_POST['username'])) $this->username = StringUtil::trim($_POST['username']); - if (isset($_POST['email'])) $this->email = StringUtil::trim($_POST['email']); - if (!empty($_POST['userID'])) $this->userID = intval($_POST['userID']); - if (isset($_POST['groupIDs']) && is_array($_POST['groupIDs'])) $this->groupIDs = ArrayUtil::toIntegerArray($_POST['groupIDs']); - if (isset($_POST['languageIDs']) && is_array($_POST['languageIDs'])) $this->languageIDs = ArrayUtil::toIntegerArray($_POST['languageIDs']); - if (isset($_POST['invertGroupIDs'])) $this->invertGroupIDs = intval($_POST['invertGroupIDs']); - if (isset($_POST['registrationDateStart'])) $this->registrationDateStart = $_POST['registrationDateStart']; - if (isset($_POST['registrationDateEnd'])) $this->registrationDateEnd = $_POST['registrationDateEnd']; - if (isset($_POST['banned'])) $this->banned = intval($_POST['banned']); - if (isset($_POST['notBanned'])) $this->notBanned = intval($_POST['notBanned']); - if (isset($_POST['lastActivityTimeStart'])) $this->lastActivityTimeStart = $_POST['lastActivityTimeStart']; - if (isset($_POST['lastActivityTimeEnd'])) $this->lastActivityTimeEnd = $_POST['lastActivityTimeEnd']; - if (isset($_POST['enabled'])) $this->enabled = intval($_POST['enabled']); - if (isset($_POST['disabled'])) $this->disabled = intval($_POST['disabled']); + foreach ($this->conditions as $conditions) { + foreach ($conditions as $condition) { + $condition->getProcessor()->readFormParameters(); + } + } if (isset($_POST['itemsPerPage'])) $this->itemsPerPage = intval($_POST['itemsPerPage']); if (isset($_POST['sortField'])) $this->sortField = $_POST['sortField']; @@ -217,33 +123,27 @@ class UserSearchForm extends UserOptionListForm { if (isset($_POST['columns']) && is_array($_POST['columns'])) $this->columns = $_POST['columns']; } - /** - * @see \wcf\acp\form\AbstractOptionListForm::initOptionHandler() - */ - protected function initOptionHandler() { - $this->optionHandler->enableSearchMode(); - $this->optionHandler->init(); - } - /** * @see \wcf\page\IPage::readData() */ public function readData() { + $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.condition.userSearch'); + foreach ($objectTypes as $objectType) { + if (!$objectType->conditiongroup) continue; + + if (!isset($this->conditions[$objectType->conditiongroup])) { + $this->conditions[$objectType->conditiongroup] = [ ]; + } + + $this->conditions[$objectType->conditiongroup][$objectType->objectTypeID] = $objectType; + } + parent::readData(); // add email column for authorized users if (WCF::getSession()->getPermission('admin.user.canEditMailAddress')) { array_unshift($this->columns, 'email'); } - - $this->readOptionTree(); - } - - /** - * Reads option tree on page init. - */ - protected function readOptionTree() { - $this->optionTree = $this->optionHandler->getOptionTree(); } /** @@ -253,27 +153,11 @@ class UserSearchForm extends UserOptionListForm { parent::assignVariables(); WCF::getTPL()->assign(array( - 'username' => $this->username, - 'email' => $this->email, - 'userID' => $this->userID, - 'groupIDs' => $this->groupIDs, - 'languageIDs' => $this->languageIDs, - 'optionTree' => $this->optionTree, - 'availableGroups' => $this->getAvailableGroups(), - 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), - 'invertGroupIDs' => $this->invertGroupIDs, - 'registrationDateStart' => $this->registrationDateStart, - 'registrationDateEnd' => $this->registrationDateEnd, - 'banned' => $this->banned, - 'notBanned' => $this->notBanned, + 'groupedObjectTypes' => $this->conditions, 'sortField' => $this->sortField, 'sortOrder' => $this->sortOrder, 'itemsPerPage' => $this->itemsPerPage, 'columns' => $this->columns, - 'lastActivityTimeStart' => $this->lastActivityTimeStart, - 'lastActivityTimeEnd' => $this->lastActivityTimeEnd, - 'enabled' => $this->enabled, - 'disabled' => $this->disabled, 'columnOptions' => $this->optionHandler->getCategoryOptions('profile') )); } @@ -285,11 +169,11 @@ class UserSearchForm extends UserOptionListForm { parent::save(); // store search result in database - $data = serialize(array( - 'matches' => $this->matches, + $data = serialize([ + 'matches' => $this->userList->getObjectIDs(), 'itemsPerPage' => $this->itemsPerPage, 'columns' => $this->columns - )); + ]); $search = SearchEditor::create(array( 'userID' => WCF::getUser()->userID, @@ -303,8 +187,9 @@ class UserSearchForm extends UserOptionListForm { $this->saved(); // forward to result page - $url = LinkHandler::getInstance()->getLink('UserList', array('id' => $this->searchID), 'sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder)); - HeaderUtil::redirect($url); + HeaderUtil::redirect(LinkHandler::getInstance()->getLink('UserList', [ + 'id' => $this->searchID + ], 'sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder))); exit; } @@ -314,15 +199,20 @@ class UserSearchForm extends UserOptionListForm { public function validate() { AbstractForm::validate(); - // remove email column for not authorized users + // remove email column for non-authorized users if (!WCF::getSession()->getPermission('admin.user.canEditMailAddress') && ($key = array_search('email', $this->columns)) !== false) { - unset($this->columns[$key]); + unset($this->columns[$key]); + } + + foreach ($this->conditions as $conditions) { + foreach ($conditions as $condition) { + $condition->getProcessor()->validate(); + } } - // do search $this->search(); - if (empty($this->matches)) { + if (!count($this->userList->getObjectIDs())) { throw new UserInputException('search', 'noMatches'); } } @@ -331,92 +221,19 @@ class UserSearchForm extends UserOptionListForm { * Search for users which fit to the search values. */ protected function search() { - $this->matches = array(); - $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(); - - // static fields - $this->buildStaticConditions(); - - // dynamic fields - $this->buildDynamicConditions(); - - // call buildConditions event - EventHandler::getInstance()->fireAction($this, 'buildConditions'); - - // do search - $statement = WCF::getDB()->prepareStatement($sql.$this->conditions, $this->maxResults); - $statement->execute($this->conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } - } - - /** - * Builds the static conditions. - */ - protected function buildStaticConditions() { - if (!empty($this->username)) { - $this->conditions->add("user_table.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%')); - } - if (!empty($this->userID)) { - $this->conditions->add("user_table.userID = ?", array($this->userID)); - } - if (!empty($this->email)) { - $this->conditions->add("user_table.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%')); - } - if (!empty($this->groupIDs)) { - $this->conditions->add("user_table.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDs)); - } - if (!empty($this->languageIDs)) { - $this->conditions->add("user_table.languageID IN (?)", array($this->languageIDs)); - } + $this->userList = new UserList(); - // registration date - if ($startDate = @strtotime($this->registrationDateStart)) { - $this->conditions->add('user_table.registrationDate >= ?', array($startDate)); - } - if ($endDate = @strtotime($this->registrationDateEnd)) { - $this->conditions->add('user_table.registrationDate <= ?', array($endDate)); - } + EventHandler::getInstance()->fireAction($this, 'search'); - if ($this->banned) { - $this->conditions->add('user_table.banned = ?', array(1)); - } - if ($this->notBanned) { - $this->conditions->add('user_table.banned = ?', array(0)); - } - - // last activity time - if ($startDate = @strtotime($this->lastActivityTimeStart)) { - $this->conditions->add('user_table.lastActivityTime >= ?', array($startDate)); - } - if ($endDate = @strtotime($this->lastActivityTimeEnd)) { - $this->conditions->add('user_table.lastActivityTime <= ?', array($endDate)); - } - - if ($this->enabled) { - $this->conditions->add('user_table.activationCode = ?', array(0)); - } - if ($this->disabled) { - $this->conditions->add('user_table.activationCode <> ?', array(0)); - } - } - - /** - * Builds the dynamic conditions. - */ - protected function buildDynamicConditions() { - foreach ($this->optionHandler->getCategoryOptions('profile') as $option) { - $option = $option['object']; - - $value = isset($this->optionHandler->optionValues[$option->optionName]) ? $this->optionHandler->optionValues[$option->optionName] : null; - $this->optionHandler->getTypeObject($option->optionType)->getCondition($this->conditions, $option, $value); + // read user ids + foreach ($this->conditions as $groupedObjectTypes) { + foreach ($groupedObjectTypes as $objectType) { + $data = $objectType->getProcessor()->getData(); + if ($data !== null) { + $objectType->getProcessor()->addObjectListCondition($this->userList, $data); + } + } } + $this->userList->readObjectIDs(); } } diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index d8e4b05efe..136470b076 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -8,7 +8,7 @@ use wcf\system\WCF; /** * Manages the background queue. - * + * * @author Tim Duesterhus * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License @@ -33,7 +33,7 @@ class BackgroundQueueHandler extends SingletonFactory { * Enqueues the given job(s) for execution at the given time. * Note: The time is a minimum time. Depending on the size of * the queue the job can be performed later as well! - * + * * @param mixed $jobs Either an instance of \wcf\system\background\job\AbstractBackgroundJob or an array of these * @param int $time Earliest time to consider the job for execution. */ @@ -141,7 +141,7 @@ class BackgroundQueueHandler extends SingletonFactory { finally { if (!$commited) WCF::getDB()->rollbackTransaction(); } - + $job = null; try { // no shut up operator, exception will be caught @@ -162,4 +162,4 @@ class BackgroundQueueHandler extends SingletonFactory { $statement->execute([ $row['jobID'] ]); } } -} +} \ No newline at end of file