-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Setting datetime fields to real null value for com_content #25760
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
Changes from 9 commits
15b6218
e480596
0dab899
13bda81
8d564e0
e87bc58
d088446
6c30585
71efbbd
dd01835
d1076aa
f8ac7f5
86387c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ALTER TABLE `#__content` MODIFY `created` DATETIME NULL DEFAULT NULL; | ||
| ALTER TABLE `#__content` MODIFY `modified` DATETIME NULL DEFAULT NULL; | ||
| ALTER TABLE `#__content` MODIFY `publish_up` DATETIME NULL DEFAULT NULL; | ||
| ALTER TABLE `#__content` MODIFY `publish_down` DATETIME NULL DEFAULT NULL; | ||
|
|
||
| UPDATE `#__content` SET `created` = NULL WHERE `created` = '0000-00-00 00:00:00'; | ||
| UPDATE `#__content` SET `modified` = NULL WHERE `modified` = '0000-00-00 00:00:00'; | ||
| UPDATE `#__content` SET `publish_up` = NULL WHERE `publish_up` = '0000-00-00 00:00:00'; | ||
| UPDATE `#__content` SET `publish_down` = NULL WHERE `publish_down` = '0000-00-00 00:00:00'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ALTER TABLE "#__content" ALTER COLUMN "created" DROP DEFAULT; | ||
| ALTER TABLE "#__content" ALTER COLUMN "created" DROP NOT NULL; | ||
| ALTER TABLE "#__content" ALTER COLUMN "modified" DROP DEFAULT; | ||
| ALTER TABLE "#__content" ALTER COLUMN "modified" DROP NOT NULL; | ||
| ALTER TABLE "#__content" ALTER COLUMN "publish_up" DROP DEFAULT; | ||
| ALTER TABLE "#__content" ALTER COLUMN "publish_up" DROP NOT NULL; | ||
| ALTER TABLE "#__content" ALTER COLUMN "publish_down" DROP DEFAULT; | ||
| ALTER TABLE "#__content" ALTER COLUMN "publish_down" DROP NOT NULL; | ||
|
|
||
| UPDATE "#__content" SET "created" = NULL WHERE "created" = '1970-01-01 00:00:00'; | ||
| UPDATE "#__content" SET "modified" = NULL WHERE "modified" = '1970-01-01 00:00:00'; | ||
| UPDATE "#__content" SET "publish_up" = NULL WHERE "publish_up" = '1970-01-01 00:00:00'; | ||
| UPDATE "#__content" SET "publish_down" = NULL WHERE "publish_down" = '1970-01-01 00:00:00'; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -225,7 +225,7 @@ protected function getInput() | |||||
| { | ||||||
| case 'SERVER_UTC': | ||||||
| // Convert a date to UTC based on the server timezone. | ||||||
| if ($this->value && $this->value != Factory::getDbo()->getNullDate()) | ||||||
| if ($this->value && strlen($this->value) && $this->value != Factory::getDbo()->getNullDate()) | ||||||
| { | ||||||
| // Get a date object based on the correct timezone. | ||||||
| $date = Factory::getDate($this->value, 'UTC'); | ||||||
|
|
@@ -237,7 +237,7 @@ protected function getInput() | |||||
| break; | ||||||
| case 'USER_UTC': | ||||||
| // Convert a date to UTC based on the user timezone. | ||||||
| if ($this->value && $this->value != Factory::getDbo()->getNullDate()) | ||||||
| if ($this->value && strlen($this->value) && $this->value != Factory::getDbo()->getNullDate()) | ||||||
| { | ||||||
| // Get a date object based on the correct timezone. | ||||||
| $date = Factory::getDate($this->value, 'UTC'); | ||||||
|
|
@@ -250,7 +250,7 @@ protected function getInput() | |||||
| } | ||||||
|
|
||||||
| // Format value when not nulldate ('0000-00-00 00:00:00'), otherwise blank it as it would result in 1970-01-01. | ||||||
| if ($this->value && $this->value != Factory::getDbo()->getNullDate() && strtotime($this->value) !== false) | ||||||
| if ($this->value && strlen($this->value) && $this->value != Factory::getDbo()->getNullDate() && strtotime($this->value) !== false) | ||||||
| { | ||||||
| $tz = date_default_timezone_get(); | ||||||
| date_default_timezone_set('UTC'); | ||||||
|
|
@@ -384,6 +384,11 @@ public function filter($value, $group = null, Registry $input = null) | |||||
| break; | ||||||
| } | ||||||
|
|
||||||
| if ($return == '') | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| $return = null; | ||||||
| } | ||||||
|
|
||||||
| return $return; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,14 @@ | |||||
| */ | ||||||
| class Content extends Table | ||||||
| { | ||||||
| /** | ||||||
| * Indicates that columns fully support the NULL value in the database | ||||||
| * | ||||||
| * @var boolean | ||||||
| * @since 4.0.0 | ||||||
| */ | ||||||
| protected $_supportNullValue = true; | ||||||
|
|
||||||
| /** | ||||||
| * Constructor | ||||||
| * | ||||||
|
|
@@ -247,17 +255,17 @@ public function check() | |||||
| // Set publish_up to null date if not set | ||||||
| if (!$this->publish_up) | ||||||
| { | ||||||
| $this->publish_up = $this->_db->getNullDate(); | ||||||
| $this->publish_up = null; | ||||||
| } | ||||||
|
|
||||||
| // Set publish_down to null date if not set | ||||||
| if (!$this->publish_down) | ||||||
| { | ||||||
| $this->publish_down = $this->_db->getNullDate(); | ||||||
| $this->publish_down = null; | ||||||
| } | ||||||
|
|
||||||
| // Check the publish down date is not earlier than publish up. | ||||||
| if ($this->publish_down < $this->publish_up && $this->publish_down > $this->_db->getNullDate()) | ||||||
| if (!is_null($this->publish_up) && !is_null($this->publish_up) && $this->publish_up > $this->publish_down) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we use === NULL not is_null in code style or?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HLeithner We use both it seems, but is_null() we use by far more often. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc @mbabker changed it in the frame work from is_null to !== NULL I'm and sure if the coding style says anything about this. At least we should use the same in all places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our codestyle has no rules regarding that. If you want us to refactor to that, then I would ask to make a separate issue for that. You might want to bring that up in the ATT. 😉 |
||||||
| { | ||||||
| // Swap the dates. | ||||||
| $temp = $this->publish_up; | ||||||
|
|
@@ -268,7 +276,7 @@ public function check() | |||||
| // Set modified to null date if not set | ||||||
| if (!$this->modified) | ||||||
| { | ||||||
| $this->modified = $this->_db->getNullDate(); | ||||||
| $this->modified = null; | ||||||
| } | ||||||
|
|
||||||
| // Clean up keywords -- eliminate extra spaces between phrases | ||||||
|
|
||||||
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.
Wouldn't this fit better?
if ($this->value !== NULL && $this->value != Factory::getDbo()->getNullDate())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.
No, the value could be an empty string, which isn't null.