[Fusionforge-commits] r8703 - trunk/gforge/common/docman

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Sun Jan 31 18:24:19 CET 2010


Author: aljeux
Date: 2010-01-31 18:24:19 +0100 (Sun, 31 Jan 2010)
New Revision: 8703

Modified:
   trunk/gforge/common/docman/DocumentGroup.class.php
Log:
docman: Add control to avoid creating an already existing name (same for renaming)

Modified: trunk/gforge/common/docman/DocumentGroup.class.php
===================================================================
--- trunk/gforge/common/docman/DocumentGroup.class.php	2010-01-31 17:24:10 UTC (rev 8702)
+++ trunk/gforge/common/docman/DocumentGroup.class.php	2010-01-31 17:24:19 UTC (rev 8703)
@@ -117,6 +117,15 @@
 			return false;
 		}
 		
+		$res=db_query_params('SELECT * FROM doc_groups WHERE groupname=$1 AND parent_doc_group=$2 AND group_id=$3',
+				array($name,
+					$parent_doc_group,
+					$this->Group->getID()));
+		if ($res && db_numrows($res) > 0) {
+			$this->setError(_('Group name is already exists'));
+			return false;
+		}
+
 		$result = db_query_params ('INSERT INTO doc_groups (group_id,groupname,parent_doc_group) VALUES ($1, $2, $3)',
 					   array ($this->Group->getID(),
 						  htmlspecialchars($name),
@@ -138,7 +147,46 @@
 		return true;
 	}
 
+	/**
+	 * delete - delete a DocumentGroup.
+	 *          delete is recursive and permanent
+	 *       TODO : use the delete status as document ?
+	 * @param integer Document Group Id, integer Project Group Id
+	 * @return boolean
+	 */
+	function delete($doc_groupid,$project_group_id) {
+		$perm =& $this->Group->getPermission (session_get_user());
+		if (!$perm || !$perm->isDocEditor()) {
+			$this->setPermissionDeniedError();
+			return false;
+		}
+		db_begin();
+		/* delete documents in directory */
+		$result = db_query_params ('DELETE FROM doc_data where doc_group = $1 and group_id = $2',
+					array($doc_groupid,
+						$project_group_id));
 
+		/* delete directory */
+		$result = db_query_params ('DELETE FROM doc_groups where doc_group = $1 and group_id = $2',
+					array($doc_groupid,
+						$project_group_id));
+
+		db_commit();
+		/* is there any subdir ? */
+		$result = db_query_params ('select doc_group from doc_groups where parent_doc_group = $1 and group_id = $2',
+					array($doc_groupid,
+						$project_group_id));
+		/* make a recursive call */
+		while ($arr = db_fetch_array($result)) {
+			$this->delete($arr,$project_group_id);
+		}
+
+		if (!$result) {
+			return false;
+		}
+		return true;
+	}
+
 	/**
 	 *	fetchData - re-fetch the data for this DocumentGroup from the database.
 	 *
@@ -223,6 +271,15 @@
 			$parent_doc_group=0;
 		}
 
+		$res=db_query_params ('SELECT * FROM doc_groups WHERE groupname=$1 AND parent_doc_group=$2 AND group_id=$3',
+				array($name,
+						$parent_doc_group,
+						$this->Group->getID()));
+		if ($res && db_numrows($res) > 0) {
+			$this->setError(_("Group name already exists"));
+			return false;
+		}
+
 		$result = db_query_params ('UPDATE doc_groups SET groupname=$1, parent_doc_group=$2 WHERE doc_group=$3 AND group_id=$4',
 					   array(htmlspecialchars($name),
 						 $parent_doc_group,
@@ -237,46 +294,6 @@
 	}
 		
 	/**
-	 * delete - delete a DocumentGroup.
-	 *          delete is recursive and permanent
-	 *       TODO : use the delete status as document ?
-	 * @param integer Document Group Id, integer Project Group Id
-	 * @return boolean
- 	 */
-	function delete($doc_groupid,$project_group_id) {
-		$perm =& $this->Group->getPermission (session_get_user());
-		if (!$perm || !$perm->isDocEditor()) {
-			$this->setPermissionDeniedError();
-			return false;
-		}
-		db_begin();
-		/* delete documents in directory */
-		$result = db_query_params ('DELETE FROM doc_data where doc_group = $1 and group_id = $2',
-					array($doc_groupid,
-						$project_group_id));
-
-		/* delete directory */
-		$result = db_query_params ('DELETE FROM doc_groups where doc_group = $1 and group_id = $2',
-					array($doc_groupid,
-						$project_group_id));
-
-		db_commit();
-		/* is there any subdir ? */
-		$result = db_query_params ('select doc_group from doc_groups where parent_doc_group = $1 and group_id = $2',
-					array($doc_groupid,
-						$project_group_id));
-		/* make a recursive call */
-		while ($arr = db_fetch_array($result)) {
-			$this->delete($arr,$project_group_id);
-		}
-
-		if (!$result) {
-			return false;
-		}
-		return true;
-	}
-
-	/**
 	* hasDocuments - Recursive function that checks if this group or any of it childs has documents associated to it
 	*
 	* A group has associated documents if and only if there are documents associated to this




More information about the Fusionforge-commits mailing list