Empty page subtitle can't be saved using dbal
|Priority:||Should have||Due date:|
|Assignee:||Xavier Perseguers||% Done:||
Saving a page with an empty subtitle field is resulting in the error:
102: These fields are not properly updated in database: (subtitle) Probably value mismatch with fieldtype.
The value of the field after the update is 'als' (false minus first and last letter)
$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array (
'_DEFAULT' => array (
'type' => 'adodb',
'config' => array (
'driver' => 'postgres8',
'port' => 5432,
'username' => 'user',
'password' => 'password',
'host' => 'localhost'
(credentials are also set in normal TYPO3 vars $typo3_db_username and so on)
OS: Windows 7 64 bit
Possible solution ==============
I've done some debugging myself, and found that the subtitle field is handled as being boolean false during save. This is not true, because it should be an empty string. Some further investigation learnt that the field is an empty string when I set the eval configuration of the field to 'trim'.
I've searched a bit deeper, and found that the substr method of t3lib_cs can return false instead of a string (which is the documented return type). This is because the php method substr() return false if the length of the string is shorter than the length to which is should be truncated...
For now I solved my problem by changing the first line of this method from:
if ($len===0) return '';
if ($len===0 || empty($string)) return '';
I do know that this handles only empty strings, and not all strings in which the source length is shorter than the destination length, but the problem only occured using an empty string. It might be a core thing, and not really dbal, but I'm not sure about that because I never had this before using dbal.
(issue imported from #M13934)
Updated by Xavier Perseguers about 3 years ago
empty() is not the valid operator according to PHP documentation:
Returns FALSE if var has a non-empty and non-zero value.
The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- "0" (0 as a string)
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
Problem here is with string "0", I used an explicit test against the empty string in my patch.