From: Jan Schneider Date: Mon, 3 Jan 2011 16:32:11 +0000 (+0100) Subject: Fix _getShares() in hierarchical driver, remove duplicate code. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=948cbecb22a0c37ef252139777d5b6a6b739e93a;p=horde.git Fix _getShares() in hierarchical driver, remove duplicate code. --- diff --git a/framework/Share/lib/Horde/Share/Sql.php b/framework/Share/lib/Horde/Share/Sql.php index 03ad59b65..763eec9c9 100644 --- a/framework/Share/lib/Horde/Share/Sql.php +++ b/framework/Share/lib/Horde/Share/Sql.php @@ -239,12 +239,13 @@ class Horde_Share_Sql extends Horde_Share_Base * to the given set of unique IDs, with the details retrieved * appropriately. * - * @param array $ids The array of ids to retrieve. + * @param array $ids The array of ids to retrieve. + * @param string $key The column name that should for the list keys. * * @return array The requested shares. * @throws Horde_Share_Exception */ - protected function _getShares(array $ids) + protected function _getShares(array $ids, $key = 'share_name') { $shares = array(); try { @@ -256,7 +257,7 @@ class Horde_Share_Sql extends Horde_Share_Base $sharelist = array(); foreach ($rows as $share) { $this->_loadPermissions($share); - $sharelist[$share['share_name']] = $this->_createObject($share); + $sharelist[$share[$key]] = $this->_createObject($share); } return $sharelist; diff --git a/framework/Share/lib/Horde/Share/Sql/Hierarchical.php b/framework/Share/lib/Horde/Share/Sql/Hierarchical.php index adb798ca7..849f0db1e 100644 --- a/framework/Share/lib/Horde/Share/Sql/Hierarchical.php +++ b/framework/Share/lib/Horde/Share/Sql/Hierarchical.php @@ -442,66 +442,14 @@ class Horde_Share_Sql_Hierarchical extends Horde_Share_Sql * to the given set of unique IDs, with the details retrieved * appropriately. * - * @param array $cids The array of ids to retrieve. + * @param array $ids The array of ids to retrieve. * - * @return array The requested shares keyed by share_id. + * @return array The requested shares keyed be share_id. * @throws Horde_Share_Exception */ protected function _getShares(array $ids) { - $shares = array(); - $query = 'SELECT * FROM ' . $this->_table . ' WHERE share_id IN (' . str_repeat('?,', count($ids) - 1) . '?)'; - try { - $rows = $this->_db->selectAll($query, $ids); - } catch (Horde_Db_Exception $e) { - throw new Horde_Share_Exception($e->getMessage()); - } - - $groups = array(); - $users = array(); - foreach ($rows as $share) { - $shares[(int)$share['share_id']] = $this->_fromDriverCharset($share); - if ($this->_hasUsers($share)) { - $users[] = (int)$share['share_id']; - } - if ($this->_hasGroups($share)) { - $groups[] = (int)$share['share_id']; - } - } - - // Get users permissions - if (!empty($users)) { - $query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users WHERE share_id IN (' . str_repeat('?,', count($users) - 1) . '?)'; - try { - $rows = $this->_db->selectAll($query, $users); - } catch (Horde_Db_Exception $e) { - throw new Horde_Share_Exception($e->getMessage()); - } - foreach ($rows as $share) { - $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm']; - } - } - - // Get groups permissions - if (!empty($groups)) { - $query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups' - . ' WHERE share_id IN (' . str_repeat('?,', count($groups) - 1) . '?)'; - try { - $rows = $this->_db->selectAll($query, $groups); - } catch (Horde_Db_Exception $e) { - throw new Horde_Share_Exception($e->getMessage()); - } - foreach ($rows as $share) { - $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm']; - } - } - - $sharelist = array(); - foreach ($shares as $id => $data) { - $sharelist[$id] = $this->_createObject($data); - } - - return $sharelist; + return parent::_getShares($ids, 'share_id'); } /**