Skip to content

[4.0] Replace the zero datetime value '0000-00-00 00:00:00' by the real NULL value#21901

Merged
wilsonge merged 12 commits intojoomla:4.0-devfrom
csthomas:com_module_null_datetime
Mar 19, 2019
Merged

[4.0] Replace the zero datetime value '0000-00-00 00:00:00' by the real NULL value#21901
wilsonge merged 12 commits intojoomla:4.0-devfrom
csthomas:com_module_null_datetime

Conversation

@csthomas
Copy link
Copy Markdown
Contributor

@csthomas csthomas commented Aug 28, 2018

Pull Request for Issue # .

Summary of Changes

This PR changes only datetimes in the module table.
No more zero dates like "0000-00-00 00:00:00" in the module table.

Method checkIn() is only added (almost copy/paste) to set column check_out_time to NULL.
At method store() the default value has been changed to $updateNulls = true to be able to save NULL values.

TODO

  • missing changes for the install files (Mysql, PostgreSQL)
  • missing changes in the update files for Postgresql version

Changes for other tables should be made in the next PRs

Testing Instructions

First way:

  1. On existed 4.0-dev installation upload changes and then click on the database "Fix" button.
    The UPDATE ... query won't be applied by the FIX button. You can do it manually (in phpMyAdmin), but it is not required, the system will work anyway!

Second way:

  1. Upload changes, then remove file configuration.php and install joomla 4.0 again (also you can test sample data).

In both cases:

  1. After changes will be applied you can create and save modules with real NULL dates.
    Test publish_up, publish_down and check_out_time columns. Everything work as before.

Expected result

You can create, edit and save modules.
Modules are loaded normally on backend and frontend.

How to revert changes in your test db

SET sql_mode = '';
ALTER TABLE `#__modules` MODIFY `publish_up` DATETIME NOT NULL DEFAULT '0000-00-00 0000:00:00';
ALTER TABLE `#__modules` MODIFY `publish_down` DATETIME NOT NULL DEFAULT '0000-00-00 0000:00:00';
ALTER TABLE `#__modules` MODIFY `checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 0000:00:00';

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Aug 30, 2018

I like the change. I was always wondering why we bloat the rows with such 0 dates instead of null.


-- Use 0 instead of '0000-00-00 00:00:00' to not get 'Invalid default value for ...'
UPDATE `#__modules` SET
`publish_up` = CASE WHEN `publish_up` IN (0, '1000-01-01 00:00:00') THEN NULL ELSE `publish_up` END,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be IN (0, '1000-01-01 00:00:00', '0000-00-00 00:00:00')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 == '0000-00-00 00:00:00' in mysql. This is almost the same.

If we want to be strict then it should be IN ('0000-00-00 00:00:00', '1000-01-01 00:00:00') but then in phpmyadmin on mysql 5.7 I got error Invalid default value for ...

Copy link
Copy Markdown
Contributor

@alikon alikon Aug 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes cause phpmyadmin have a standard/default sql_mode for mysql > 5.7

but for mysql server < 5.7 is always true that 0 == '0000-00-00 00:00:00' ?
not sure depending on sql_mode settings

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Aug 30, 2018

we should do this now in 4.0 or never more

@csthomas csthomas force-pushed the com_module_null_datetime branch from 40f8046 to 4049165 Compare August 30, 2018 23:01
@csthomas csthomas changed the title [4.0][POC] Replace the zero datetime value '0000-00-00 00:00:00' by the real NULL value [4.0] Replace the zero datetime value '0000-00-00 00:00:00' by the real NULL value Aug 30, 2018
@csthomas
Copy link
Copy Markdown
Contributor Author

Ready for core review and test:)

@csthomas
Copy link
Copy Markdown
Contributor Author

By adding patch from curl https://patch-diff.githubusercontent.com/raw/joomla/joomla-cms/pull/19707.diff | git apply --reject you can test the update file for postgresql

