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 002f0a0c559e022406bff1b904477f36ff56dc3b (commit)
via df23765095ca58554435f1ae479e47fac9f472bb (commit)
via fd9f2a6d7198c0daa25298bc16c2df73374b3678 (commit)
from c9c49431376d6a1d2a6ef6b4bd07ae6db05b262c (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=002f0a0c559e022406bff1b904477f36ff56dc3b
commit 002f0a0c559e022406bff1b904477f36ff56dc3b
Merge: c9c4943 df23765
Author: Franck Villaume <[email protected]>
Date: Fri Jan 27 15:15:19 2017 +0000
merge bredt/master: fix effort field
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=df23765095ca58554435f1ae479e47fac9f472bb
commit df23765095ca58554435f1ae479e47fac9f472bb
Author: Stéphane-Eymeric Bredthauer <[email protected]>
Date: Fri Jan 27 15:51:11 2017 +0100
Tracker: copy effort unit set on 'Apply Template Tracker'
diff --git a/src/common/include/Group.class.php
b/src/common/include/Group.class.php
index 8396b55..332d515 100644
--- a/src/common/include/Group.class.php
+++ b/src/common/include/Group.class.php
@@ -2683,7 +2683,7 @@ class Group extends FFError {
foreach ($oldatf->getArtifactTypes() as
$o) {
$t =
artifactType_get_object($id_mappings['tracker'][$o->getID()]);
$id_mappings['tracker'][$o->getID()] = $t->getID();
- $newEFIds =
$t->cloneFieldsFrom($o->getID(), $o->Group->getID(), $id_mappings);
+ $newEFIds =
$t->cloneFieldsFrom($o->getID(), $id_mappings);
if
(forge_get_config('use_tracker_widget_display')) {
$lm->createDefaultLayoutForTracker($t->getID(), $o->getID(), $newEFIds);
}
diff --git a/src/common/tracker/ArtifactType.class.php
b/src/common/tracker/ArtifactType.class.php
index 8c786f3..239c6be 100644
--- a/src/common/tracker/ArtifactType.class.php
+++ b/src/common/tracker/ArtifactType.class.php
@@ -29,6 +29,7 @@
require_once $gfcommon.'include/FFError.class.php';
require_once $gfcommon.'tracker/ArtifactExtraFieldElement.class.php';
require_once $gfcommon.'tracker/ArtifactStorage.class.php';
+require_once $gfcommon.'tracker/EffortUnitSet.class.php';
require_once $gfcommon.'include/MonitorElement.class.php';
/**
@@ -249,9 +250,10 @@ class ArtifactType extends FFError {
status_timeout,
submit_instructions,
browse_instructions,
- datatype)
+ datatype,
+ unit_set_id)
VALUES
- ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)',
+ ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)',
array($this->Group->getID(),
htmlspecialchars($name),
htmlspecialchars($description),
@@ -261,7 +263,9 @@ class ArtifactType extends FFError {
1209600,
htmlspecialchars($submit_instructions),
htmlspecialchars($browse_instructions),
- $datatype));
+ $datatype,
+
$this->Group->getEffortUnitSet()
+ ));
$id = db_insertid($res, 'artifact_group_list',
'group_artifact_id');
@@ -746,20 +750,8 @@ class ArtifactType extends FFError {
* @param array $id_mappings array mapping between
template objects and new project objects
* @return boolean true/false on success
*/
- function cloneFieldsFrom($clone_tracker_id, $group_id = null,
$id_mappings = array()) {
- if ($group_id) {
- $g = group_get_object($group_id);
- } else {
- $g =
group_get_object(forge_get_config('template_group'));
- }
- if (!$g || !is_object($g)) {
- $this->setError(_('Could Not Get Template Group'));
- return false;
- } elseif ($g->isError()) {
- $this->setError(_('Template Group Error').'
'.$g->getErrorMessage());
- return false;
- }
- $at = new ArtifactType($g,$clone_tracker_id);
+ function cloneFieldsFrom($clone_tracker_id, $id_mappings = array()) {
+ $at = artifactType_get_object($clone_tracker_id);
if (!$at || !is_object($at)) {
$this->setError(_('Could Not Get Tracker To Clone'));
return false;
@@ -767,6 +759,99 @@ class ArtifactType extends FFError {
$this->setError(_('Clone Tracker Error').'
'.$at->getErrorMessage());
return false;
}
+
+ // Effort Unit Set
+ $ef_effort =
$at->getExtraFields(array(ARTIFACT_EXTRAFIELDTYPE_EFFORT));
+ if (!empty($ef_effort)) {
+ $eus = new EffortUnitSet($at, $at->getEffortUnitSet());
+ $this_eus = new EffortUnitSet($this,
$this->getEffortUnitSet());
+ switch ($eus->getLevel()) {
+ case EFFORTUNITSET_FORGE_LEVEL:
+ switch ($this_eus->getLevel()) {
+ case
EFFORTUNITSET_PROJECT_LEVEL:
+ if
(!$this_eus->isEquivalentTo($eus)) {
+ // make a copy
at the tracker level
+ $new_eus = new
EffortUnitSet($this);
+
$new_eus->copy($eus);
+
$this->setEffortUnitSet($new_eus->getID());
+ }
+ break;
+ case
EFFORTUNITSET_TRACKER_LEVEL:
+ if
(!$this_eus->isEquivalentTo($eus)) {
+
$this->setError(_('Clone Tracker Error')._(':').' '._('Effort Unit Set already
define and not compatible'));
+ return false;
+ }
+ break;
+ }
+ break;
+ case EFFORTUNITSET_PROJECT_LEVEL:
+ switch ($this_eus->getLevel()) {
+ case EFFORTUNITSET_FORGE_LEVEL:
+ $new_eus_id =
getEffortUnitSetForLevel($this, EFFORTUNITSET_PROJECT_LEVEL);
+ if ($new_eus_id) {
+ $new_eus = new
EffortUnitSet($this, $new_eus_id);
+ if
(!$new_eus->isEquivalentTo($eus)) {
+
$this->setEffortUnitSet($new_eus->getID());
+ } else {
+ // make
a copy at the tracker level
+
$new_eus = new EffortUnitSet($this);
+
$new_eus->copy($eus);
+
$this->setEffortUnitSet($new_eus->getID());
+ }
+ } else {
+ // make a copy
at the project level
+ $new_eus = new
EffortUnitSet($this->Group);
+
$new_eus->copy($eus);
+
$this->setEffortUnitSet($new_eus->getID());
+ }
+ break;
+ case
EFFORTUNITSET_PROJECT_LEVEL:
+ if
(!$this_eus->isEquivalentTo($eus)) {
+ // make a copy
at the tracker level
+ $new_eus = new
EffortUnitSet($this);
+
$new_eus->copy($eus);
+
$this->setEffortUnitSet($new_eus->getID());
+ }
+ break;
+ case
EFFORTUNITSET_TRACKER_LEVEL:
+ if
(!$this_eus->isEquivalentTo($eus)) {
+
$this->setError(_('Clone Tracker Error')._(':').' '._('Effort Unit Set already
define and not compatible'));
+ return false;
+ }
+ break;
+ }
+ break;
+ case EFFORTUNITSET_TRACKER_LEVEL:
+ switch ($this_eus->getLevel()) {
+ case EFFORTUNITSET_FORGE_LEVEL:
+ case
EFFORTUNITSET_PROJECT_LEVEL:
+ $new_eus_id =
getEffortUnitSetForLevel($this, EFFORTUNITSET_TRACKER_LEVEL);
+ if ($new_eus_id) {
+ $new_eus = new
EffortUnitSet($this, $new_eus_id);
+ if
(!$new_eus->isEquivalentTo($eus)) {
+
$this->setEffortUnitSet($new_eus->getID());
+ } else {
+
$this->setError(_('Clone Tracker Error')._(':').' '._('Effort Unit Set already
define and not compatible'));
+ return
false;
+ }
+ } else {
+ // make a copy
at the tracker level
+ $new_eus = new
EffortUnitSet($this);
+
$new_eus->copy($eus);
+
$this->setEffortUnitSet($new_eus->getID());
+ }
+ break;
+ case
EFFORTUNITSET_TRACKER_LEVEL:
+ if
(!$this_eus->isEquivalentTo($eus)) {
+
$this->setError(_('Clone Tracker Error')._(':').' '._('Effort Unit Set already
define and not compatible'));
+ return false;
+ }
+ break;
+ }
+ break;
+ }
+ }
+
// do not filter and get disabled fields as well
$efs = $at->getExtraFields(array(), true);
diff --git a/src/common/tracker/EffortUnit.class.php
b/src/common/tracker/EffortUnit.class.php
index 3556a4a..637852d 100644
--- a/src/common/tracker/EffortUnit.class.php
+++ b/src/common/tracker/EffortUnit.class.php
@@ -25,21 +25,22 @@ require_once $gfcommon.'tracker/EffortUnitSet.class.php';
class EffortUnit extends FFError {
+ /**
+ * @var EffortUnitSet $EffortUnitSet Effort unit set to which the
unit belongs.
+ */
+ private $EffortUnitSet;
- var $EffortUnitSet;
/**
- * Associative array of data from db.
- *
- * @var array $data_array.
+ * @var array $data_array Associative array of data from db.
*/
- var $data_array;
+ private $data_array;
- var $level;
/**
* EffortUnit - EffortUnit object constructor
*
- * @param int|bool $id Required - Id of the Effort
Unit you want to instantiate.
- * @param int|bool $res Database result from select
query OR associative array of all columns.
+ * @param EffortUnitSet $EffortUnitSet Required - Effort Unit
Set.
+ * @param integer|boolean $id Required - Id of the Effort
Unit you want to instantiate.
+ * @param integer|boolean $res Database result from select
query OR associative array of all columns.
*/
function __construct(&$EffortUnitSet, $id = false, $res = false) {
parent::__construct();
@@ -78,8 +79,8 @@ class EffortUnit extends FFError {
/**
* fetchData - May need to refresh database fields if an update
occurred.
*
- * @param int $unit_id The unit_id.
- * @return bool success or not
+ * @param integer $unit_id The unit_id.
+ * @return boolean success or not
*/
function fetchData($unit_id) {
$res = db_query_params ('SELECT * FROM effort_unit WHERE
unit_id=$1',
@@ -98,7 +99,7 @@ class EffortUnit extends FFError {
* @param string $name The name of the
unit.
* @param integer $conversion_factor The conversion factor
to define the current unit.
* @param integer $to_unit The unity used
for the definition of the current unit.
- * @param integre $unit_position The position of the
unit when listed.
+ * @param integer $unit_position The position of the
unit when listed.
* @param boolean $is_base_unit True if this unit is a
base unit.
* @param array $importData For import
* @return bool success or not
@@ -200,6 +201,11 @@ class EffortUnit extends FFError {
return $this->data_array['to_unit'];
}
+ /**
+ * getToUnitName - get unit name use to define this unit.
+ *
+ * @return string unit name use to define this unit.
+ */
function getToUnitName() {
if (!empty($this->data_array['to_unit'])) {
$toUnit = new EffortUnit($this->EffortUnitSet,
$this->data_array['to_unit']);
@@ -209,9 +215,9 @@ class EffortUnit extends FFError {
}
}
/**
- * getMultiplier - get this unit base multiplier.
+ * getConversionFactor - get conversion factor that define this unit .
*
- * @return integer unit base multiplier.
+ * @return integer conversion factor.
*/
function getConversionFactor() {
return $this->data_array['conversion_factor'];
@@ -226,6 +232,11 @@ class EffortUnit extends FFError {
return $this->data_array['unit_position'];
}
+ /**
+ * getEffortUnitSet - get Effort Unit Set of this unit.
+ *
+ * @return EffortUnitSet Effort Unit Set.
+ */
function &getEffortUnitSet(){
return $this->EffortUnitSet;
}
@@ -239,10 +250,21 @@ class EffortUnit extends FFError {
return ($this->data_array['is_deleted']?true:false);
}
+ /**
+ * isBaseUnit - this Effort Unit is or not the base unit.
+ *
+ * @return boolean is or not base unit.
+ */
function isBaseUnit() {
return ($this->data_array['is_base_unit']?true:false);
}
+ /**
+ * delete - delete this Effort Unit.
+ * @param array $importData For import
+ *
+ * @return boolean success or not.
+ */
function delete($importData = array()) {
db_begin();
if(array_key_exists('user', $importData)){
@@ -304,6 +326,15 @@ class EffortUnit extends FFError {
return true;
}
+ /**
+ * update - update this Effort Unit, name or definition.
+ * @param string $name The name of the
unit.
+ * @param integer $conversion_factor The conversion factor
to define the current unit.
+ * @param integer $to_unit The unity used
for the definition of the current unit.
+ * @param array $importData For import
+ *
+ * @return boolean success or not.
+ */
function update($name, $conversion_factor, $to_unit, $importData =
array()){
if (!ctype_digit(strval($conversion_factor)) ||
$conversion_factor<1) {
$this->setError(_('Conversion factor must be an integer
greater or equal to 1'));
@@ -397,8 +428,13 @@ class EffortUnit extends FFError {
return true;
}
+ /**
+ * updatePosition - Update this Effort Unit dispaly position.
+ * @param integer $unit_position new position
+ *
+ * @return boolean success or not.
+ */
function updatePosition($unit_position) {
-
$result=db_query_params ('UPDATE effort_unit SET unit_position=
$1 WHERE unit_id=$2',
array($unit_position, $this->getID()));
if ($result && db_affected_rows($result) > 0) {
@@ -410,6 +446,12 @@ class EffortUnit extends FFError {
}
}
+ /**
+ * reorderUnits - Reorder all units.
+ * @param integer $new_position new position of this unit
+ *
+ * @return boolean success or not.
+ */
function reorderUnits($new_position) {
$unitFactory = new EffortUnitFactory($this->EffortUnitSet);
$unitsData = $unitFactory->getUnitsData();
@@ -442,7 +484,14 @@ class EffortUnit extends FFError {
return true;
}
+ /**
+ * copy - copy definition from an other unit.
+ * @param EffortUnit $from_unit Unit to be copied
+ *
+ * @return boolean success or not.
+ */
function copy($from_unit) {
+ db_begin();
$name = $from_unit->getName();
$conversion_factor = $from_unit->getConversionFactor();
$position = $from_unit->getPosition();
@@ -455,9 +504,59 @@ class EffortUnit extends FFError {
$to_unit_id = 1;
}
$id = $this->create($name, $conversion_factor, $to_unit_id,
$position, $is_base_unit);
+ if ($id) {
+ // Update artifacts data
+ $res = db_query_params('WITH t AS (
+
SELECT data_id
+
FROM artifact_extra_field_data
+
INNER JOIN artifact_extra_field_list USING (extra_field_id)
+
INNER JOIN artifact_group_list USING (group_artifact_id)
+
WHERE
+
field_type = $1 AND
+
field_data like $2 AND
+
unit_set_id = $3
+
)
+ UPDATE
artifact_extra_field_data AS d
+ SET
field_data = CAST(SUBSTRING(field_data FROM \'#"%#"U%\' FOR \'#\') AS INTEGER)
|| \'U\' || $4
+ FROM t
+ WHERE
d.data_id = t.data_id',
+
array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$from_unit->getID(),
$from_unit->getEffortUnitSet()->getID(), $id));
+ if (!$res) {
+ $this->setError(_('Error coping Effort
Unit')._(': ').db_error());
+ db_rollback();
+ return false;
+ }
+ // Update default values
+ $res = db_query_params('WITH t AS (
+
SELECT default_id
+
FROM artifact_extra_field_default
+
INNER JOIN artifact_extra_field_list USING (extra_field_id)
+
INNER JOIN artifact_group_list USING (group_artifact_id)
+
WHERE
+
field_type = $1 AND
+
default_value like $2 AND
+
unit_set_id = $3
+
)
+ UPDATE
artifact_extra_field_default AS d
+ SET
default_value = CAST(SUBSTRING(default_value FROM \'#"%#"U%\' FOR \'#\') AS
INTEGER) || \'U\' || $4
+ FROM t
+ WHERE
d.default_id = t.default_id',
+
array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$from_unit->getID(),
$from_unit->getEffortUnitSet()->getID(), $id));
+ if (!$res) {
+ $this->setError(_('Error')._(':').' '._('Cannot
update Effort Unit (default value update)')._(':').' '.db_error());
+ db_rollback();
+ return false;
+ }
+ }
+ db_commit();
return $id;
}
+ /**
+ * getConversionFactorForBaseUnit - get conversion factor for Base Unit.
+ *
+ * @return integer conversion factor.
+ */
function getConversionFactorForBaseUnit() {
$factor = $this->getConversionFactor();
$toUnitId = $this->getToUnit();
@@ -468,6 +567,11 @@ class EffortUnit extends FFError {
return $factor;
}
+ /**
+ * getUnitsDependingOn - get array of units depending on this unit.
+ *
+ * @return array array of EffortUnit depending on this unit.
+ */
function getUnitsDependingOn(){
$unitsDependingOn = array();
$effortUnitFactory = new
EffortUnitFactory($this->EffortUnitSet);
@@ -480,4 +584,28 @@ class EffortUnit extends FFError {
}
return $unitsDependingOn;
}
+
+ /**
+ * isEquivalentTo - test if this unit is equivalent to the other.
+ * @param EffortUnit $effortUnit Unit to compare to
+ *
+ * @return boolean success or not.
+ */
+ function isEquivalentTo($effortUnit){
+ if ($this->getName() != $effortUnit->getName()) {
+ return false;
+ }
+ if ($this->getConversionFactor() !=
$effortUnit->getConversionFactor()) {
+ return false;
+ }
+ if ($this->isBaseUnit() && $effortUnit->isBaseUnit()) {
+ return true;
+ }
+ $thisToUnit = new EffortUnit($this->EffortUnitSet,
$this->getToUnit());
+ $toUnit = new EffortUnit($effortUnit->EffortUnitSet,
$effortUnit->getToUnit());
+ if (!$toUnit->isEquivalentTo($thisToUnit)) {
+ return false;
+ }
+ return true;
+ }
}
diff --git a/src/common/tracker/EffortUnitFactory.class.php
b/src/common/tracker/EffortUnitFactory.class.php
index 7a71a1f..882b030 100644
--- a/src/common/tracker/EffortUnitFactory.class.php
+++ b/src/common/tracker/EffortUnitFactory.class.php
@@ -27,22 +27,24 @@ require_once $gfcommon.'tracker/EffortUnit.class.php';
class EffortUnitFactory extends FFError {
/**
- * The Effort Unit Set.
- *
- * @var object Effort Unit Set.
+ * @var EffortUnitSet $EffortUnitSet Effort Unit Set of the factory.
*/
- var $EffortUnitSet;
+ private $EffortUnitSet;
/**
- * The Effort Units array.
- *
- * @var array Effort Units.
+ * @var array $Units array of EffortUnit object.
*/
- var $Units;
+ private $Units;
+ /**
+ * @var array $UnitsData array of EffortUnits data.
+ */
var $UnitsData;
+
/**
- * @param Object $EffortUnitSet The Effort Unit Set object to
which this EffortUnitFactory is associated.
+ * EffortUnitFactory - EffortUnitFactory object constructor
+ *
+ * @param EffortUnitSet $EffortUnitSet The Effort Unit Set
object to which this EffortUnitFactory is associated.
*/
function __construct(&$EffortUnitSet) {
parent::__construct();
@@ -124,6 +126,11 @@ class EffortUnitFactory extends FFError {
return $result ;
}
+ /**
+ * getBaseUnit - return the base EffortUnit object.
+ *
+ * @return EffortUnit the base EffortUnit object.
+ */
function getBaseUnit() {
$units = $this->getUnits();
foreach($units as $unit) {
@@ -134,6 +141,12 @@ class EffortUnitFactory extends FFError {
return false;
}
+ /**
+ * getUnitByName - get a EffortUnit object by name.
+ *
+ * @param string $name the name of the EffortUnit
+ * @return EffortUnit the base EffortUnit object.
+ */
function getUnitByName($name) {
$units = $this->getUnits();
foreach($units as $unit) {
@@ -144,6 +157,12 @@ class EffortUnitFactory extends FFError {
return false;
}
+ /**
+ * encodedToValue - return the value of an effort expressed in encoded
unit.
+ *
+ * @param string $encoded encoded effort
+ * @return integer the value of an effort expressed in encoded
unit.
+ */
function encodedToValue($encoded){
$value = 0;
if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
@@ -153,6 +172,12 @@ class EffortUnitFactory extends FFError {
return $value;
}
+ /**
+ * encodedToValueInBaseUnit - return the value of an effort expressed
in base unit.
+ *
+ * @param string $encoded encoded effort
+ * @return integer the value of an effort expressed in base unit.
+ */
function encodedToValueInBaseUnit($encoded){
$value = 0;
if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
@@ -161,6 +186,12 @@ class EffortUnitFactory extends FFError {
return $value;
}
+ /**
+ * encodedToUnitId - return the unit id of an encoded effort.
+ *
+ * @param string $encoded encoded effort
+ * @return integer the unit id of an encoded effort.
+ */
function encodedToUnitId($encoded) {
if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
$unitId = intval($matches[2]);
@@ -172,6 +203,12 @@ class EffortUnitFactory extends FFError {
return $unitId;
}
+ /**
+ * encodedToUnitName - return the unit name of an encoded effort.
+ *
+ * @param string $encoded encoded effort
+ * @return string the unit name of an encoded effort.
+ */
function encodedToUnitName($encoded) {
$units = $this->getUnitsArr();
if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
@@ -182,6 +219,12 @@ class EffortUnitFactory extends FFError {
return $unitName;
}
+ /**
+ * encodedToString - return the value and the unit name of an encoded
effort.
+ *
+ * @param string $encoded encoded effort
+ * @return string the value and the unit name of an encoded
effort.
+ */
function encodedToString($encoded) {
if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
$unit = new EffortUnit($this->EffortUnitSet,
$matches[2]);
diff --git a/src/common/tracker/EffortUnitSet.class.php
b/src/common/tracker/EffortUnitSet.class.php
index cf60fb3..a84abd9 100644
--- a/src/common/tracker/EffortUnitSet.class.php
+++ b/src/common/tracker/EffortUnitSet.class.php
@@ -28,26 +28,35 @@ define('EFFORTUNITSET_PROJECT_LEVEL', 2);
define('EFFORTUNITSET_TRACKER_LEVEL', 3);
class EffortUnitSet extends FFError {
- var $Object;
+
/**
- * The Group object.
- *
- * @var object $Group.
+ * @var null|Group|ArtifactType $Object The object associated
to this Effort Unit Set.
*/
- var $Group;
+ private $Object;
/**
- * Artifact Type object.
- *
- * @var object $ArtifactType.
+ * @var Group $Group The ArtifactType's group or the group
associated to this Effort Unit Set
+ */
+ private $Group;
+
+ /**
+ * @var ArtifactType $ArtifactType The ArtifactType associated to
this Effort Unit Set
*/
- var $ArtifactType;
+ private $ArtifactType;
- var $data_array;
+ /**
+ * @var array $data_array Associative array of data from db.
+ */
+ private $data_array;
- var $objectLevel;
+ /**
+ * @var integer $objectLevel The level (forge/projet/tracker) of the
object $Object.
+ */
+ private $objectLevel;
/**
+ * EffortUnitSet - EffortUnitSet object constructor
+ *
* @param Object $Object Null, group, tracker object to which
this EffortUnitSet is associated
*/
function __construct(&$Object=null, $unit_set_id=false, $arr=false) {
@@ -104,6 +113,12 @@ class EffortUnitSet extends FFError {
return;
}
+ /**
+ * create - Create new Effort Unit Set in the database.
+ *
+ * @param array $importData For import
+ * @return bool success or not
+ */
function create($importData = array()) {
if(array_key_exists('user', $importData)){
$user = $importData['user'];
@@ -118,32 +133,28 @@ class EffortUnitSet extends FFError {
// Only Effort Unit Set of the object level can be created as a
new one
switch ($this->objectLevel){
case EFFORTUNITSET_TRACKER_LEVEL:
- $res = db_query_params('SELECT 1 FROM
effort_unit_set WHERE group_id=$1 AND group_artifact_id=$2',
- array($this->Group->getID(),
$this->ArtifactType->getID()));
+ $res = db_query_params('SELECT 1 FROM
effort_unit_set WHERE group_id=$1 AND group_artifact_id=$2 AND level=$3',
+ array($this->Group->getID(),
$this->ArtifactType->getID(), EFFORTUNITSET_TRACKER_LEVEL));
if (!$res) {
$this->setError(_('Error checking if
Effort Unit Set already exist')._(':').' '.db_error());
- db_rollback();
return false;
}
if (db_numrows($res)>0) {
$this->setError(sprintf(_('Effort Unit
Set already exist for tracker %s'),$this->ArtifactType->getName()));
- db_rollback();
return false;
}
$query ='INSERT INTO effort_unit_set(level,
group_id, group_artifact_id, created_date, created_by) VALUES($1, $2, $3, $4,
$5)';
$params = array(EFFORTUNITSET_TRACKER_LEVEL,
$this->Group->getID(), $this->ArtifactType->getID(), $time, $user);
break;
case EFFORTUNITSET_PROJECT_LEVEL:
- $res = db_query_params('SELECT 1 FROM
effort_unit_set WHERE group_id=$1',
- array($this->Group->getID()));
+ $res = db_query_params('SELECT 1 FROM
effort_unit_set WHERE group_id=$1 AND group_artifact_id IS NULL AND level=$2',
+ array($this->Group->getID(),
EFFORTUNITSET_PROJECT_LEVEL));
if (!$res) {
$this->setError(_('Error checking if
Effort Unit Set already exist')._(':').' '.db_error());
- db_rollback();
return false;
}
if (db_numrows($res)>0) {
$this->setError(sprintf(_('Effort Unit
Set already exist for project %s'),$this->Group->getPublicName()));
- db_rollback();
return false;
}
$query ='INSERT INTO effort_unit_set(level,
group_id, created_date, created_by) VALUES($1, $2, $3, $4)';
@@ -172,29 +183,76 @@ class EffortUnitSet extends FFError {
}
}
+ /**
+ * copy - Copy new Effort Unit Set from an other Effort Unit Set.
+ *
+ * @param EffortUnitSet $from_unit_set Effort Unit Set to be
copied
+ * @return bool success or not
+ */
function copy($from_unit_set){
db_begin();
$unit_set_id = $this->create();
+ if (!$unit_set_id) {
+ db_rollback();
+ return false;
+ }
$from_unit_factory = new EffortUnitFactory($from_unit_set);
$from_baseUnit = $from_unit_factory->getBaseUnit();
- if (!$this->_recursive_copy($from_baseUnit)) {
+ if (!$this->recursiveUnitCopy($from_baseUnit)) {
db_rollback();
return false;
}
switch ($this->objectLevel) {
case EFFORTUNITSET_PROJECT_LEVEL:
- $this->Group->setEffortUnitSet($this->getID());
+ if
(!$this->Group->setEffortUnitSet($this->getID())) {
+ $this->setError(_('Error setting new
effort unit set for the group')._(':').' '.$this->Group->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ $atf = new ArtifactTypeFactory($this->Group);
+ if (!$atf) {
+ $this->setError(_('Error on new
ArtifactTypeFactory'));
+ db_rollback();
+ return false;
+ }
+ if ($atf->isError()) {
+ $this->setError(_('Error on new
ArtifactTypeFactory')._(':').' '.$atf->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ $ats = $atf->getArtifactTypes();
+ if (!empty($ats) && is_array($ats)) {
+ foreach ($ats as $at) {
+ if ($at->getEffortUnitSet() ==
$from_unit_set->getID()) {
+ if
(!$at->setEffortUnitSet($unit_set_id)) {
+
$this->setError(_('Error on updating artifact type')._(':').'
'.$at->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ }
+ }
+ }
break;
case EFFORTUNITSET_TRACKER_LEVEL:
-
$this->ArtifactType->setEffortUnitSet($this->getID());
+ if
(!$this->ArtifactType->setEffortUnitSet($unit_set_id)) {
+ $this->setError(_('Error setting new
effort unit set for the artifact type')._(':').'
'.$this->ArtifactType->getErrorMessage());
+ db_rollback();
+ return false;
+ }
break;
}
db_commit();
return true;
}
- function _recursive_copy($from_unit) {
+ /**
+ * recursiveUnitCopy - Copy Effort Unit Set and units depending on.
+ *
+ * @param EffortUnit $from_unit Effort Unit to be copied
+ * @return bool success or not
+ */
+ private function recursiveUnitCopy($from_unit) {
db_begin();
$new_unit = new EffortUnit($this);
if (!$new_unit) {
@@ -208,33 +266,12 @@ class EffortUnitSet extends FFError {
db_rollback();
return false;
}
- // Update artifacts data
- $res = db_query_params('WITH t AS (
- SELECT
data_id
-
FROM artifact_extra_field_data
-
INNER JOIN artifact_extra_field_list USING (extra_field_id)
-
INNER JOIN artifact_group_list USING (group_artifact_id)
- WHERE
-
field_type = $1 AND
-
field_data like $2 AND
-
unit_set_id = $3
- )
- UPDATE
artifact_extra_field_data AS d
- SET field_data
= CAST(SUBSTRING(field_data FROM \'#"%#"U%\' FOR \'#\') AS INTEGER) || \'U\' ||
$4
- FROM t
- WHERE d.data_id
= t.data_id',
-
array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$from_unit->getID(),
$from_unit->getEffortUnitSet()->getID(), $new_unit_id));
- if (!$res) {
- $this->setError(_('Error coping Effort Unit')._(':
').db_error());
- db_rollback();
- return false;
- }
$from_unit_set = $from_unit->getEffortUnitSet();
$from_unit_factory = new EffortUnitFactory($from_unit_set);
$units = $from_unit_factory->getUnits();
foreach ($units as $unit) {
if ($unit->getToUnit()==$from_unit->getID() &&
$unit->getID()!=$from_unit->getID()) {
- if (!$this->_recursive_copy($unit)) {
+ if (!$this->recursiveUnitCopy($unit)) {
db_rollback();
return false;
}
@@ -247,7 +284,7 @@ class EffortUnitSet extends FFError {
/**
* fetchData - May need to refresh database fields if an update
occurred.
*
- * @param int $group_id The group_id.
+ * @param integer $group_id The group_id.
* @return bool success or not
*/
function fetchData($unit_set_id) {
@@ -264,38 +301,97 @@ class EffortUnitSet extends FFError {
/**
* getID - Simply return the unit_set_id for this object.
*
- * @return int unit_set_id.
+ * @return integer unit_set_id.
*/
function getID() {
return $this->data_array['unit_set_id'];
}
+ /**
+ * getLevel - return the level (forge/projet/tracker) at which the set
is defined.
+ *
+ * @return integer level.
+ */
function getLevel() {
return $this->data_array['level'];
}
+ /**
+ * getObjectLevel - return the level of the object used.
+ *
+ * @return integer objectLevel.
+ */
function getObjectLevel() {
return $this->objectLevel;
}
/**
- * getGroup - get the Group object this EffortUnitFactory is associated
with.
+ * getGroup - get the Group object this EffortUnitSet is associated
with.
*
- * @return object The Group object.
+ * @return Group The Group object.
*/
function &getGroup() {
return $this->Group;
}
+ /**
+ * getArtifactType - get the ArtifactType object this EffortUnitSet is
associated with.
+ *
+ * @return ArtifactType The ArtifactType object.
+ */
function &getArtifactType() {
return $this->ArtifactType;
}
+ /**
+ * getObject - get the Object this EffortUnitSet is associated with.
+ *
+ * @return null|Group|ArtifactType The Object.
+ */
function &getObject() {
return $this->Object;
}
+
+ /**
+ * isEquivalentTo - test if this unit set is equivalent to the other.
+ * @param EffortUnitSet $effortUnitSet Unit set to test
+ *
+ * @return boolean true/false.
+ */
+ function isEquivalentTo($effortUnitSet){
+ if ($this->getID() == $effortUnitSet->getID()) {
+ return true;
+ }
+ $thisEffortUnitFactory = new EffortUnitFactory($this);
+ $effortUnitFactory = new EffortUnitFactory($effortUnitSet);
+ if (count($thisEffortUnitFactory)==count($effortUnitFactory)) {
+ $thisUnits = $thisEffortUnitFactory->getUnits();
+ $units = $effortUnitFactory->getUnits();
+ foreach ($thisUnits as $thisUnit) {
+ $found = false;
+ foreach ($units as $unit) {
+ if ($thisUnit->isEquivalentTo($unit)) {
+ $found=true;
+ break;
+ }
+ }
+ if (!$found) {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ return true;
+ }
}
+/**
+ * getAvailableEffortUnitSets - Get list of EffortUnitSets available for the
object.
+ * @param null|Group|ArtifactType $Object Object
+ *
+ * @return array list of EffortUnitSets.
+ */
function getAvailableEffortUnitSets(&$Object=null) {
if (!$Object) {
$class ='';
@@ -307,28 +403,25 @@ function getAvailableEffortUnitSets(&$Object=null) {
case 'ArtifactTypeHtml':
if (!$Object || !is_object($Object)) {
$this->setError(_('Invalid Artifact Type'));
- return;
+ return false;
}
if ($Object->isError()) {
$this->setError(_('Effort Unit Set')._(':').'
'.$Object->getErrorMessage());
- return;
+ return false;
}
- $atid = $Object->getID();
$at_name = $Object->getName();
- $group_id = $Object->getGroup()->getID();
$group_name = $Object->getGroup()->getPublicName();
$objectLevel = EFFORTUNITSET_TRACKER_LEVEL;
break;
case 'Group':
if (!$Object || !is_object($Object)) {
$this->setError(_('Invalid Project'));
- return;
+ return false;
}
if ($Object->isError()) {
$this->setError(_('Effort Unit Set')._(':').'
'.$Object->getErrorMessage());
- return;
+ return false;
}
- $group_id = $Object->getID();
$group_name = $Object->getPublicName();
$objectLevel = EFFORTUNITSET_PROJECT_LEVEL;
break;
@@ -339,40 +432,119 @@ function getAvailableEffortUnitSets(&$Object=null) {
$effortUnitSets = array();
switch($objectLevel) {
case EFFORTUNITSET_TRACKER_LEVEL:
+ $id =
getEffortUnitSetForLevel($Object,EFFORTUNITSET_TRACKER_LEVEL);
+ if ($id) {
+ $effortUnitSets[$id] = sprintf(_('Tracker "%s"
level Effort Unit Set'),$at_name);
+ }
+ // no break
+ case EFFORTUNITSET_PROJECT_LEVEL:
+ $id =
getEffortUnitSetForLevel($Object,EFFORTUNITSET_PROJECT_LEVEL);
+ if ($id) {
+ $effortUnitSets[$id] = sprintf(_('Project "%s"
level Effort Unit Set'),$group_name);
+ }
+ // no break
+ case EFFORTUNITSET_FORGE_LEVEL:
+ $id =
getEffortUnitSetForLevel($Object,EFFORTUNITSET_FORGE_LEVEL);
+ if ($id) {
+ $effortUnitSets[$id] = _('Forge level Effort
Unit Set');
+ }
+ }
+ return $effortUnitSets;
+}
+
+/**
+ * getAvailableEffortUnitSets - Get EffortUnitSet ID available for the object
at this level.
+ * @param null|Group|ArtifactType $Object Object
+ * @param integer $level level
+ *
+ * @return integer EffortUnitSet ID.
+ */
+function getEffortUnitSetForLevel(&$Object,$level) {
+ if (!$Object) {
+ $class ='';
+ } else {
+ $class = get_class($Object);
+ }
+ switch ($class) {
+ case 'ArtifactType':
+ case 'ArtifactTypeHtml':
+ if (!$Object || !is_object($Object)) {
+ $this->setError(_('Invalid Artifact Type'));
+ return false;
+ }
+ if ($Object->isError()) {
+ $this->setError(_('Effort Unit Set')._(':').'
'.$Object->getErrorMessage());
+ return false;
+ }
+ $atid = $Object->getID();
+ $at_name = $Object->getName();
+ $group_id = $Object->getGroup()->getID();
+ $group_name = $Object->getGroup()->getPublicName();
+ break;
+ case 'Group':
+ if (!$Object || !is_object($Object)) {
+ $this->setError(_('Invalid Project'));
+ return false;
+ }
+ if ($Object->isError()) {
+ $this->setError(_('Effort Unit Set')._(':').'
'.$Object->getErrorMessage());
+ return false;
+ }
+ $group_id = $Object->getID();
+ $group_name = $Object->getPublicName();
+ if ($level<EFFORTUNITSET_PROJECT_LEVEL) {
+ return false;
+ }
+ break;
+ case '':
+ if ($level<EFFORTUNITSET_FORGE_LEVEL) {
+ return false;
+ }
+ break;
+ }
+ switch($level) {
+ case EFFORTUNITSET_TRACKER_LEVEL:
$res = db_query_params ('SELECT unit_set_id FROM
effort_unit_set WHERE group_id=$1 AND group_artifact_id=$2 AND level=$3',
- array($group_id, $atid,
EFFORTUNITSET_TRACKER_LEVEL));
+ array($group_id, $atid, EFFORTUNITSET_TRACKER_LEVEL));
if (!$res) {
$this->setError(sprintf(_('Error getting
Tracker "%s" level Effort Unit Set'),$at_name), db_error());
return false;
}
if (db_numrows($res)>0) {
$row = db_fetch_array($res);
- $effortUnitSets[$row['unit_set_id']]=
sprintf(_('Tracker "%s" level Effort Unit Set'),$at_name);
+ return $row['unit_set_id'];
+ } else {
+ return false;
}
- // no break
+ break;
case EFFORTUNITSET_PROJECT_LEVEL:
$res = db_query_params ('SELECT unit_set_id FROM
effort_unit_set WHERE group_id=$1 AND group_artifact_id IS NULL AND level=$2',
- array($group_id,
EFFORTUNITSET_PROJECT_LEVEL));
+ array($group_id, EFFORTUNITSET_PROJECT_LEVEL));
if (!$res) {
$this->setError(sprintf(_('Error getting
Project "%s" level Effort Unit Set'),$group_name), db_error());
return false;
}
if (db_numrows($res)>0) {
$row = db_fetch_array($res);
- $effortUnitSets[$row['unit_set_id']]=
sprintf(_('Project "%s" level Effort Unit Set'),$group_name);
+ return $row['unit_set_id'];
+ } else {
+ return false;
}
- // no break
+ break;
case EFFORTUNITSET_FORGE_LEVEL:
$res = db_query_params ('SELECT unit_set_id FROM
effort_unit_set WHERE group_id IS NULL AND group_artifact_id IS NULL AND
level=$1',
- array(EFFORTUNITSET_FORGE_LEVEL));
+ array(EFFORTUNITSET_FORGE_LEVEL));
if (!$res) {
$this->setError(_('Error getting Forge level
Effort Unit Set'), db_error());
return false;
}
if (db_numrows($res)>0) {
$row = db_fetch_array($res);
- $effortUnitSets[$row['unit_set_id']]= _('Forge
level Effort Unit Set');
+ return $row['unit_set_id'];
+ } else {
+ return false;
}
+ break;
}
- return $effortUnitSets;
+ return false;
}
diff --git a/src/common/tracker/actions/effort_units.php
b/src/common/tracker/actions/effort_units.php
index d4c8085..1e4a25d 100644
--- a/src/common/tracker/actions/effort_units.php
+++ b/src/common/tracker/actions/effort_units.php
@@ -503,6 +503,14 @@ function postcopy_set(&$effortUnitSet) {
}
$object = $effortUnitSet->getObject();
$newEffortUnitSet = new EffortUnitSet($object);
+ if (!$newEffortUnitSet) {
+ echo $HTML->error_msg(_('Error coping Effort Unit
Set')._(':').' '._('Error on new EffortUnitSet'));
+ return false;
+ }
+ if ($newEffortUnitSet->isError()) {
+ echo $HTML->error_msg(_('Error coping Effort Unit
Set')._(':').' '._('Error on new EffortUnitSet').'
'.$newEffortUnitSet->getErrorMessage());
+ return false;
+ }
if (!$newEffortUnitSet->copy($effortUnitSet)) {
echo $HTML->error_msg(_('Error coping Effort Unit
Set')._(':').' '.$newEffortUnitSet->getErrorMessage());
return false;
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=fd9f2a6d7198c0daa25298bc16c2df73374b3678
commit fd9f2a6d7198c0daa25298bc16c2df73374b3678
Author: Stéphane-Eymeric Bredthauer <[email protected]>
Date: Mon Jan 23 10:40:44 2017 +0100
sync CHANGES
diff --git a/src/CHANGES b/src/CHANGES
index 35895be..62f1d6c 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -29,7 +29,7 @@ FusionForge 6.X:
* Taskboard: support multiple taskboards per project [#785] (TrivialDev)
* Taskboard: support filtering tasks [#786] (TrivialDev)
* Tracker: keep values in artifact new submit form on error. (TrivialDev)
-* Tracker: add new customfield: text regex (TrivialDev)
+* Tracker: add new customfield parameter: text regex (TrivialDev)
* Tracker: add new customfield: User (TrivialDev)
* Tracker: add new customfield: DateTime (TrivialDev)
* Tracker: add new customfield: Release (TrivialDev)
-----------------------------------------------------------------------
Summary of changes:
src/common/include/Group.class.php | 2 +-
src/common/tracker/ArtifactType.class.php | 119 ++++++++--
src/common/tracker/EffortUnit.class.php | 156 +++++++++++--
src/common/tracker/EffortUnitFactory.class.php | 61 ++++-
src/common/tracker/EffortUnitSet.class.php | 302 +++++++++++++++++++------
src/common/tracker/actions/effort_units.php | 8 +
6 files changed, 542 insertions(+), 106 deletions(-)
hooks/post-receive
--
FusionForge
_______________________________________________
Fusionforge-commits mailing list
[email protected]
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits