From 218e56c5251fb23d1319362f53f6c3c507960bb8 Mon Sep 17 00:00:00 2001 From: halftrainedharry <85392304+halftrainedharry@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:41:46 +0100 Subject: [PATCH] Fix saving time for date TVs created in MODX 2.x (#16505) ### 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 --- core/src/Revolution/Processors/Resource/Create.php | 3 +-- core/src/Revolution/Processors/Resource/Update.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/Revolution/Processors/Resource/Create.php b/core/src/Revolution/Processors/Resource/Create.php index 67c35c9f569..98a0d490497 100644 --- a/core/src/Revolution/Processors/Resource/Create.php +++ b/core/src/Revolution/Processors/Resource/Create.php @@ -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'); @@ -769,4 +769,3 @@ public function clearCache() return $clear; } } - diff --git a/core/src/Revolution/Processors/Resource/Update.php b/core/src/Revolution/Processors/Resource/Update.php index 895d78c209a..89499f7f083 100644 --- a/core/src/Revolution/Processors/Resource/Update.php +++ b/core/src/Revolution/Processors/Resource/Update.php @@ -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');