// Set publish_up, publish_down and checked_out_time to null date if not set
if (!$this->publish_up)
// Pre-processing by observers
$event = AbstractEvent::create(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do the events in a new pr, so we can focus here on the null issue?

@csthomas
Copy link
Copy Markdown
Contributor Author

csthomas commented Aug 31, 2018

In the "Files changed" tab it is probably not visible. I copy&paste checkIn() method from Table.php and pasted it into Module.php. Then I changed only the comment and two lines to change the sql zero date with NULL and empty string with null.

I will change the order of methods in the file, and the diff view should be more readable.

@csthomas
Copy link
Copy Markdown
Contributor Author

The diff between Table.php and Module.php for checkIn() method.

screenshot_20180831_113733

I did not want to add changes in Table.php because it breaks other tables.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Aug 31, 2018

Would be good if we can do it without copy paste. Can you not expand the query with an "or is null" in Table.php?

@csthomas
Copy link
Copy Markdown
Contributor Author

Can you not expand the query with an "or is null" in Table.php?

Read carefully, this is an update query (SET ....):

- ->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($this->_db->getNullDate()));
+ ->set($this->_db->quoteName($checkedOutTimeField) . ' = NULL');

@csthomas
Copy link
Copy Markdown
Contributor Author

csthomas commented Aug 31, 2018

I changed the code and now should be more readable, without overloading checkIn() method.

@csthomas
Copy link
Copy Markdown
Contributor Author

csthomas commented Sep 4, 2018

@alikon @tonypartridge @ggppdk @Bakual I am asking you for a test, at least for a part, I know people are very busy.

If this go then I can work on the rest of tables.

@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Sep 4, 2018

I have tested this item ✅ successfully on b3e640c

@csthomas thanks for making such PRs to improve / fix Database API and Database handling

I have tested with MySQL
frontend and backend modules,

also looked to see if there are more places to be updated with usage of isNullDatetime() by looking at files that have #__modules as
but did not find any more places


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21901.

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Sep 10, 2018

on my to do list

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Sep 26, 2018

Can we get here some tests? Would be nice to get it in.

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Nov 14, 2018

I have tested this item ✅ successfully on a692e02

sorry for the delay


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21901.

@csthomas
Copy link
Copy Markdown
Contributor Author

There is some conflicts so I have to resolve it. @wilsonge do you have time to review the code?

@csthomas csthomas force-pushed the com_module_null_datetime branch from a692e02 to b9a01f7 Compare November 14, 2018 21:39
@csthomas
Copy link
Copy Markdown
Contributor Author

I rebased PR. There were conflicts in sql files. Now there is need one more test.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Dec 3, 2018

Would be good to get some more tests here and the conflicts fixed, so we can get it merged.

@csthomas
Copy link
Copy Markdown
Contributor Author

csthomas commented Dec 3, 2018

I did what I could. Your turn.

@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Mar 19, 2019

#24151

So what is the status with this PR ?
Furthermore after this gets merged , more similar PRs will be needed

@wilsonge
Copy link
Copy Markdown
Contributor

Let's go for this. I think we still have other compatibility issues. But this seems like a positive starting point.

@wilsonge wilsonge merged commit 447983b into joomla:4.0-dev Mar 19, 2019
@wilsonge wilsonge added this to the Joomla 4.0 milestone Mar 19, 2019
@ghost
Copy link
Copy Markdown

ghost commented Mar 20, 2019

@ggppdk can #24151 be closed or needs more Pull Requests?

@wilsonge
Copy link
Copy Markdown
Contributor

@franz-wohlkoenig needs more. this rolls it out for modules. this will need rolling out everywhere that has a publish up/down column (com_content etc etc)

@hardik-codes
Copy link
Copy Markdown
Contributor

Members may I help with further PRs ?
@wilsonge @franz-wohlkoenig

@wilsonge
Copy link
Copy Markdown
Contributor

Fine by me

@hardik-codes
Copy link
Copy Markdown
Contributor

Fine by me

Where in are the further changes to be made?

@sakiss
Copy link
Copy Markdown
Contributor

sakiss commented Jun 14, 2019

Tested that and works.
Fixes the error messages related with empty published_up, published_down and checked_out_time in the module saving as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants