[Fusionforge-commits] FusionForge branch master updated. v6.0.5-1871-g7afb551

Franck Villaume nerville at libremir.placard.fr.eu.org
Sun May 28 18:23:56 CEST 2017


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  7afb551995a945bab4edb6e8895903463e762d27 (commit)
      from  3af9c97c6eb2c994aab4974cf9c3ad6182cdabbb (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 -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=7afb551995a945bab4edb6e8895903463e762d27

commit 7afb551995a945bab4edb6e8895903463e762d27
Author: St├ęphane-Eymeric Bredthauer <sebredthauer at gmail.com>
Date:   Sun May 28 18:13:37 2017 +0200

    Tracker: Artifacts dependencies, part 2

diff --git a/src/common/tracker/Artifact.class.php b/src/common/tracker/Artifact.class.php
index 5629a70..98179f6 100644
--- a/src/common/tracker/Artifact.class.php
+++ b/src/common/tracker/Artifact.class.php
@@ -134,11 +134,18 @@ class Artifact extends FFObject {
 	/**
 	 * Database result set of children
 	 *
-	 * @var	result	$children
+	 * @var	array	$children
 	 */
 	var $children;
 
 	/**
+	 * Database result set of parent
+	 *
+	 * @var	integer|boolean	$parent
+	 */
+	var $parent;
+
+	/**
 	 * cached return value of getVotes
 	 * @var	int|bool	$votes
 	 */
@@ -1628,14 +1635,177 @@ class Artifact extends FFObject {
 				}
 			}
 		}
-		unset($this->extra_field_data);
 
-		if ($update)
+		// update parent
+		if ($this->hasParent()) {
+			$parentId = $this->getParent();
+			$parentArtifact = artifact_get_object($parentId);
+			$parentArtifact->updateOnChildChange($changes);
+		}
+
+		// update children
+		if ($this->hasChildren()) {
+			$childrenArray = $this->getChildren();
+
+			foreach ($childrenArray as $childArray) {
+				$childId = $childArray['artifact_id'];
+				$childArtifact = artifact_get_object($childId);
+				$childArtifact->updateOnParentChange($changes);
+			}
+		}
+
+		unset($this->extra_field_data);
+		if ($update) {
 			$this->updateLastModified($importData);
+		}
 
 		return true;
 	}
 
