[Fusionforge-commits] FusionForge branch master updated. c307e207f152ec897d772ff99b2f932b2129f943

Franck Villaume nerville at fusionforge.org
Thu Apr 10 15:36:02 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  c307e207f152ec897d772ff99b2f932b2129f943 (commit)
      from  ab498c6c5f0cb1cece9f3c2161c2bee2d4f421c4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c307e207f152ec897d772ff99b2f932b2129f943
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Thu Apr 10 15:35:21 2014 +0200

    docman: cleanup and factorize the doc_group state id management

diff --git a/src/common/docman/Document.class.php b/src/common/docman/Document.class.php
index 2034cdb..dcc89c5 100644
--- a/src/common/docman/Document.class.php
+++ b/src/common/docman/Document.class.php
@@ -997,14 +997,17 @@ class Document extends Error {
 	 * @return	boolean	success or not.
 	 */
 	function trash() {
-		$this->setState('2');
-		$dm = new DocumentManager($this->Group);
-		$this->setDocGroupID($dm->getTrashID());
-		$this->setLock(0);
-		$this->setReservedBy(0);
-		$this->sendNotice(false);
-		$this->clearMonitor();
-		return true;
+		if (!$this->getLocked() || ((time() - $this->getLockdate()) > 600)) {
+			$this->setState('2');
+			$dm = new DocumentManager($this->Group);
+			$this->setDocGroupID($dm->getTrashID());
+			$this->setLock(0);
+			$this->setReservedBy(0);
+			$this->sendNotice(false);
+			$this->clearMonitor();
+			return true;
+		}
+		return false;
 	}
 
 
diff --git a/src/common/docman/DocumentGroup.class.php b/src/common/docman/DocumentGroup.class.php
index 4cd1999..97aed1c 100644
--- a/src/common/docman/DocumentGroup.class.php
+++ b/src/common/docman/DocumentGroup.class.php
@@ -682,10 +682,69 @@ class DocumentGroup extends Error {
 	 * setStateID - set the state id of this document group.
 	 *
 	 * @param	int	$stateid	State ID.
+	 * @param	bool	$recursive	set the state id recursively. (i.e. move the directory and his content to trash)
 	 * @return	boolean	success or not.
 	 * @access	public
 	 */
-	function setStateID($stateid) {
+	function setStateID($stateid, $recursive = false) {
+		if ($recursive) {
+			$df = new DocumentFactory($this->Group);
+			if ($df->isError())
+				exit_error($df->getErrorMessage(), 'docman');
+
+			$dgf = new DocumentGroupFactory($this->Group);
+			if ($dgf->isError())
+				exit_error($dgf->getErrorMessage(), 'docman');
+
+			$trashnested_groups =& $dgf->getNested();
+
+			$df->setDocGroupID($this->getID());
+			$d_arr =& $df->getDocuments();
+
+			$trashnested_docs = array();
+			/* put the doc objects into an array keyed of the docgroup */
+			if (is_array($d_arr)) {
+				foreach ($d_arr as $doc) {
+					$trashnested_docs[$doc->getDocGroupID()][] = $doc;
+				}
+			}
+
+			if (is_array($trashnested_groups[$this->getID()])) {
+				foreach ($trashnested_groups[$this->getID()] as $dg) {
+					$localdf = new DocumentFactory($this->Group);
+					$localdf->setDocGroupID($dg->getID());
+					$d_arr =& $localdf->getDocuments();
+					if (is_array($d_arr)) {
+						foreach ($d_arr as $doc) {
+							$trashnested_docs[$doc->getDocGroupID()][] = $doc;
+						}
+					}
+				}
+			}
+
+			$localdocgroup_arr = array();
+			$localdocgroup_arr[] = $this->getID();
+			if (is_array(@$trashnested_groups[$docgroup])) {
+				foreach ($trashnested_groups[$docgroup] as $dg) {
+					if (!$dg->setStateID($stateid))
+						return false;
+					$localdocgroup_arr[] = $dg->getID();
+				}
+			}
+
+			foreach ($localdocgroup_arr as $docgroup_id) {
+				if (isset($trashnested_docs[$docgroup_id]) && is_array($trashnested_docs[$docgroup_id])) {
+					foreach ($trashnested_docs[$docgroup_id] as $d) {
+						if (!$d->setState($stateid))
+							return false;
+					}
+				}
+			}
+
+			$dm = new DocumentManager($this->Group);
+			if (!$this->setParentDocGroupId($dm->getTrashID()))
+				return false;
+		}
 		return $this->setValueinDB(array('stateid'), array($stateid));
 	}
 
@@ -739,6 +798,20 @@ class DocumentGroup extends Error {
 	}
 
 	/**
+	 * trash - move this directory and his contents to trash
+	 *
+	 * @return	bool	success or not.
+	 */
+	function trash() {
+		if (!$this->getLocked() || ((time() - $this->getLockdate()) > 600)) {
+			//we need to move recursively all docs and all doc_groups in trash
+			// aka setStateID to 2.
+			if ($this->setStateID(2, true))
+				return true;
+		}
+		return false;
+	}
+	/**
 	 * injectZip - private method to inject a zip archive tree and files
 	 *
 	 * @param	array	$uploadedZip	uploaded zip
diff --git a/src/common/docman/actions/editdocgroup.php b/src/common/docman/actions/editdocgroup.php
index b7c45a0..11e9161 100644
--- a/src/common/docman/actions/editdocgroup.php
+++ b/src/common/docman/actions/editdocgroup.php
@@ -5,7 +5,7 @@
  * Copyright 2000, Quentin Cregan/Sourceforge
  * Copyright 2002-2003, Tim Perdue/GForge, LLC
  * Copyright 2010-2011, Franck Villaume - Capgemini
- * Copyright 2013, Franck Villaume - TrivialDev
+ * Copyright 2013-2014, Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -36,12 +36,12 @@ $urlredirect = '/docman/?group_id='.$group_id.'&view=listfile&dirid='.$dirid;
 // plugin projects-hierarchy handler
 if ($childgroup_id) {
 	$g = group_get_object($childgroup_id);
-	$urlredirect = '/docman/?group_id='.$group_id.'&view=listfile&dirid='.$dirid.'&childgroup_id='.$childgroup_id;
+	$urlredirect .= '&childgroup_id='.$childgroup_id;
 }
 
 if (!forge_check_perm('docman', $g->getID(), 'approve')) {
 	$return_msg = _('Document Manager Action Denied.');
-	session_redirect('/docman/?group_id='.$group_id.'&view=listfile&dirid='.$dirid.'&warning_msg='.urlencode($return_msg));
+	session_redirect($urlredirect.'&warning_msg='.urlencode($return_msg));
 }
 
 $groupname = getStringFromRequest('groupname');
@@ -50,54 +50,16 @@ $dg = new DocumentGroup($g, $dirid);
 if ($dg->isError())
 	session_redirect($urlredirect.'&error_msg='.urlencode($dg->getErrorMessage()));
 
+$currentParentID = $dg->getParentID();
 if (!$dg->update($groupname, $parent_dirid))
 	session_redirect($urlredirect.'&error_msg='.urlencode($dg->getErrorMessage()));
 
-if ($dg->getState() == 2) {
-	/**
-	 * we need to update stateid for the content
-	 * Get the document groups info
-	 */
-	$df = new DocumentFactory($g);
-	if ($df->isError())
-		exit_error($df->getErrorMessage(), 'docman');
-
-	$dgf = new DocumentGroupFactory($g);
-	if ($dgf->isError())
-		exit_error($dgf->getErrorMessage(), 'docman');
-
-	$trashnested_groups =& $dgf->getNested(2);
-
-	$df->setDocGroupID($dirid);
-	$d_arr =& $df->getDocuments();
-
-	$trashnested_docs = array();
-	/* put the doc objects into an array keyed of the docgroup */
-	if (is_array($d_arr)) {
-		foreach ($d_arr as $doc) {
-			$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-		}
-	}
-
-	if (is_array($trashnested_groups[$dirid])) {
-		foreach ($trashnested_groups[$dirid] as $ndg) {
-			$localdf = new DocumentFactory($g);
-			$localdf->setDocGroupID($ndg->getID());
-			$d_arr =& $localdf->getDocuments();
-			if (is_array($d_arr)) {
-				foreach ($d_arr as $doc) {
-					$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-				}
-			}
-		}
-	}
-
-	docman_recursive_stateid($dirid, $trashnested_groups, $trashnested_docs, 1);
+$dm = new DocumentManager($g);
+if ($dg->getState() == 2 && ($currentParentID == $dm->getTrashID())) {
+	if (!$dg->setStateID('1', true))
+		session_redirect($urlredirect.'&error_msg='.urlencode($dg->getErrorMessage()));
 }
 
-if (!$dg->setStateID('1'))
-	session_redirect($urlredirect.'&error_msg='.urlencode($dg->getErrorMessage()));
-
 $return_msg = sprintf(_('Documents folder %s updated successfully'), $dg->getName());
 if ($childgroup_id)
 	$return_msg .= ' '.sprintf(_('on project %s'), $g->getPublicName());
diff --git a/src/common/docman/actions/trashdir.php b/src/common/docman/actions/trashdir.php
index ab8299a..cb55879 100644
--- a/src/common/docman/actions/trashdir.php
+++ b/src/common/docman/actions/trashdir.php
@@ -5,7 +5,7 @@
  * Copyright 2000, Quentin Cregan/Sourceforge
  * Copyright 2002-2003, Tim Perdue/GForge, LLC
  * Copyright 2010-2011, Franck Villaume - Capgemini
- * Copyright 2013, Franck Villaume - TrivialDev
+ * Copyright 2013-2014 Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -47,53 +47,11 @@ if ($childgroup_id) {
 	$g = group_get_object($childgroup_id);
 }
 
-/* when moving a document group to trash, it's recursive and it's applied to documents that belong to these document groups */
-/* Get the document groups info */
-$df = new DocumentFactory($g);
-if ($df->isError())
-	exit_error($df->getErrorMessage(), 'docman');
-
-$dgf = new DocumentGroupFactory($g);
-if ($dgf->isError())
-	exit_error($dgf->getErrorMessage(), 'docman');
-
-$trashnested_groups =& $dgf->getNested();
-
-$df->setDocGroupID($dirid);
-$d_arr =& $df->getDocuments();
-
-$trashnested_docs = array();
-/* put the doc objects into an array keyed of the docgroup */
-if (is_array($d_arr)) {
-	foreach ($d_arr as $doc) {
-		$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-	}
-}
-
-if (is_array($trashnested_groups[$dirid])) {
-	foreach ($trashnested_groups[$dirid] as $dg) {
-		$localdf = new DocumentFactory($g);
-		$localdf->setDocGroupID($dg->getID());
-		$d_arr =& $localdf->getDocuments();
-		if (is_array($d_arr)) {
-			foreach ($d_arr as $doc) {
-				$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-			}
-		}
-	}
-}
-
-/* set to trash content of this dirid */
-docman_recursive_stateid($dirid, $trashnested_groups, $trashnested_docs, 2);
-
 /* set this dirid to trash */
 $dg = new DocumentGroup($g, $dirid);
 $currentParent = $dg->getParentID();
-if (!$dg->setStateID('2'))
-	session_redirect($redirecturl.'&error_msg='.urlencode($dg->getErrorMessage()));
 
-$dm = new DocumentManager($g);
-if (!$dg->setParentDocGroupId($dm->getTrashID()))
+if (!$dg->trash())
 	session_redirect($redirecturl.'&dirid='.$currentParent.'&error_msg='.urlencode($dg->getErrorMessage()));
 
 $return_msg = sprintf(_('Documents folder %s moved to trash successfully.'),$dg->getName());
diff --git a/src/common/docman/include/utils.php b/src/common/docman/include/utils.php
index 3d7afba..73f2a76 100644
--- a/src/common/docman/include/utils.php
+++ b/src/common/docman/include/utils.php
@@ -73,21 +73,3 @@ function docman_fill_zip($zip, $nested_groups, $document_factory, $docgroup = 0,
 	}
 	return true;
 }
-
-function docman_recursive_stateid($docgroup, $nested_groups, $nested_docs, $stateid = 2) {
-	$localdocgroup_arr = array();
-	$localdocgroup_arr[] = $docgroup;
-	if (is_array(@$nested_groups[$docgroup])) {
-		foreach ($nested_groups[$docgroup] as $dg) {
-			$dg->setStateID($stateid);
-			$localdocgroup_arr[] = $dg->getID();
-		}
-	}
-	foreach ($localdocgroup_arr as $docgroup_id) {
-		if (isset($nested_docs[$docgroup_id]) && is_array($nested_docs[$docgroup_id])) {
-			foreach ($nested_docs[$docgroup_id] as $d) {
-				$d->setState($stateid);
-			}
-		}
-	}
-}
diff --git a/src/common/docman/include/webdav.php b/src/common/docman/include/webdav.php
index fa2d9d7..da2b858 100644
--- a/src/common/docman/include/webdav.php
+++ b/src/common/docman/include/webdav.php
@@ -357,51 +357,17 @@ class HTTP_WebDAV_Server_Docman extends HTTP_WebDAV_Server {
 		$analysed_path = $this->analyse($subpath, $group_id);
 		$g = group_get_object($group_id);
 		if ($analysed_path['isdir']) {
-			$df = new DocumentFactory($g);
-			if ($df->isError())
-				exit_error($df->getErrorMessage(), 'docman');
-
-			$dgf = new DocumentGroupFactory($g);
-			if ($dgf->isError())
-				exit_error($dgf->getErrorMessage(), 'docman');
-
-			$trashnested_groups =& $dgf->getNested();
-			$df->setDocGroupID($analysed_path['doc_group']);
-			$d_arr =& $df->getDocuments();
-			if (is_array($d_arr)) {
-				foreach ($d_arr as $doc) {
-					$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-				}
-			}
-
-			if (is_array($trashnested_groups[$analysed_path['doc_group']])) {
-				foreach ($trashnested_groups[$analysed_path['doc_group']] as $dg) {
-					$localdf = new DocumentFactory($g);
-					$localdf->setDocGroupID($dg->getID());
-					$d_arr =& $localdf->getDocuments();
-					if (is_array($d_arr)) {
-						foreach ($d_arr as $doc) {
-							$trashnested_docs[$doc->getDocGroupID()][] = $doc;
-						}
-					}
-				}
-			}
-			/* set this dirid to trash */
+			/* set this doc_group to trash */
 			$dg = new DocumentGroup($g, $analysed_path['doc_group']);
-			$currentParent = $dg->getParentID();
-			if (!$dg->setStateID('2'))
-				session_redirect($redirecturl.'&error_msg='.urlencode($dg->getErrorMessage()));
-
-			$dm = new DocumentManager($g);
-			if (!$dg->setParentDocGroupId($dm->getTrashID()))
-				session_redirect($redirecturl.'&dirid='.$currentParent.'&error_msg='.urlencode($dg->getErrorMessage()));
+			if ($dg->trash())
+				return '200';
 
-			return '200';
+			return '423';
 		} else {
 			if ($analysed_path['docid']) {
 				$d = new Document($g, $analysed_path['docid']);
-				$d->trash();
-				return '200';
+				if ($d->trash())
+					return '200';
 			}
 		}
 		return '404';
diff --git a/src/common/docman/views/listtrashfile.php b/src/common/docman/views/listtrashfile.php
index d5013e0..c7091a7 100644
--- a/src/common/docman/views/listtrashfile.php
+++ b/src/common/docman/views/listtrashfile.php
@@ -122,7 +122,7 @@ jQuery(document).ready(function() {
 if ($DocGroupName) {
 	$content = _('Document Folder')._(': ').html_e('i', array(), $DocGroupName, false).' ';
 	if ($DocGroupName != '.trash') {
-		$content .= util_make_link('#', html_image('docman/configure-directory.png', 22, 22, array('alt' => _('Edit'))), array('id' => 'docman-editdirectory', 'class' => 'tabtitle', 'title' => _('Edit this folder')), true);
+		$content .= util_make_link('#', html_image('docman/configure-directory.png', 22, 22, array('alt' => _('Edit'))), array('id' => 'docman-editdirectory', 'class' => 'tabtitle', 'title' => _('Edit this folder'), 'onclick' => 'javascript:controllerListTrash.toggleEditDirectoryView({lockIntervalDelay: 60000, doc_group:'.$ndg->getID().', groupId:'.$ndg->Group->getID().', docManURL:\''.util_make_uri('/docman').'\'})' ), true);
 		$content .= util_make_link($redirecturl.'&action=deldir', html_image('docman/delete-directory.png', 22, 22, array('alt' => _('Delete folder'))), array('id' => 'docman-deletedirectory', 'class' => 'tabtitle', 'title' => _('Delete permanently this folder and his content.')));
 	}
 	echo html_e('h3', array('class' => 'docman_h3'), $content, false);

-----------------------------------------------------------------------

Summary of changes:
 src/common/docman/Document.class.php       |   19 ++++---
 src/common/docman/DocumentGroup.class.php  |   75 +++++++++++++++++++++++++++-
 src/common/docman/actions/editdocgroup.php |   54 +++-----------------
 src/common/docman/actions/trashdir.php     |   46 +----------------
 src/common/docman/include/utils.php        |   18 -------
 src/common/docman/include/webdav.php       |   46 +++--------------
 src/common/docman/views/listtrashfile.php  |    2 +-
 7 files changed, 102 insertions(+), 158 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list