Example #1
0
 /**
  * Migrate date and datetime db field values to timestamp
  *
  * @param array $result
  * @return array
  */
 public function addData(array $result)
 {
     $dateTimeFormats = QueryHelper::getDateTimeFormats();
     foreach ($result['processedTca']['columns'] as $column => $columnConfig) {
         if (isset($columnConfig['config']['dbType']) && ($columnConfig['config']['dbType'] === 'date' || $columnConfig['config']['dbType'] === 'datetime')) {
             if (!empty($result['databaseRow'][$column]) && $result['databaseRow'][$column] !== $dateTimeFormats[$columnConfig['config']['dbType']]['empty']) {
                 // Create an ISO-8601 date from current field data; the database always contains UTC
                 // The field value is something like "2016-01-01" or "2016-01-01 10:11:12", so appending "UTC"
                 // 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;
             }
         } else {
             // its a UNIX timestamp! We do not modify this here, as it will only be treated as a datetime because
             // of eval being set to "date" or "datetime". This is handled in InputTextElement then.
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Returns the date and time formats compatible with the given database table.
  *
  * @param string $table Table name for which to return an empty date. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how date and time should be formatted).
  * @return array
  */
 public function getDateTimeFormats($table)
 {
     $this->logDeprecation();
     return QueryHelper::getDateTimeFormats();
 }
Example #3
0
 /**
  * Evaluate "input" type values.
  *
  * @param string $value The value to set.
  * @param array $tcaFieldConf Field configuration from TCA
  * @param string $table Table name
  * @param int $id UID of record
  * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
  * @param string $field Field name
  * @return array $res The result array. The processed value (if any!) is set in the "value" key.
  */
 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field)
 {
     // Handle native date/time fields
     $isDateOrDateTimeField = false;
     $format = '';
     $emptyValue = '';
     // 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;
         } else {
             $isDateOrDateTimeField = true;
             $dateTimeFormats = QueryHelper::getDateTimeFormats();
             $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
             // Convert the date/time into a timestamp for the sake of the checks
             $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();
         }
     }
     // Secures the string-length to be less than max.
     if ((int) $tcaFieldConf['max'] > 0) {
         $value = mb_substr((string) $value, 0, (int) $tcaFieldConf['max'], 'utf-8');
     }
     // Checking range of value:
     // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
     if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int) $value !== (int) $tcaFieldConf['default']) {
         if (isset($tcaFieldConf['range']['upper']) && (int) $value > (int) $tcaFieldConf['range']['upper']) {
             $value = $tcaFieldConf['range']['upper'];
         }
         if (isset($tcaFieldConf['range']['lower']) && (int) $value < (int) $tcaFieldConf['range']['lower']) {
             $value = $tcaFieldConf['range']['lower'];
         }
     }
     if (empty($tcaFieldConf['eval'])) {
         $res = ['value' => $value];
     } else {
         // Process evaluation settings:
         $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
         if ($this->runtimeCache->has($cacheId)) {
             $evalCodesArray = $this->runtimeCache->get($cacheId);
         } else {
             $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], true);
             $this->runtimeCache->set($cacheId, $evalCodesArray);
         }
         $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
         // 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...
         if ($field && $realPid >= 0 && !empty($res['value'])) {
             if (in_array('uniqueInPid', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
             }
             if ($res['value'] && in_array('unique', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
             }
         }
     }
     // Handle native date/time fields
     if ($isDateOrDateTimeField) {
         // Convert the timestamp back to a date/time
         $res['value'] = $res['value'] ? date($format, $res['value']) : $emptyValue;
     }
     return $res;
 }