From c06deacb9b1bbf0e21df8affa3effaa823ce9222 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 4 Oct 2021 09:44:02 -0400 Subject: [PATCH] ensure blank note date in UI defaults to current date. See https://lab.civicrm.org/dev/core/-/issues/2884 --- CRM/Upgrade/Incremental/php/FiveFortyThree.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CRM/Upgrade/Incremental/php/FiveFortyThree.php b/CRM/Upgrade/Incremental/php/FiveFortyThree.php index 1872f58ec3..86a80032d8 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyThree.php @@ -151,6 +151,8 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental $this->addTask('Update individual_suffix token in greetings (use {contact.suffix_id:label})', 'updateGreetingOptions', 'contact.individual_suffix', 'contact.suffix_id:label', $rev ); + + $this->addTask('Set note_date field to NOT NULL', 'setNoteDateFieldNotNull'); } /** @@ -184,4 +186,19 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental return TRUE; } + /** + * Ensure note_date is NOT NULL + * + * Since note_date is exposed in the UI, we want to ensure an empty value + * results in CURRENT_TIME, not a NULL date. + */ + public static function setNoteDateFieldNotNull(): bool { + $i18nRewrite = FALSE; + $query = "UPDATE civicrm_note SET note_date = created_date WHERE note_date IS NULL"; + CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, $i18nRewrite); + $query = "ALTER TABLE civicrm_note CHANGE COLUMN `note_date` `note_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date attached to the note'"; + CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, $i18nRewrite); + return TRUE; + } + } -- 2.25.1