소스 검색

Fixed issue with Date fields being mandatory (DB column created with attribute ON UPDATE CURRENT_TIMESTAMP)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@134 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 년 전
부모
커밋
398017d18e
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 25 0
      core/attributedef.class.inc.php

+ 25 - 0
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(