From: Alexander Ebert Date: Wed, 15 Aug 2012 23:01:03 +0000 (+0200) Subject: Enhanced ACP search X-Git-Tag: 2.0.0_Beta_1~959^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cfb057c906b769e116c9bfdf4c7ef824962d8d32;p=GitHub%2FWoltLab%2FWCF.git Enhanced ACP search --- diff --git a/wcfsetup/install/files/lib/system/cache/builder/ACPSearchProviderCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ACPSearchProviderCacheBuilder.class.php index a2d180245f..7c7802b5dc 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ACPSearchProviderCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ACPSearchProviderCacheBuilder.class.php @@ -18,8 +18,6 @@ class ACPSearchProviderCacheBuilder implements ICacheBuilder { * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { - list($cache, $packageID) = explode('-', $cacheResource['cache']); - $providerList = new ACPSearchProviderList(); $providerList->getConditionBuilder()->add("acp_search_provider.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $providerList->sqlLimit = 0; diff --git a/wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php index abafea3f14..5f5019befd 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php @@ -37,12 +37,15 @@ class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInsta WHERE providerName = ? AND packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); foreach ($items as $item) { $statement->execute(array( $item['attributes']['name'], $this->installation->getPackageID() )); } + WCF::getDB()->commitTransaction(); } /** diff --git a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php index 3d2b1f9c8d..9272e55305 100644 --- a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php @@ -26,7 +26,8 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider { // search by language item $conditions = new PreparedStatementConditionBuilder(); $conditions->add("languageID = ?", array(WCF::getLanguage()->languageID)); - $conditions->add("languageItem LIKE ?", array('wcf.acp.option.'.$query.'%')); + $conditions->add("languageItem LIKE ?", array('wcf.acp.option.%')); + $conditions->add("languageItemValue LIKE ?", array($query.'%')); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); // get available abbrevations @@ -51,7 +52,7 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider { FROM wcf".WCF_N."_language_item ".$conditions." ORDER BY languageItemValue ASC"; - $statement = WCF::getDB()->prepareStatement($sql, ($limit * 2)); // use double limit here since categories are matched too + $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); $languageItems = array(); while ($row = $statement->fetchArray()) { @@ -66,16 +67,62 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider { $conditions->add("menuItem IN (?)", array(array_keys($languageItems))); $conditions->add("menuItemLink <> ''"); - $sql = "SELECT menuItem, menuItemLink + $sql = "SELECT menuItem, menuItemLink, permissions, options FROM wcf".WCF_N."_acp_menu_item ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql, $limit); + $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); + $count = 0; while ($row = $statement->fetchArray()) { - $results[] = new ACPSearchResult($languageItems[$row['menuItem']], $row['menuItemLink']); + if ($count == $limit) { + break; + } + + if ($this->checkMenuItem($row)) { + $results[] = new ACPSearchResult($languageItems[$row['menuItem']], $row['menuItemLink']); + $count++; + } } return $results; } + + /** + * Validates options and permissions for a given menu item. + * + * @param array $row + * @return boolean + */ + protected function checkMenuItem(array $row) { + // check the options of this item + $hasEnabledOption = true; + if (!empty($row['options'])) { + $hasEnabledOption = false; + $options = explode(',', strtoupper($row['options'])); + foreach ($options as $option) { + if (defined($option) && constant($option)) { + $hasEnabledOption = true; + break; + } + } + } + if (!$hasEnabledOption) return false; + + // check the permission of this item for the active user + $hasPermission = true; + if (!empty($row['permissions'])) { + $hasPermission = false; + $permissions = explode(',', $row['permissions']); + foreach ($permissions as $permission) { + if (WCF::getSession()->getPermission($permission)) { + $hasPermission = true; + break; + } + } + } + if (!$hasPermission) return false; + + return true; + } }