+	function updateOnParentChange($parentChanges) {
+		if ($this->hasParent()) {
+			$return = false;
+			$changes = false;
+
+			$extra_fields = $this->getExtraFieldData();
+			$priority = $this->getPriority();
+			$status_id = $this->getStatusID();
+			$status_id = $this->getArtifactType()->remapStatus($status_id, $extra_fields);
+			$assigned_to = $this->getAssignedTo();
+			$summary = $this->getSummary();
+			$canned_response = 100;
+			$details = "";
+			$artifact_type_id = $this->getArtifactType()->getID();
+			$description = $this->getDetails();
+			$at = $this->getArtifactType();
+			$ef = $at->getExtraFields();
+
+			$parent = $this->getParent();
+			$parentArtifact = artifact_get_object($parent);
+			$parentExtra_fields = $parentArtifact->getExtraFieldData();
+			$parentAt = $parentArtifact->getArtifactType();
+
+			foreach ($extra_fields as $key=>$value) {
+				$distribution_rule = $ef[$key]['distribution_rule'];
+				switch ($distribution_rule) {
+					case ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_NO_DISTRIBUTION:
+						break;
+					case ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_STATUS_CLOSE_RECURSIVELY:
+						$parentStatusID = $parentArtifact->getStatusID();
+						$parentStatusID = $parentAt->remapStatus($parentStatusID, $parentExtra_fields);
+						if (isset($parentChanges['status']) && $parentStatusID != 1 && $status_id == 1) {
+							$changes = true;
+							if ($parentAt->getID() == $at->getID()) {
+								$status_id = $parentStatusID;
+								if ($at->usesCustomStatuses()) {
+									$extra_fields[$at->getCustomStatusField()] = $parentExtra_fields[$parentAt->getCustomStatusField()];
+									$status_id = $at->remapStatus($status_id, $extra_fields);
+								}
+							} else {
+								if (!$at->usesCustomStatuses()) {
+									$status_id = 2; //closed
+								} else {
+									$parentStatusList = $parentAt->getExtraFieldElements($parentAt->getCustomStatusField());
+									$parentStatusName = $parentStatusList[$parentAt->getCustomStatusField()];
+									$statusList = $at->getExtraFieldElements($at->getCustomStatusField());
+									$found = false;
+									foreach ($statusList as $id->$statusName) {
+										if ($parentStatusName == $statusName) {
+											$found = true;
+											$extra_fields[$at->getCustomStatusField()] = $id;
+											$status_id = 2;
+											break;
+										}
+									}
+									//TODO: status not found
+								}
+							}
+						}
+						break;
+				}
+			}
+			if ($changes) {
+				return $this->update($priority,$status_id,
+						$assigned_to,$summary,$canned_response,$details,$artifact_type_id,
+						$extra_fields, $description);
+			}
+		} else {
+			return true;
+		}
+	}
+
+	function updateOnChildChange($childChanges) {
+		if ($this->hasChildren()) {
+			$return = false;
+			$changes = false;
+
+			$extra_fields = $this->getExtraFieldData();
+			$priority = $this->getPriority();
+			$status_id = $this->getStatusID();
+			$status_id = $this->getArtifactType()->remapStatus($status_id, $extra_fields);
+			$assigned_to = $this->getAssignedTo();
+			$summary = $this->getSummary();
+			$canned_response = 100;
+			$details = "";
+			$artifact_type_id = $this->getArtifactType()->getID();
+			$description = $this->getDetails();
+			$at = $this->getArtifactType();
+			$ef = $at->getExtraFields();
+
+			$children = $this->getChildren();
+
+			foreach ($extra_fields as $key=>$value) {
+				$aggregation_rule = $ef[$key]['aggregation_rule'];
+				$type = $ef[$key]['field_type'];
+				$alias = $ef[$key]['alias'];
+				switch ($aggregation_rule) {
+					case ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_NO_AGGREGATION:
+						break;
+					case ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_SUM:
+						switch ($type) {
+							case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
+								$sum = 0;
+								break;
+						}
+						foreach ($children as $child) {
+							$childArtifact = artifact_get_object($child['artifact_id']);
+							$childExtra_fields = $childArtifact->getExtraFieldData();
+							if ($at->getID() == $child['group_artifact_id']) {
+								// same tracker
+								$childEf_id= $key;
+							} else {
+								$childAt = $childArtifact->getArtifactType();
+								$childEf= $childAt->getExtraFieldByAlias($alias);
+								if ($childEf) {
+									$childEf_id = $child_ef['extra_field_id'];
+								} else {
+									$childEf_id = false;
+								}
+							}
+							if ($childEf_id) {
+								switch ($type) {
+									case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
+										$sum = $sum+$childExtra_fields[$childEf_id];
+										break;
+								}
+							}
+						}
+						$extra_fields[$key]=$sum;
+						$changes = true;
+						break;
+				}
+			}
+
+			if ($changes) {
+				return $this->update($priority,$status_id,
+						$assigned_to,$summary,$canned_response,$details,$artifact_type_id,
+						$extra_fields, $description);
+			}
+		} else {
+			return true;
+		}
+	}
+
 	/**
 	 * getExtraFieldData - get an array of data for the extra fields associated with this artifact
 	 *
@@ -2041,9 +2211,9 @@ class Artifact extends FFObject {
 
 	function hasChildren() {
 		if (!$this->children) {
-			$res = $this->getChildren();
+			$children = $this->getChildren();
 		}
-		$nb = db_numrows($this->children);
+		$nb = count($this->children);
 		if ($nb>0) {
 			return $nb;
 		}
@@ -2051,45 +2221,50 @@ class Artifact extends FFObject {
 	}
 
 	function  getChildren() {
-		$aid = $this->getID();
 		if (!$this->children) {
-			$this->children = db_query_params ('SELECT *
-		FROM artifact_extra_field_list, artifact_extra_field_data, artifact_group_list, artifact, groups
-		WHERE field_type = $1
-		AND artifact_extra_field_list.extra_field_id=artifact_extra_field_data.extra_field_id
-		AND artifact_group_list.group_artifact_id = artifact_extra_field_list.group_artifact_id
-		AND artifact.artifact_id = artifact_extra_field_data.artifact_id
-		AND groups.group_id = artifact_group_list.group_id
-		AND field_data = $2
-		AND artifact.is_deleted = 0
-		ORDER BY artifact_group_list.group_id ASC, name ASC, artifact.artifact_id ASC',
-					array(ARTIFACT_EXTRAFIELDTYPE_PARENT,
-							$aid));
+			$res = db_query_params ('SELECT *
+													FROM artifact_extra_field_list, artifact_extra_field_data, artifact_group_list, artifact, groups
+													WHERE field_type = $1
+													AND artifact_extra_field_list.extra_field_id=artifact_extra_field_data.extra_field_id
+													AND artifact_group_list.group_artifact_id = artifact_extra_field_list.group_artifact_id
+													AND artifact.artifact_id = artifact_extra_field_data.artifact_id
+													AND groups.group_id = artifact_group_list.group_id
+													AND field_data = $2
+													AND artifact.is_deleted = 0
+													ORDER BY artifact_group_list.group_id ASC, name ASC, artifact.artifact_id ASC',
+								array(ARTIFACT_EXTRAFIELDTYPE_PARENT,
+										$this->getID()));
+			while ($row = db_fetch_array($res)) {
+				$this->children[] = $row;
+			}
+			db_free_result($res);
 		}
 		return $this->children;
 	}
 
 	function hasParent() {
-		return ($this->getParent?true:false);
+		return ($this->getParent()?true:false);
 	}
 
 	function  getParent() {
-		$res = db_query_params ('SELECT field_data FROM
-									artifact_extra_field_data
-									NATURAL INNER JOIN artifact_extra_field_list
-								WHERE
-									field_type = $1
-										AND artifact_id = $2',
-					array(ARTIFACT_EXTRAFIELDTYPE_PARENT,
-							$this->getID()));
-		if (db_numrows($res) == 0) {
-			$return = false;
-		} else {
-			$data = db_fetch_array($res);
-			db_free_result($res);
-			$return = $data['field_data'];
+		if (!isset($this->parent)) {
+			$res = db_query_params ('SELECT field_data FROM
+										artifact_extra_field_data
+										NATURAL INNER JOIN artifact_extra_field_list
+									WHERE
+										field_type = $1
+											AND artifact_id = $2',
+						array(ARTIFACT_EXTRAFIELDTYPE_PARENT,
+								$this->getID()));
+			if (db_numrows($res) == 0) {
+				$this->parent= false;
+			} else {
+				$data = db_fetch_array($res);
+				db_free_result($res);
+				$this->parent= $data['field_data'];
+			}
 		}
-		return $return;
+		return $this->parent;
 	}
 
 
diff --git a/src/common/tracker/ArtifactExtraField.class.php b/src/common/tracker/ArtifactExtraField.class.php
index 0176971..c3a0f7a 100644
--- a/src/common/tracker/ArtifactExtraField.class.php
+++ b/src/common/tracker/ArtifactExtraField.class.php
@@ -53,20 +53,19 @@ define('ARTIFACT_EXTRAFIELDTYPE_EFFORT',21);
 define('ARTIFACT_EXTRAFIELDTYPE_EFFORTRANGE',22);
 define('ARTIFACT_EXTRAFIELDTYPE_PARENT',23);
 
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_SELECT, ARTIFACT_EXTRAFIELDTYPE_RADIO, ARTIFACT_EXTRAFIELDTYPE_STATUS)));
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_CHECKBOX, ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)));
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_CHOICE", serialize (array_merge(unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE), unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE))));
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_SPECALCHOICE", serialize(array(ARTIFACT_EXTRAFIELDTYPE_USER, ARTIFACT_EXTRAFIELDTYPE_RELEASE)));
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_VALUE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_TEXT,ARTIFACT_EXTRAFIELDTYPE_TEXTAREA,ARTIFACT_EXTRAFIELDTYPE_RELATION,ARTIFACT_EXTRAFIELDTYPE_INTEGER,ARTIFACT_EXTRAFIELDTYPE_FORMULA,ARTIFACT_EXTRAFIELDTYPE_DATETIME, ARTIFACT_EXTRAFIELDTYPE_EFFORT)));
+define ('ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE', serialize (array (ARTIFACT_EXTRAFIELDTYPE_SELECT, ARTIFACT_EXTRAFIELDTYPE_RADIO, ARTIFACT_EXTRAFIELDTYPE_STATUS)));
+define ('ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE', serialize (array (ARTIFACT_EXTRAFIELDTYPE_CHECKBOX, ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)));
+define ('ARTIFACT_EXTRAFIELDTYPEGROUP_CHOICE', serialize (array_merge(unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE), unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE))));
+define ('ARTIFACT_EXTRAFIELDTYPEGROUP_SPECALCHOICE', serialize(array(ARTIFACT_EXTRAFIELDTYPE_USER, ARTIFACT_EXTRAFIELDTYPE_RELEASE)));
+define ('ARTIFACT_EXTRAFIELDTYPEGROUP_VALUE', serialize (array (ARTIFACT_EXTRAFIELDTYPE_TEXT,ARTIFACT_EXTRAFIELDTYPE_TEXTAREA,ARTIFACT_EXTRAFIELDTYPE_RELATION,ARTIFACT_EXTRAFIELDTYPE_INTEGER,ARTIFACT_EXTRAFIELDTYPE_FORMULA,ARTIFACT_EXTRAFIELDTYPE_DATETIME, ARTIFACT_EXTRAFIELDTYPE_EFFORT)));
 
-define ("ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_NO_AGGREGATION", 0);
-define ("ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_SUM", 1);
-define ("ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_RESTRICTED", 2);
-define ("ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_UPWARDS", 3);
-
-define ("ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_NO_DISTRIBUTION", 0);
-define ("ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_STATUS_CLOSE_RECURSIVELY", 1);
+define ('ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_NO_AGGREGATION', 0);
+define ('ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_SUM', 1);
+define ('ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_RESTRICTED', 2);
+define ('ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_UPWARDS', 3);
 
+define ('ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_NO_DISTRIBUTION', 0);
+define ('ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_STATUS_CLOSE_RECURSIVELY', 1);
 
 class ArtifactExtraField extends FFError {
 
@@ -1282,15 +1281,22 @@ class ArtifactExtraField extends FFError {
 	function getAvailableAggregationRules() {
 		$return= array(ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_NO_AGGREGATION => _('Parent value is not depending on children\'s values'));
 		$type = $this->getType();
-		if ($type == ARTIFACT_EXTRAFIELDTYPE_EFFORT) {
+
+// 		if ($type == ARTIFACT_EXTRAFIELDTYPE_EFFORT) {
+// 			$return = array_merge($return, array(ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_SUM => _('Parent value is the sum of children\'s values')));
+// 		}
+
+		if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
 			$return = array_merge($return, array(ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_SUM => _('Parent value is the sum of children\'s values')));
 		}
-		if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
-			$return = array_merge($return, array(
-													ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_RESTRICTED => _('Deny closing the parent, as long as not all children have been closed'),
-													ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_UPWARDS => _('Close the parent, after the last child has been closed')
-								));
-		}
+
+// 		if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
+// 			$return = array_merge($return, array(
+// 													ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_RESTRICTED => _('Deny closing the parent, as long as not all children have been closed'),
+// 													ARTIFACT_EXTRAFIELD_AGGREGATION_RULE_STATUS_CLOSE_UPWARDS => _('Close the parent, after the last child has been closed')
+// 								));
+// 		}
+
 		if (count($return)==1) {
 			$return = array();
 		}
@@ -1309,9 +1315,11 @@ class ArtifactExtraField extends FFError {
 	function getAvailableDistributionRules() {
 		$return= array(ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_NO_DISTRIBUTION => _('Parent value is not depending on children\'s values'));
 		$type = $this->getType();
+
 		if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
 			$return = array_merge($return, array(ARTIFACT_EXTRAFIELD_DISTRIBUTION_RULE_STATUS_CLOSE_RECURSIVELY => _('Closure of parent involves recursive closure of children')));
 		}
+
 		if (count($return)==1) {
 			$return = array();
 		}
diff --git a/src/common/tracker/ArtifactType.class.php b/src/common/tracker/ArtifactType.class.php
index 8057c1a..2639c50 100644
--- a/src/common/tracker/ArtifactType.class.php
+++ b/src/common/tracker/ArtifactType.class.php
@@ -1581,6 +1581,18 @@ class ArtifactType extends FFError {
 		$lm = new WidgetLayoutManager();
 		return $lm->getLayout($this->getID(), WidgetLayoutManager::OWNER_TYPE_TRACKER);
 	}
+
+	function getExtraFieldByAlias($alias){
+		$return = false;
+		$efs = $this->getExtraFields();
+		foreach ($efs as $ef) {
+			if ($alias == $ef['alias']) {
+				$return = $ef;
+				break;
+			}
+		}
+		return $return;
+	}
 }
 
 // Local Variables:
diff --git a/src/common/tracker/include/ArtifactHtml.class.php b/src/common/tracker/include/ArtifactHtml.class.php
index b8eef85..c5813b7 100644
--- a/src/common/tracker/include/ArtifactHtml.class.php
+++ b/src/common/tracker/include/ArtifactHtml.class.php
@@ -225,8 +225,8 @@ function hide_edit_button(id) {
 	}
 
 	function showChildren() {
-		$result=$this->getChildren();
-		$rows= db_numrows($result);
+		$children = $this->getChildren();
+		$rows= count($children);
 		$return = '';
 		if ($rows > 0){
 			$return = '	<table class="fullwidth">
@@ -234,7 +234,7 @@ function hide_edit_button(id) {
 								<td colspan="2">';
 			$current = '';
 			$end = '';
-			while ($arr = db_fetch_array($result)) {
+			foreach ($children as $arr) {
 				if (forge_check_perm('tracker', $arr['group_artifact_id'], 'read')) {
 					$title = $arr['group_name']._(': ').$arr['name'];
 					if ($title != $current) {

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

Summary of changes:
 src/common/tracker/Artifact.class.php             | 243 +++++++++++++++++++---
 src/common/tracker/ArtifactExtraField.class.php   |  46 ++--
 src/common/tracker/ArtifactType.class.php         |  12 ++
 src/common/tracker/include/ArtifactHtml.class.php |   6 +-
 4 files changed, 251 insertions(+), 56 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list