[BUGFIX] Default value for native datetime fields must not be 0 96/51296/8
authorSascha Egerer <sascha@sascha-egerer.de>
Thu, 12 Jan 2017 21:14:41 +0000 (22:14 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 9 Jun 2017 11:28:01 +0000 (13:28 +0200)
The default database value for native fields of type datetime
must not be 0 but NULL.

Resolves: #79304
Releases: master, 8.7
Change-Id: I823a85be2a01ccd8df4997ab2969b2c95ed78cd1
Reviewed-on: https://review.typo3.org/51296
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRowDateTimeFields.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index b05209c..6645476 100644 (file)
@@ -43,8 +43,7 @@ class DatabaseRowDateTimeFields implements FormDataProviderInterface
                     // makes date() treat it as a UTC date (which is what we store in the database).
                     $result['databaseRow'][$column] = date('c', strtotime($result['databaseRow'][$column] . ' UTC'));
                 } else {
-                    // Set to 0 timestamp
-                    $result['databaseRow'][$column] = 0;
+                    $result['databaseRow'][$column] = null;
                 }
             } else {
                 // its a UNIX timestamp! We do not modify this here, as it will only be treated as a datetime because
index c2be5a4..c2ffc06 100644 (file)
@@ -1729,7 +1729,7 @@ class DataHandler
         // normal integer "date" fields (timestamps) are handled in checkValue_input_Eval
         if (isset($tcaFieldConf['dbType']) && ($tcaFieldConf['dbType'] === 'date' || $tcaFieldConf['dbType'] === 'datetime')) {
             if (empty($value)) {
-                $value = 0;
+                $value = null;
             } else {
                 $isDateOrDateTimeField = true;
                 $dateTimeFormats = QueryHelper::getDateTimeFormats();
@@ -1739,7 +1739,7 @@ class DataHandler
                 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
                 // We store UTC timestamps in the database, which is what getTimestamp() returns.
                 $dateTime = new \DateTime($value);
-                $value = $value === $emptyValue ? 0 : $dateTime->getTimestamp();
+                $value = $value === $emptyValue ? null : $dateTime->getTimestamp();
             }
         }
         // Secures the string-length to be less than max.
@@ -1770,6 +1770,10 @@ class DataHandler
             }
 
             $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
+            if (isset($tcaFieldConf['dbType']) && isset($res['value']) && !$res['value']) {
+                // set the value to null if we have an empty value for a native field
+                $res['value'] = null;
+            }
 
             // Process UNIQUE settings:
             // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...