From 5b26f68ec152e046f5213a98defc9af959fbf539 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Thu, 10 Sep 2009 14:29:29 +0000 Subject: [PATCH] Fixed issue with Date fields being mandatory (DB column created with attribute ON UPDATE CURRENT_TIMESTAMP) SVN:trunk[134] --- core/attributedef.class.inc.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 865da06259..cc96f02046 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -659,6 +659,31 @@ class AttributeDate extends AttributeDBField public function GetEditClass() {return "Date";} public function GetDBFieldType() {return "TIMESTAMP";} + // #@# THIS HAS TO REVISED + // Having null not allowed was interpreted by mySQL + // which was creating the field with the flag 'ON UPDATE CURRENT_TIMESTAMP' + // Then, on each update of the record, the field was modified. + // We will have to specify the default value if we want to restore this option + // In fact, we could also have more verbs dedicated to the DB: + // GetDBDefaultValue()... or GetDBFieldCreationStatement().... + public function IsNullAllowed() {return true;} + public function GetDefaultValue() + { + $default = parent::GetDefaultValue(); + + if (!parent::IsNullAllowed()) + { + if (empty($default)) + { + $default = date("Y-m-d H:i"); + } + } + + return $default; + } + // END OF THE WORKAROUND + /////////////////////////////////////////////////////////////// + public function GetBasicFilterOperators() { return array(