diff --git a/trunk/business/ChangeMgmt.business.php b/trunk/business/ChangeMgmt.business.php index ac59bcd8b..8ed0ead72 100644 --- a/trunk/business/ChangeMgmt.business.php +++ b/trunk/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); } } diff --git a/trunk/business/ServiceDesk.business.php b/trunk/business/ServiceDesk.business.php index 7ee9c0562..9ecd9022a 100644 --- a/trunk/business/ServiceDesk.business.php +++ b/trunk/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); } } diff --git a/trunk/business/incidentMgmt.business.php b/trunk/business/incidentMgmt.business.php index eef137790..bccc74ba8 100644 --- a/trunk/business/incidentMgmt.business.php +++ b/trunk/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); } } diff --git a/trunk/core/cmdbsource.class.inc.php b/trunk/core/cmdbsource.class.inc.php index ea06e112d..5ca68e2c3 100644 --- a/trunk/core/cmdbsource.class.inc.php +++ b/trunk/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 "
\n";
+		print_r($aRow);
+		echo "
\n"; + return $iNextInsertId; + } + public static function GetInsertId() { return mysql_insert_id(self::$m_resDBLink); diff --git a/trunk/core/metamodel.class.php b/trunk/core/metamodel.class.php index 3e79c0a17..60696cded 100644 --- a/trunk/core/metamodel.class.php +++ b/trunk/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);