Bläddra i källkod

ComputeValues optimized + fix in the algo computing the priority of an Incident

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@543 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 år sedan
förälder
incheckning
3b67721d14
2 ändrade filer med 22 tillägg och 19 borttagningar
  1. 12 3
      core/dbobject.class.php
  2. 10 16
      modules/itop-tickets-1.0.0/model.itop-tickets.php

+ 12 - 3
core/dbobject.class.php

@@ -50,6 +50,10 @@ abstract class DBObject
 		{
 			$this->FromRow($aRow, $sClassAlias);
 			$this->m_bFullyLoaded = $this->IsFullyLoaded();
+			if ($this->m_bFullyLoaded)
+			{
+				$this->DoComputeValues();
+			}
 			return;
 		}
 		// Creation of brand new object
@@ -74,6 +78,7 @@ abstract class DBObject
 				$this->m_aLoadedAtt[$sAttCode] = true;
 			}
 		}
+		$this->DoComputeValues();
 	}
 
 	// Read-only <=> Written once (archive)
@@ -149,6 +154,7 @@ abstract class DBObject
 			throw new CoreException("Failed to reload object of class '".get_class($this)."', id = ".$this->m_iKey);
 		}
 		$this->FromRow($aRow);
+		$this->DoComputeValues();
 
 		// Process linked set attributes
 		//
@@ -338,7 +344,6 @@ abstract class DBObject
 			// #@# non-scalar attributes.... handle that differentely
 			$this->Reload();
 		}
-		$this->ComputeFields();
 		return $this->m_aCurrValues[$sAttCode];
 	}
 
@@ -351,7 +356,8 @@ abstract class DBObject
 		return $this->m_aOrigValues[$sAttCode];
 	}
 
-	public function ComputeFields()
+	// Compute scalar attributes that depend on any other type of attribute
+	public function DoComputeValues()
 	{
 		if (is_callable(array($this, 'ComputeValues')))
 		{
@@ -820,7 +826,7 @@ abstract class DBObject
 		$sRootClass = MetaModel::GetRootClass($sClass);
 
 		// Ensure the update of the values (we are accessing the data directly)
-		$this->ComputeFields();
+		$this->DoComputeValues();
 		$this->OnInsert();
 
 		if ($this->m_iKey < 0)
@@ -896,6 +902,9 @@ abstract class DBObject
 		{
 			throw new CoreException("DBUpdate: could not update a newly created object, please call DBInsert instead");
 		}
+
+		$this->DoComputeValues();
+
 		$aChanges = $this->ListChanges();
 		if (count($aChanges) == 0)
 		{

+ 10 - 16
modules/itop-tickets-1.0.0/model.itop-tickets.php

@@ -376,30 +376,24 @@ class Incident extends Ticket
 		$aPriorities = array(
 			// single person
 			1 => array(
-				array(
-					1 => 1,
-					2 => 1,
-					3 => 2,
-				)
+				1 => 1,
+				2 => 1,
+				3 => 2,
 			),
 			// a group
 			2 => array(
-				array(
-					1 => 1,
-					2 => 2,
-					3 => 3,
-				)
+				1 => 1,
+				2 => 2,
+				3 => 3,
 			),
 			// a departement!
 			3 => array(
-				array(
-					1 => 2,
-					2 => 3,
-					3 => 3,
-				)
+				1 => 2,
+				2 => 3,
+				3 => 3,
 			),
 		);
-		$iPriority = 1; //$aPriorities[$this->Get('impact')][$this->Get('urgency')];
+		$iPriority = $aPriorities[$this->Get('impact')][$this->Get('urgency')];
 		$this->Set('priority', $iPriority);
 		
 		// Compute the SLA deadlines