[Fusionforge-commits] FusionForge branch master updated. 6.0.4-1161-g361dfaa

Franck Villaume nerville at libremir.placard.fr.eu.org
Fri Nov 18 09:36:39 CET 2016


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  361dfaa4a95ac81bac46d9a8aefdf9d46e0026af (commit)
      from  8753ebcc405bffdfbbebd7d2f00419409fc821b9 (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=361dfaa4a95ac81bac46d9a8aefdf9d46e0026af

commit 361dfaa4a95ac81bac46d9a8aefdf9d46e0026af
Author: St├ęphane-Eymeric Bredthauer <sebredthauer at gmail.com>
Date:   Thu Nov 17 21:19:24 2016 +0100

    Tracker: fix none as default

diff --git a/src/common/tracker/ArtifactExtraField.class.php b/src/common/tracker/ArtifactExtraField.class.php
index 1ab000e..600c6eb 100644
--- a/src/common/tracker/ArtifactExtraField.class.php
+++ b/src/common/tracker/ArtifactExtraField.class.php
@@ -497,51 +497,48 @@ class ArtifactExtraField extends FFError {
 		if (in_array($type, unserialize(ARTIFACT_EXTRAFIELDTYPE_MULTICHOICETYPE))) {
 			if (is_array($default)) {
 				$efValues = $this->getAvailableValues();
+				$oldDefault = $this->getDefaultValues();
+				if (!is_array($oldDefault)) {
+					if (is_null($oldDefault)) {
+						$oldDefault = array();
+					} else {
+						$oldDefault = array($oldDefault);
+					}
+				}
+				$efID = $this->getID();
+				if ($this->getShow100()) {
+					$efValues [] = array('element_id'=>100);
+				}
 				foreach ($efValues as $efValue) {
-					if (isset($default[$efValue['element_id']]) && $default[$efValue['element_id']] && $efValue['is_default']==0) {
-						$efe = new ArtifactExtraFieldElement($this, $efValue['element_id']);
-						if (!$efe || !is_object($efe)) {
-							if (is_object($efe)) {
-								$this->setError(_('Unable to create extra field element').' '.$efValue['element_name'].' '._(':').$efe->getErrorMessage());
-							} else {
-								$this->setError(_('Unable to create extra field element').' '.$efValue['element_name']);
-							}
-							$return = false;
-						} elseif (!$efe->update($efValue['element_name'], $efValue['status_id'], $efValue['auto_assign_to'], true)) {
-							$this->setError(_('Unable to update extra field element').' '.$efValue['element_name'].' '._(':').$efe->getErrorMessage());
+					$value = $efValue['element_id'];
+					if (in_array($value, $default) && !in_array($value, $oldDefault)) {
+						$res = db_query_params ('INSERT INTO artifact_extra_field_default (extra_field_id, default_value) VALUES ($1,$2)',
+								array ($efID, $value)) ;
+						if (!$res) {
+							$this->setError(_('Unable to set default values')._(':').' '.db_error());
 							$return = false;
 						}
-					} elseif (((isset($default[$efValue['element_id']]) && !$default[$efValue['element_id']]) || !isset($default[$efValue['element_id']]))  && $efValue['is_default']==1) {
-						$efe = new ArtifactExtraFieldElement($this, $efValue['element_id']);
-						if (!$efe || !is_object($efe)) {
-							if (is_object($efe)) {
-								$this->setError(_('Unable to create extra field element').' '.$efValue['element_name'].' '._(':').$efe->getErrorMessage());
-							} else {
-								$this->setError(_('Unable to create extra field element'.' '.$efValue['element_name']));
-							}
-							$return = false;
-						} elseif (!$efe->update($efValue['element_name'], $efValue['status_id'], $efValue['auto_assign_to'], false)) {
-							$this->setError(_('Unable to update extra field element').' '.$efValue['element_name'].' '._(':').$efe->getErrorMessage());
+					} elseif (!in_array($value, $default) && in_array($value, $oldDefault)) {
+						$res = db_query_params ('DELETE FROM artifact_extra_field_default WHERE extra_field_id=$1 AND default_value=$2',
+								array ($efID, $value)) ;
+						if (!$res) {
+							$this->setError(_('Unable to set default values')._(':').' '.db_error());
 							$return = false;
 						}
 					}
 				}
 			} elseif (is_integer($default)) {
-				if ($default == '100') {
-					$return = $this->resetDefaultValues();
-				} else {
-					$efe = new ArtifactExtraFieldElement($this, $default);
-					if (!$efe || !is_object($efe)) {
-						if (is_object($efe)) {
-							$this->setError(_('Unable to create extra field element').' (id='.$default.') '._(':').$efe->getErrorMessage());
-						} else {
-							$this->setError(_('Unable to create extra field element'.' (id='.$default.')'));
-						}
-						$return = false;
-					} elseif (!$efe->update($efe->getName(), $efe->getStatusID(), $efe->getAutoAssignto(), true)) {
-						$this->setError(_('Unable to update extra field element').' '.$efe->getName().' '._(':').$efe->getErrorMessage());
-						$return = false;
+				$efe = new ArtifactExtraFieldElement($this, $default);
+				if (!$efe || !is_object($efe)) {
+					if (is_object($efe)) {
+						$this->setError(_('Unable to create extra field element').' (id='.$default.') '._(':').$efe->getErrorMessage());
+					} else {
+						$this->setError(_('Unable to create extra field element'.' (id='.$default.')'));
 					}
+					$return = false;
+				} elseif (!$efe->setAsDefault(true)) {
+					$this->setError(_('Unable to update extra field element').' '.$efe->getName().' '._(':').$efe->getErrorMessage());
+					$return = false;
 				}
 			} else {
 				$this->setError(_('Unable to set default value')._(':').$default);
@@ -560,7 +557,7 @@ class ArtifactExtraField extends FFError {
 							$this->setError(_('Unable to create extra field element'.' (id='.$default.')'));
 						}
 						$return = false;
-					} elseif (!$efe->update($efe->getName(), $efe->getStatusID(), $efe->getAutoAssignto(), true)) {
+					} elseif (!$efe->setAsDefault(true)) {
 						$this->setError(_('Unable to update extra field element').' '.$efe->getName().' '._(':').$efe->getErrorMessage());
 						$return = false;
 					}
@@ -625,24 +622,39 @@ class ArtifactExtraField extends FFError {
 		if (in_array($type, unserialize(ARTIFACT_EXTRAFIELDTYPE_VALUETYPE))) {
 			$row = db_fetch_array($res);
 			$return = $row['default_value'];
-			if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER && is_null($return)) {
-				$return = 0;
+			if (is_null($return) && $type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
+					$return = 0;
 			}
 		} elseif ($type == ARTIFACT_EXTRAFIELDTYPE_USER || $type == ARTIFACT_EXTRAFIELDTYPE_RELEASE) {
 			$row = db_fetch_array($res);
 			if (!$row) {
-				$return = 100;
+				if ($this->getShow100()) {
+					$return = 100;
+				} else {
+					$return = null;
+				}
 			} else {
 				$return = (integer)$row['default_value'];
 			}
 		} elseif (in_array($type, unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
 			$row = db_fetch_array($res);
-			$return = (integer)$row['default_value'];
+			if (!$row) {
+				if ($this->getShow100()) {
+					$return = 100;
+				} else {
+					$return = null;
+				}
+			} else {
+				$return = (integer)$row['default_value'];
+			}
 		} elseif (in_array($type, unserialize(ARTIFACT_EXTRAFIELDTYPE_MULTICHOICETYPE))) {
 			$return = array();
 			while ($row = db_fetch_array($res)) {
 				$return[] = $row['default_value'];
 			}
+			if (empty($return)) {
+				$return = null;
+			}
 		}
 		return $return;
 	}
@@ -693,6 +705,7 @@ class ArtifactExtraField extends FFError {
 						ORDER BY element_pos ASC, element_id ASC',
 						array ($this->getID()));
 			$default = $this->getDefaultValues();
+
 			$return = array();
 			if (in_array($type, unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
 				while ($row = db_fetch_array($res)) {
diff --git a/src/common/tracker/ArtifactExtraFieldElement.class.php b/src/common/tracker/ArtifactExtraFieldElement.class.php
index bc3d565..4ea0226 100644
--- a/src/common/tracker/ArtifactExtraFieldElement.class.php
+++ b/src/common/tracker/ArtifactExtraFieldElement.class.php
@@ -301,6 +301,40 @@ class ArtifactExtraFieldElement extends FFError {
 	}
 
 	/**
+	 * setAsDefault - set this field element as default value or not.
+	 *
+	 * @param	isDefault	boolean true-> set as default, false->unset as default
+	 * @return	boolean
+	 */
+	function setAsDefault($isDefault) {
+		if ($this->isDefault() && !$is_default) {
+			$result = db_query_params ('DELETE FROM artifact_extra_field_default WHERE extra_field_id = $1 AND default_value = $2',
+					array ($this->ArtifactExtraField->getID(), $this->getID()));
+			if (!$result) {
+				$this->setError(db_error());
+				return false;
+			}
+		} elseif (!$this->isDefault() && $is_default) {
+			if (in_array($this->ArtifactExtraField->getType(), unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
+				$result = db_query_params ('DELETE FROM artifact_extra_field_default WHERE extra_field_id = $1',
+						array ($this->ArtifactExtraField->getID()));
+				if (!$result) {
+					$this->setError(db_error());
+					$return = false;
+				}
+			}
+			$result = db_query_params ('INSERT INTO artifact_extra_field_default (extra_field_id, default_value) VALUES ($1,$2)',
+					array ($this->ArtifactExtraField->getID(), $this->getID()));
+			if (!$result) {
+				$this->setError(db_error());
+				return false;
+			}
+		}
+		return true;
+	}
+
+
+	/**
 	 * getChildrenElements - return the array of the elements of children fields who depend on current element
 	 *
 	 * @return	array of parent elements
@@ -438,37 +472,9 @@ class ArtifactExtraFieldElement extends FFError {
 			return false;
 		}
 
-		$default = db_query_params ('SELECT 1 FROM artifact_extra_field_default WHERE default_value=$1',
-				array ($this->getID())) ;
-		if (!$default) {
-			$this->setError('ArtifactExtraField: Invalid ArtifactExtraFieldElement ID');
+		if (!$this->setAsDefault($is_default)) {
 			return false;
 		}
-		if (db_numrows($default) >= 1 && !$is_default) {
-			$result = db_query_params ('DELETE FROM artifact_extra_field_default WHERE extra_field_id = $1 AND default_value = $2',
-					array ($this->ArtifactExtraField->getID(), $this->getID()));
-			if (!$result) {
-				$this->setError(db_error());
-				return false;
-			}
-		}
-		if (db_numrows($default) == 0 && $is_default) {
-			if (in_array($this->ArtifactExtraField->getType(), unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
-				$result = db_query_params ('DELETE FROM artifact_extra_field_default WHERE extra_field_id = $1',
-						array ($this->ArtifactExtraField->getID()));
-				if (!$result) {
-					$this->setError(db_error());
-					$return = false;
-				}
-			}
-			$result = db_query_params ('INSERT INTO artifact_extra_field_default (extra_field_id, default_value) VALUES ($1,$2)',
-					array ($this->ArtifactExtraField->getID(), $this->getID()));
-			if (!$result) {
-				$this->setError(db_error());
-				return false;
-			}
-		}
-		db_free_result($default);
 		return true;
 	}
 
diff --git a/src/common/tracker/ArtifactType.class.php b/src/common/tracker/ArtifactType.class.php
index 3ceec01..2e8eb14 100644
--- a/src/common/tracker/ArtifactType.class.php
+++ b/src/common/tracker/ArtifactType.class.php
@@ -827,6 +827,7 @@ class ArtifactType extends FFError {
 						$role = RBACEngine::getInstance()->getRoleById($roleEl['element_name']);
 						if ( $role->hasUser($defaultUser)) {
 							$nef->setDefaultValues($default);
+							break;
 						}
 					}
 				} else {
diff --git a/src/common/tracker/actions/admin-updates.php b/src/common/tracker/actions/admin-updates.php
index 38ac319..86edb5e 100644
--- a/src/common/tracker/actions/admin-updates.php
+++ b/src/common/tracker/actions/admin-updates.php
@@ -640,6 +640,7 @@ if (getStringFromRequest('add_extrafield')) {
 			$is_default = getIntFromRequest('is_default');
 		} else {
 			$is_default =  getArrayFromRequest('is_default');
+			$is_default = array_keys($is_default);
 		}
 		if ($ac->setDefaultValues($is_default)) {
 			$feedback .= _('Default value(s) Updated');
diff --git a/src/common/tracker/views/form-addextrafieldoption.php b/src/common/tracker/views/form-addextrafieldoption.php
index c718bc5..8dbbe4c 100644
--- a/src/common/tracker/views/form-addextrafieldoption.php
+++ b/src/common/tracker/views/form-addextrafieldoption.php
@@ -116,7 +116,7 @@ if (!$ac || !is_object($ac)) {
 				}
 				$title_arr[]='';
 				echo $HTML->listTableTop ($title_arr,false, ' ');
-				if (in_array($efType, unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
+				if (in_array($efType, unserialize(ARTIFACT_EXTRAFIELDTYPE_CHOICETYPE))) {
 					$row_attrs = array('class'=>$HTML->boxGetAltRowStyle(-1,true));
 					$cells = array();
 					$cells[] = array('', 'class'=>'align-right');
@@ -125,7 +125,29 @@ if (!$ac || !is_object($ac)) {
 					}
 					$cells[] = array('', 'class'=>'align-center');
 					$cells[] = array(_('None'));
-					$content = html_build_radio_button('is_default', 100, true);
+					if (in_array($efType, unserialize(ARTIFACT_EXTRAFIELDTYPE_MULTICHOICETYPE))) {
+						$defaultValues = $ac->getDefaultValues();
+						if (is_array($defaultValues)) {
+							if (in_array('100', $defaultValues)) {
+								$content = html_build_checkbox('is_default[100]', false, true);
+							} else {
+								$content = html_build_checkbox('is_default[100]', false, false);
+							}
+						} else {
+							if ($defaultValues == 100) {
+								$content = html_build_checkbox('is_default[100]', false, true);
+							} else {
+								$content = html_build_checkbox('is_default[100]', false, false);
+							}
+						}
+					} elseif (in_array($efType, unserialize(ARTIFACT_EXTRAFIELDTYPE_SINGLECHOICETYPE))) {
+						$defaultValues = $ac->getDefaultValues();
+						if ($defaultValues == 100) {
+							$content = html_build_radio_button('is_default', 100, true);
+						} else {
+							$content = html_build_radio_button('is_default', 100, false);
+						}
+					}
 					$cells[] = array($content, 'class'=>'align-center');
 					$cells[] = array('', 'class'=>'align-center');
 					echo $HTML->multiTableRow($row_attrs, $cells);

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

Summary of changes:
 src/common/tracker/ArtifactExtraField.class.php    | 95 ++++++++++++----------
 .../tracker/ArtifactExtraFieldElement.class.php    | 64 ++++++++-------
 src/common/tracker/ArtifactType.class.php          |  1 +
 src/common/tracker/actions/admin-updates.php       |  1 +
 .../tracker/views/form-addextrafieldoption.php     | 26 +++++-
 5 files changed, 115 insertions(+), 72 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list