cvs: pear /Perm_LiveUser/Admin/Perm/Container DB_Complex.php MDB_Complex.php
| From: | Arnaud Limbourg | Date: | Thu, 11 Dec 2003 08:16:43 +0000 |
| Subject: | cvs: pear /Perm_LiveUser/Admin/Perm/Container DB_Complex.php MDB_Complex.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14782@lists.php.net to get a copy of this message | ||
arnaud Thu Dec 11 03:16:43 2003 EDT
Modified files:
/pear/Perm_LiveUser/Admin/Perm/Container DB_Complex.php
MDB_Complex.php
Log:
* fix for #401
Index: pear/Perm_LiveUser/Admin/Perm/Container/DB_Complex.php
diff -u pear/Perm_LiveUser/Admin/Perm/Container/DB_Complex.php:1.32
pear/Perm_LiveUser/Admin/Perm/Container/DB_Complex.php:1.33
--- pear/Perm_LiveUser/Admin/Perm/Container/DB_Complex.php:1.32 Wed Dec 10 08:03:47 2003
+++ pear/Perm_LiveUser/Admin/Perm/Container/DB_Complex.php Thu Dec 11 03:16:42 2003
@@ -45,7 +45,7 @@
* @author Christian Dickmann <dickmann@php.net>
* @author Markus Wolff <wolff@21st.de>
* @author Matt Scifo <mscifo@php.net>
- * @version $Id: DB_Complex.php,v 1.32 2003/12/10 13:03:47 arnaud Exp $
+ * @version $Id: DB_Complex.php,v 1.33 2003/12/11 08:16:42 arnaud Exp $
* @package LiveUser
*/
class LiveUser_Admin_Perm_Container_DB_Complex extends LiveUser_Admin_Perm_Container_DB_Medium
@@ -118,16 +118,27 @@
}
/**
- * assign subgroup to parent group
+ * Assign subgroup to parent group.
*
+ * First checks that the child group does not have a parent group
+ * already assigned to it. If so it returns an error object
+ *
* @access public
* @param integer id of parent group
* @param integer id of child group
- * @return mixed boolean or DB Error object
+ * @return mixed boolean, DB Error object or LiveUser Error Object
*/
function assignSubgroup($group_id, $subgroup_id)
{
- // XXX test for infinite loop
+ $query = 'SELECT subgroup_id FROM
+ ' . $this->prefix . 'group_subgroups
+ WHERE subgroup_id=' . $this->dbc->quote($subgroup_id);
+
+ if (!is_null($this->dbc->getOne($query))) {
+ return PEAR::raiseError(null, LIVEUSER_ERROR, null, E_USER_WARNING,
+ 'Child group already has a parent group', 'LiveUser', true);
+ }
+
$query = 'INSERT INTO
' . $this->prefix . 'group_subgroups
(group_id, subgroup_id)
@@ -136,6 +147,7 @@
' . (int)$group_id . ',
' . (int)$subgroup_id . '
)';
+
$result = $this->dbc->query($query);
return $result;
Index: pear/Perm_LiveUser/Admin/Perm/Container/MDB_Complex.php
diff -u pear/Perm_LiveUser/Admin/Perm/Container/MDB_Complex.php:1.21
pear/Perm_LiveUser/Admin/Perm/Container/MDB_Complex.php:1.22
--- pear/Perm_LiveUser/Admin/Perm/Container/MDB_Complex.php:1.21 Wed Dec 10 08:03:47 2003
+++ pear/Perm_LiveUser/Admin/Perm/Container/MDB_Complex.php Thu Dec 11 03:16:42 2003
@@ -45,7 +45,7 @@
* @author Christian Dickmann <dickmann@php.net>
* @author Markus Wolff <wolff@21st.de>
* @author Matt Scifo <mscifo@php.net>
- * @version $Id: MDB_Complex.php,v 1.21 2003/12/10 13:03:47 arnaud Exp $
+ * @version $Id: MDB_Complex.php,v 1.22 2003/12/11 08:16:42 arnaud Exp $
* @package LiveUser
*/
class LiveUser_Admin_Perm_Container_MDB_Complex extends LiveUser_Admin_Perm_Container_MDB_Medium
@@ -120,16 +120,27 @@
}
/**
- * assign subgroup to parent group
+ * Assign subgroup to parent group.
+ *
+ * First checks that the child group does not have a parent group
+ * already assigned to it. If so it returns an error object
*
* @access public
* @param integer id of parent group
* @param integer id of child group
- * @return mixed boolean or MDB Error object
+ * @return mixed boolean, MDB Error object or LiveUser Error Object
*/
function assignSubgroup($group_id, $subgroup_id)
{
- // XXX test for infinite loop
+ $query = 'SELECT subgroup_id FROM
+ ' . $this->prefix . 'group_subgroups
+ WHERE subgroup_id=' . $this->dbc->getValue('integer',
$subgroup_id);
+
+ if (!is_null($this->dbc->getOne($query))) {
+ return PEAR::raiseError(null, LIVEUSER_ERROR, null, E_USER_WARNING,
+ 'Child group already has a parent group', 'LiveUser', true);
+ }
+
$query = 'INSERT INTO
' . $this->prefix . 'group_subgroups
(group_id, subgroup_id)
@@ -138,6 +149,7 @@
' . $this->dbc->getValue('integer', $group_id) . ',
' . $this->dbc->getValue('integer', $subgroup_id) . '
)';
+
$result = $this->dbc->query($query);
return $result;