Skip to content

Commit

Permalink
Fix saving time for date TVs created in MODX 2.x (#16505)
Browse files Browse the repository at this point in the history
### What does it do?
Fixes the code in the "Resource/Create" and "Resource/Update" processors
(that was added in #16398) to also work for date TVs that were created
in MODX 2.x.

### Why is it needed?
In MODX 2.x, the input property **"hideTime"** of a Date-TV is stored as
the value "false" (or "true") -> `s:8:"hideTime";s:5:"false";`
In MODX 3, the same property is stored as the value "0" (or "1") ->
`s:8:"hideTime";s:1:"0";`

In MODX installations, that were updated from MODX 2.x to MODX 3, the
time part of the date-TV-value always gets deleted.

### How to test

- Create a TV of type "date".
- Change the value of "hideTime" from `s:1:"0";` to `s:5:"false";` in
the column "input_properties".
- Make sure, that the time part of the TV value still gets saved
correctly.

### Related topic in the MODX forum
https://community.modx.com/t/date-tv-time-wont-save/7335
  • Loading branch information
halftrainedharry authored Mar 20, 2024
1 parent e4948f4 commit 218e56c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions core/src/Revolution/Processors/Resource/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public function addTemplateVariables()
$tvProperties = $tv->get('input_properties');
if (!empty($value)) {
$dateTime = new \DateTime($value);
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime']) {
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime'] && $tvProperties['hideTime'] != 'false') {
$dateTime->setTime(0, 0, 0, 0);
}
$value = $dateTime->format('Y-m-d H:i:s');
Expand Down Expand Up @@ -769,4 +769,3 @@ public function clearCache()
return $clear;
}
}

2 changes: 1 addition & 1 deletion core/src/Revolution/Processors/Resource/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public function saveTemplateVariables()
$tvProperties = $tv->get('input_properties');
if (!empty($value)) {
$dateTime = new \DateTime($value);
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime']) {
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime'] && $tvProperties['hideTime'] != 'false') {
$dateTime->setTime(0, 0, 0, 0);
}
$value = $dateTime->format('Y-m-d H:i:s');
Expand Down

0 comments on commit 218e56c

Please sign in to comment.