-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change boolean columns from char(1) to tinyint(1) #4797
Conversation
PHP stan complains about
How should we handle this?
Thoughts:
|
core-bundle/src/Migration/Version500/BooleanFieldsMigration.php
Outdated
Show resolved
Hide resolved
Changed my mind to:
|
Probably not because of mysqli :( |
It's not very intuitive though to have to write |
I think we would need to go with option no. 3 then in that case? i.e. change the doc to
|
I think we should merge this one with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
core-bundle/src/Migration/Version500/BooleanFieldsMigration.php
Outdated
Show resolved
Hide resolved
core-bundle/tests/EventListener/DataContainer/PreviewLinkListenerTest.php
Outdated
Show resolved
Hide resolved
core-bundle/tests/Routing/ResponseContext/CoreResponseContextFactoryTest.php
Outdated
Show resolved
Hide resolved
As discussed, we want to wait for #4800 before we merge this PR. |
700143e
to
00bb683
Compare
Unfortunately I have hit a roadblock here. Doctrine seems to convert parameter values that are $objDatabase->prepare("INSERT INTO tl_search %s")
->set($arrSet)
->execute(); With this PR the following error will occur when trying to log into the back end for example:
The functional tests will also fail here for the same reason. |
As briefly discussed with @ausi I am now casting any booleans to integer in |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still plenty of wrong values in the code base, I‘m afraid. A first quick search revealed the following:
- CalendarEventsModel.php line 269
- Dbafs.php line 516
- FormFieldModel.php line 201
- FormModel.php line 121
- ImageSizeItemModel.php line 95
- MemberGroupModel.php line 83 and 101
- MemberModel.php line 197
- Module.php line 476
- NewsModel.php line 238
We have to make sure to search for ='1'
and =''
as well as = '1'
and = ''
to find all occurrences.
Also I made another sweep. |
} | ||
} | ||
|
||
return $targets; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are fields of extensions included too, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see my initial comment. However in the new version, any fields of dynamcially added DCAs (like Catalog Manager or MetaModels) would not be included.
Thank you @fritzmg. |
Description ----------- Contao 4 already has support for `boolean` SQL fields. However, there is still one issue remaining: if you try to copy records, you might encounter the following error: ``` Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column `tl_content`.`foobar` at row 1 ``` This can be reproduced by the following DCA: ```php // contao/dca/tl_content.php $GLOBALS['TL_DCA']['tl_content']['fields']['foobar'] = [ 'eval' => ['doNotCopy' => true], 'sql' => ['type' => 'boolean', 'default' => false], ]; ``` Update the database and then try to copy a page article that contains content elements. This happens because the PDO driver automatically casts everything strings, if no type is given - which for `false` means an empty string - which in turn is not compatible with a `boolean` (`tinyint(1)`) field. To fix this we need to backport [this](https://github.com/contao/contao/blob/110d32fd52f5abfb58a07d15813d09dda7292e8e/core-bundle/contao/library/Contao/Database/Statement.php#L243-L248) from #4797. Commits ------- f2b4709 cast boolean to integer 7753a81 set type instead 4d8e742 cs fix 0126e2c Update core-bundle/src/Resources/contao/library/Contao/Database/State… c67a11e use string param and only fill array if empty d0801f9 fix check 5d992d2 cs fix 8698b23 Only set type to boolean if it wasn’t set explicitly (#8) 70d240f use foreach Co-authored-by: ausi <martin@auswoeger.com>
Description ----------- Contao 4 already has support for `boolean` SQL fields. However, there is still one issue remaining: if you try to copy records, you might encounter the following error: ``` Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column `tl_content`.`foobar` at row 1 ``` This can be reproduced by the following DCA: ```php // contao/dca/tl_content.php $GLOBALS['TL_DCA']['tl_content']['fields']['foobar'] = [ 'eval' => ['doNotCopy' => true], 'sql' => ['type' => 'boolean', 'default' => false], ]; ``` Update the database and then try to copy a page article that contains content elements. This happens because the PDO driver automatically casts everything strings, if no type is given - which for `false` means an empty string - which in turn is not compatible with a `boolean` (`tinyint(1)`) field. To fix this we need to backport [this](https://github.com/contao/contao/blob/110d32fd52f5abfb58a07d15813d09dda7292e8e/core-bundle/contao/library/Contao/Database/Statement.php#L243-L248) from contao/contao#4797. Commits ------- f2b47094 cast boolean to integer 7753a816 set type instead 4d8e7429 cs fix 0126e2c3 Update core-bundle/src/Resources/contao/library/Contao/Database/State… c67a11e4 use string param and only fill array if empty d0801f9a fix check 5d992d21 cs fix 8698b23b Only set type to boolean if it wasn’t set explicitly (#8) 70d240f7 use foreach Co-authored-by: ausi <martin@auswoeger.com>
Implements #4184
Note: the migration automatically converts the empty string value of all
char(1)
fields to0
, if the DCA SQL definition is of typeboolean
. So this would also automatically be done for any extensions, if applicable.