소스 검색

Fixed bug in the history of tickets (incident or any other type, for which the name is based on the ticket ID, which remained undetermined until the record is created)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@142 a333f486-631f-4898-b8df-5754b55c2be0
romainq 16 년 전
부모
커밋
b793bf98e2
5개의 변경된 파일38개의 추가작업 그리고 21개의 파일을 삭제
  1. 6 7
      business/ChangeMgmt.business.php
  2. 6 7
      business/ServiceDesk.business.php
  3. 6 7
      business/incidentMgmt.business.php
  4. 12 0
      core/cmdbsource.class.inc.php
  5. 8 0
      core/metamodel.class.php

+ 6 - 7
business/ChangeMgmt.business.php

@@ -180,16 +180,15 @@ class bizChangeTicket extends cmdbAbstractObject
 		return true;
 	}
 
-	public function ComputeFields()
+	public function ComputeValues()
 	{
-		if ($this->GetKey() > 0)
+		$iKey = $this->GetKey();
+		if ($iKey < 0)
 		{
-			$sName = sprintf('C-%06d', $this->GetKey());
-		}
-		else
-		{
-			$sName = "Id not set";
+			// Object not yet in the Database
+			$iKey = MetaModel::GetNextKey(get_class($this));
 		}
+		$sName = sprintf('C-%06d', $iKey);
 		$this->Set('name', $sName);
 	}
 }

+ 6 - 7
business/ServiceDesk.business.php

@@ -144,16 +144,15 @@ class bizServiceCall extends cmdbAbstractObject
 		return true;
 	}
 	
-	public function ComputeFields()
+	public function ComputeValues()
 	{
-		if ($this->GetKey() > 0)
+		$iKey = $this->GetKey();
+		if ($iKey < 0)
 		{
-			$sName = sprintf('I-%06d', $this->GetKey());
-		}
-		else
-		{
-			$sName = "Id not set";
+			// Object not yet in the Database
+			$iKey = MetaModel::GetNextKey(get_class($this));
 		}
+		$sName = sprintf('S-%06d', $iKey);
 		$this->Set('name', $sName);
 	}
 }

+ 6 - 7
business/incidentMgmt.business.php

@@ -149,16 +149,15 @@ class bizIncidentTicket extends cmdbAbstractObject
 		return true;
 	}
 	
-	public function ComputeFields()
+	public function ComputeValues()
 	{
-		if ($this->GetKey() > 0)
+		$iKey = $this->GetKey();
+		if ($iKey < 0)
 		{
-			$sName = sprintf('I-%06d', $this->GetKey());
-		}
-		else
-		{
-			$sName = "Id not set";
+			// Object not yet in the Database
+			$iKey = MetaModel::GetNextKey(get_class($this));
 		}
+		$sName = sprintf('I-%06d', $iKey);
 		$this->Set('name', $sName);
 	}
 }

+ 12 - 0
core/cmdbsource.class.inc.php

@@ -185,6 +185,18 @@ class CMDBSource
 		return $result;
 	}
 
+	public static function GetNextInsertId($sTable)
+	{
+		$sSQL = "SHOW TABLE STATUS LIKE '$sTable'";
+		$result = self::Query($sSQL);
+		$aRow = mysql_fetch_assoc($result);
+		$iNextInsertId = $aRow['Auto_increment'];
+		echo "<pre>\n";
+		print_r($aRow);
+		echo "</pre>\n";
+		return $iNextInsertId;
+	}
+
 	public static function GetInsertId()
 	{
 		return mysql_insert_id(self::$m_resDBLink);

+ 8 - 0
core/metamodel.class.php

@@ -2642,6 +2642,14 @@ abstract class MetaModel
 		return new $sClass();
 	}	
 
+	public static function GetNextKey($sClass)
+	{
+		$sRootClass = MetaModel::GetRootClass($sClass);
+		$sRootTable = MetaModel::DBGetTable($sRootClass);
+		$iNextKey = CMDBSource::GetNextInsertId($sRootTable);
+		return $iNextKey;
+	}
+
 	public static function BulkDelete(DBObjectSearch $oFilter)
 	{
 		$sSQL = self::MakeDeleteQuery($oFilter);