Finally bothered to work out the simple way of stopping Joomla 3.10 creating those pesky 0000-00-00 00:00:00 dates which are now invalid in MySql. This is very simple for components you control, and possible to easily hack in the core Joomla - which will be one of the features of Roomla when I get around to it.

For custom components it is simply two changes in the Table code (components/com_mycomponent/tables/viewname.php)

 

First add a function store()

public function store($updateNulls = true) {
    return parent::store($updateNulls);
}

This simply overrides the core table.php store() function to make use of the fact that it now has a parameter to all null fields to be updated

Then in the check() function you can simply add checks for empty date fields and replace the value with NULL

public function check() {
// ...
 
if ($this->targdate == '') $this->targdate = NULL;
if ($this->postdate == '') $this->postdate = NULL;
 
// ...
return true;
}

Job done. Joomla will read the null dates and make relevant callendar form fields empty, and when it saves if the calendar field is empty it will poke NULL into the db instead.

For Roomla (my hacked version of Joomla 3.10) you can achieve the same thing for all built in components by instead of overriding the store() function just change the default value of $updateNulls to true in line 792 of /libraries/src/Table/Table.php

Then in the components tables/view.php check() functions apply the test for empty dates and make them null - particularly modified, checked_out_time, publish_up, publish_down etc.

 

Comments powered by CComment