[4.0] [com_categories] Fix default value for not nullable datetime columns and make some nullable #26470
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for Issue #24535 (part).
Summary of Changes
This PR fixes all datetime columns of the
com_categoriesdatabase table#__categoriesso there will not be anyInvalid value '0000-00-00 00:00:00' for datetimeerror anymore on MySQL 5.7 or later when strict mode is enabled.Similar to my other PR's for the datetime/timestamp columns of other components, this PR makes column
checked_out_timenullable and have default value NULL.In addition this PR removes the default values from columns
created_timeandmodified_time. This will enforce to insert new records with values for these columns being provided and throw an SQL error if some of these values is not specified, i.e. such errors will not be hidden anymore.Old data will be updated as little as possible. The
created_timecolumn will be not touched at all. We can assume that for core components there is no data with values '0000-00-00 00:00:00' on MySQL or '1970-01-01 00:00:00' on PostgreSQL, and data created by 3rd party components should not be modified. Themodified_timecolumn will be set to the value of thecreated_timecolumn only if it has value '0000-00-00 00:00:00' on MySQL or '1970-01-01 00:00:00' on PostgreSQL. Our PHP already sets the modified time to the created time when saving new records, i.e. modified = created means never modified.Testing Instructions
Testers please report back the database kind (MySQL or PostgreSQL) on which you have tested.
If you have both MySQL and PostgreSQL, please test on both if possible.
Test 1: New installation
configuration.phpand delete all Joomla database tables in PhpMyAdmin or PhpPgAdmin (depending on your database type).datetime/timestamp without timezonecolumns.Result: See section "Expected result" below.
Test 2: Update sql script
installation/sql/mysql/joomla.sqlinto the SQL command window but don't execute the commands yet:This switches off strict mode to the SQL will run on MySQL 5.7 or later.
administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-09-29.sqloradministrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-09-29.sql(depending on your database type) into the SQL command window, in case of MySQL below the previously pasted commands, but don't execute the commands yet.#__by your database prefix in the SQL statements pasted before in the SQL input window.datetime/timestamp without timezonecolumns.Result: See section "Expected result" below.
Expected result
New Installation
Categories work as well as without this PR. In a MySQL database there are no columns of data type
datetimehaving value '0000-00-00 00:00:00' in table#__categories, and there is no invalid default value anymore in MySQL >= 5.7 with strict mode on. On PostgreSQL there are no columns of data typetimestamp without time zonehaving value '0000-00-00 00:00:00' in this table.There is one exception: When checking in a category using com_checkin, the
checked_out_timeis set to '0000-00-00 00:00:00' on MySQL and '1970-01-01 00:00:00' on PosgreSQL. This will be changed with a separate, future PR for com_checkin. Checking in an item with the lock icon in list display works, i.e. therechecked_out_timeis set to NULL.Update sql script
The statements are processed without error. The expected result is the same as for a new installation.
Actual result
New Installation
On MySQL same as expected, but the default value of database columns of data type
datetimehaving value '0000-00-00 00:00:00' in table#__categoriesis invalid in MySQL >= 5.7 with strict mode on, and there might be values '0000-00-00 00:00:00'. On postgreSQL same as expected, but there might be values '1970-01-01 00:00:00' in this table.Documentation Changes Required
Maybe core developer docs and extension developer docs should be updated to encourage them not to use '0000-00-00 00:00:00' on MySQL anymore but use real NULL and not abuse '1970-01-01 00:00:00' on PostgreSQL as a speudo null date anymore and use real NULL values also there.