-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] [com_users] Fix default value for not nullable datetime columns and make some nullable #26469
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
[4.0] [com_users] Fix default value for not nullable datetime columns and make some nullable #26469
Conversation
Co-Authored-By: Quy <[email protected]>
…-default-com-users
|
I have tested this item ✅ successfully on e583fce This is done using an existing and a new installation. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/26469. |
|
@roland-d And what is your opinion on setting last visit date equal to registration date for new users who never have visted the site? |
|
@richard67 To me this is fine because the user did actually visit the site, just didn't login. Performing the registration is a kind of act of logging in if you ask me. |
|
@roland-d Thanks for testing and feedback. |
|
Please don't set the date of the lastvisit to the date of registration. Having that field as nullable, is a regular way to find failed registrations or inactive accounts. It is pretty important to see if an account has never been actually used. |
|
I think the same as Hannes, a registration is not a login. Please make it null able. |
|
@Hackwar @HLeithner I am open for it, but then we have to make core_modified_time in the ucm_content table, too. That would not be a big problem, but as I don't want to make design decisions on my own I have discussed that with @wilsonge . Maybe he can have a look on it again. I will implement it like he advices me. |
|
So currently we have 2 vote for "ok as it is", and 2 votes for "make last visit time nullable". I am open for both, just let me know any final decision, if necessary by PLT. |
|
@Hackwar @HLeithner But just by the way, the google doc and worksheet are available in Glip since weeks for discussion ... and I often advertised it ... don't you think it is a bit late to come now with this discusson? Anyway, I'll let others decide and then do what is decided. |
|
I didn't changed my opinion I had on jday. Modifed should be null and this is a similar thing. |
|
Guys in PLT or whoever else, pleace decide who will decide, or decide who will decide who will decide, or whatever, and then tell me what I shall do and I will do it. |
|
@Hackwar @HLeithner Maybe an idea how to solve it: We make a new column for modified time in the users table, call it "modifiedDate" to fit to the other excentric names in that table, use this column like elsewhere, e.g. save when user data has been modified. We don't have such column yet so it would be useful. We map this to the #__ucm_content.core_modified_time and let the lastVisitDate column be nullable and not map it to ucm content. What do you think about this? It would solve your issue with the users table here. |
|
P.S.: Or we drop UCM soon ;-) |
|
The problem with the last loggin time set to the same time as registration is that you can't see if the user ever logged in. For example if you automatically login on registration both times are the same time. (not 100% sure if this thoughts reflects the code) |
|
@HLeithner It does not help much to explain me the problem again, except you think I am so stupid that I did not understand it at the first time. I would make more sense to read why I have done it this way, mapping of columns to ucm_content, and maybe comment my proposal above or make an own proposal on how to solve it. Btw, the easiest solution of course would be just not to map the LastVisitDate column to ucm_content anymore. |
|
I explained it because it'different then the modified solution of com_content for example. There it seams to be ok because if modified === created then it has never been modified. Here it is different, if you set it to the same time it's doesn't mean that the user has never logged in because it's possible that he logged in on registration. I only explained the difference, maybe not for you, maybe only for my self. Do we need it in the ucm table? what do other extensions if they want to map a null date to modified time column of ucm? does the ucm code automatically use our nullDate value? |
|
Other components do not map null dates to the core_modified_time of ucm_content, that's why core_modified_time is not nullable. We could make it nullable, let com_users map the lastVisitDate column like it does now but let it write null values, and the other components still will not write null values to it. But I need a conrimation of someone who knows ucm_content stuff bettee than I do that we can do it that way. |
|
@Hackwar @HLeithner Will change the last visit time of users to be nullable, but needs a bit investigation before. Stay tuned. |
|
Closing in favour of PR #26609 for user notes and another PR to be created soon for the users table. |
|
Keep this open. Just merge 4.0 into this branch :) |
|
No, merge conflicts would be crazy. I prefer to make a new one, am already working on it, and we can link there to the discussion here. |
|
PR for the users table is #26611 . |
Pull Request for Issue #24535 (part).
Summary of Changes
This Pull Request (PR) fixes all datetime columns of the
com_usersdatabase tables#__usersand#__user_notesso 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.The user notes are handled like other tables in my other PR's: Columns
publish_up,publish_downandchecked_out_timewill be nullable and will have default value NULL, and the same is done with columnreview_time. Columnscreated_timeandmodified_timewill not allow null values like before, but the default value will be removed. 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.The users are a bit special: There are not the usual created and modified columns. But in column
field_mappingsof tablecontent_typesyou can find for the record for com_users (type_alias= 'com_users.user') you can see that there columnregisterDateor table#__usersis mapped to thecore_created_timecolumn of the#__ucm_contenttable, andlastvisitDateis mapped tocore_modified_time. Other datetime columns are not mapped for com_user.For this reason, the
lastvisitDatewill be handled likemodifiedormodified_timecolumns in my other PR's for the datetime issue: It will not allow null values and not have a default value, and if a user has never visited the site (i.e. new user), thelastvisitDatewill be equal to theregisterDatecolumn. This might not look very logical, but the decision was made to handle modified columns of other tables in that way for consistenty because it was already done like that at several places, and because the users table is also relevant for UCM and we have that columns mapping mentioned above, I think we have to do it that way. Suggestions for a better way to handle it without changing handling of all modified time columns of other tables would be welcome.The
lastResetTime(time of last password reset) column of the users table will allow null values.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-28.sqloradministrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-09-28.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
Tags 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 tables#__usersand#__user_notes, 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 user note using com_checkin, the
checked_out_timein table#__user_notesis 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 '0000-00-00 00:00:00' of database columns of data type
datetimeis 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.