From 0fff433e90983bc3064f0e4cb4edaf49e58ebb99 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Wed, 13 Oct 2010 08:23:05 +0000 Subject: [PATCH] #283 Fixed issue with the default value of Enum attributes SVN:trunk[891] --- core/attributedef.class.inc.php | 16 +++++++ test/testlist.inc.php | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index acdad362b..cb51a15ec 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -1096,6 +1096,22 @@ class AttributeEnum extends AttributeString } } + public function ScalarToSQL($value) + { + // Note: for strings, the null value is an empty string and it is recorded as such in the DB + // but that wasn't working for enums, because '' is NOT one of the allowed values + // that's why a null value must be forced to a real null + $value = parent::ScalarToSQL($value); + if ($this->IsNull($value)) + { + return null; + } + else + { + return $value; + } + } + public function RequiresIndex() { return false; diff --git a/test/testlist.inc.php b/test/testlist.inc.php index 3adfe5dfa..3111834e1 100644 --- a/test/testlist.inc.php +++ b/test/testlist.inc.php @@ -1379,6 +1379,17 @@ class TestImportREST extends TestWebServices ), 'csvdata' => "name;status;owner_name;location_name;location_id->org_name;os_family;os_version;management_ip;cpu;ram;brand;model;serial_number\nlocalhost.;production;Demo;Grenoble;Demo;Ubuntu 9.10;2.6.31-19-generic-#56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010;16.16.230.232;Intel(R) Core(TM)2 Duo CPU T7100 @ 1.80GHz;2005;Hewlett-Packard;HP Compaq 6510b (GM108UC#ABF);CNU7370BNP", ), + array( + 'desc' => 'Load server - wrong value for status', + 'login' => 'admin', + 'password' => 'admin', + 'args' => array( + 'class' => 'Server', + 'output' => 'details', + 'reconciliationkeys' => '', + ), + 'csvdata' => "name;status;owner_name;location_name;location_id->org_name;os_family;os_version;management_ip;cpu;ram;brand;model;serial_number\nlocalhost.;Production;Demo;Grenoble;Demo;Ubuntu 9.10;2.6.31-19-generic-#56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010;16.16.230.232;Intel(R) Core(TM)2 Duo CPU T7100 @ 1.80GHz;2005;Hewlett-Packard;HP Compaq 6510b (GM108UC#ABF);CNU7370BNP", + ), array( 'desc' => 'Load NW if', 'login' => 'admin', @@ -2101,4 +2112,67 @@ class TestTriggerAndEmail extends TestBizModel return true; } } + +class TestCreateObjects extends TestBizModel +{ + static public function GetName() + { + return 'Itop - create objects'; + } + + static public function GetDescription() + { + return 'Create weird objects (reproduce a bug?)'; + } + + static public function GetConfigFile() {return '../config-itop.php';} + + protected function DoExecute() + { + $oMyObj = MetaModel::NewObject("Server"); + $oMyObj->Set("name", "test".rand(1,1000)); + $oMyObj->Set("org_id", 2); + $oMyObj->Set("status", 'production'); + $this->ObjectToDB($oMyObj, $bReload = true); + echo "

Created: {$oMyObj->GetHyperLink()}

"; + + $sTicketRef = "I-abcdef"; + echo "

Creating: $sTicketRef

"; + $oMyObj = MetaModel::NewObject("Incident"); + $oMyObj->Set("ref", $sTicketRef); + $oMyObj->Set("title", "my title"); + $oMyObj->Set("description", "my description"); + $oMyObj->Set("ticket_log", "my ticket log"); + $oMyObj->Set("start_date", "2010-03-08 17:37:00"); + $oMyObj->Set("status", "resolved"); + $oMyObj->Set("caller_id", 1); + $oMyObj->Set("org_id", 1); + $oMyObj->Set("urgency", 3); + $oMyObj->Set("agent_id", 1); + $oMyObj->Set("close_date", "0000-00-00 00:00:00"); + $oMyObj->Set("last_update", "2010-04-08 16:47:29"); + $oMyObj->Set("solution", "branche ton pc!"); + // External key given as a string -> should be casted to an integer + $oMyObj->Set("service_id", "1"); + $oMyObj->Set("servicesubcategory_id", "1"); + $oMyObj->Set("product", ""); + $oMyObj->Set("impact", 2); + $oMyObj->Set("priority", 3); + $oMyObj->Set("related_problem_id", 0); + $oMyObj->Set("related_change_id", 0); + $oMyObj->Set("assignment_date", ""); + $oMyObj->Set("resolution_date", ""); + $oMyObj->Set("tto_escalation_deadline", ""); + $oMyObj->Set("ttr_escalation_deadline", ""); + $oMyObj->Set("closure_deadline", ""); + $oMyObj->Set("resolution_code", "fixed"); + $oMyObj->Set("user_satisfaction", ""); + $oMyObj->Set("user_commment", ""); + $oMyObj->Set("workgroup_id", 4); + $this->ObjectToDB($oMyObj, $bReload = true); + echo "

Created: {$oMyObj->GetHyperLink()}

"; + } +} + + ?>