From 95ae25b992df943c9ad18d59edd1c8b7faeca62b Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sun, 19 Jan 2020 21:36:47 +0000 Subject: [PATCH] Convert civicrm_note.modified_date to timestamp --- CRM/Contribute/BAO/Contribution.php | 1 - CRM/Contribute/Form/Contribution/Confirm.php | 1 - CRM/Core/BAO/Note.php | 4 ---- CRM/Core/DAO/Note.php | 7 ++++--- CRM/Event/BAO/Participant.php | 1 - CRM/Event/Form/ParticipantFeeSelection.php | 1 - CRM/Grant/BAO/Grant.php | 1 - CRM/Upgrade/Incremental/sql/5.24.alpha1.mysql.tpl | 3 +++ tests/phpunit/api/v3/NoteTest.php | 3 ++- xml/schema/Core/Note.xml | 3 ++- 10 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 00b4047fa9..9638929c64 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -533,7 +533,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), - 'modified_date' => date('Ymd'), ]; if (!$noteParams['contact_id']) { $noteParams['contact_id'] = $params['contact_id']; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 4d9534b811..3b4d391ef1 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1001,7 +1001,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'note' => $params['contribution_note'], 'entity_id' => $contribution->id, 'contact_id' => $contribution->contact_id, - 'modified_date' => date('Ymd'), ]; CRM_Core_BAO_Note::add($noteParams, []); diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index ce27f69cb6..ab14eb12a6 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -135,10 +135,6 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { $note = new CRM_Core_BAO_Note(); - if (!isset($params['modified_date'])) { - $params['modified_date'] = date("Ymd"); - } - if (!isset($params['privacy'])) { $params['privacy'] = 0; } diff --git a/CRM/Core/DAO/Note.php b/CRM/Core/DAO/Note.php index d47f7d40c0..6d4d873746 100644 --- a/CRM/Core/DAO/Note.php +++ b/CRM/Core/DAO/Note.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Note.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:1a545c1e601969ae689d9577a3c14389) + * (GenCodeChecksum:7a58bb39022811ac55bfaed58c241487) */ /** @@ -66,7 +66,7 @@ class CRM_Core_DAO_Note extends CRM_Core_DAO { /** * When was this note last modified/edited * - * @var date + * @var timestamp */ public $modified_date; @@ -191,10 +191,11 @@ class CRM_Core_DAO_Note extends CRM_Core_DAO { ], 'modified_date' => [ 'name' => 'modified_date', - 'type' => CRM_Utils_Type::T_DATE, + 'type' => CRM_Utils_Type::T_TIMESTAMP, 'title' => ts('Note Modified By'), 'description' => ts('When was this note last modified/edited'), 'where' => 'civicrm_note.modified_date', + 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'table_name' => 'civicrm_note', 'entity' => 'Note', 'bao' => 'CRM_Core_BAO_Note', diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index bb64e18477..89fcd74fa3 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -238,7 +238,6 @@ class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant { 'note' => $noteValue, 'entity_id' => $participant->id, 'contact_id' => $id, - 'modified_date' => date('Ymd'), ]; $noteIDs = []; if ($noteId) { diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index 4172825564..bc604dbbc2 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -252,7 +252,6 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { 'note' => $params['note'], 'entity_id' => $this->_participantId, 'contact_id' => $this->_contactId, - 'modified_date' => date('Ymd'), ]; CRM_Core_BAO_Note::add($noteParams); } diff --git a/CRM/Grant/BAO/Grant.php b/CRM/Grant/BAO/Grant.php index baf098c4fc..58f035100d 100644 --- a/CRM/Grant/BAO/Grant.php +++ b/CRM/Grant/BAO/Grant.php @@ -241,7 +241,6 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant { 'note' => $params['note'] = $params['note'] ? $params['note'] : "null", 'entity_id' => $grant->id, 'contact_id' => $id, - 'modified_date' => date('Ymd'), ]; CRM_Core_BAO_Note::add($noteParams, (array) CRM_Utils_Array::value('note', $ids)); diff --git a/CRM/Upgrade/Incremental/sql/5.24.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.24.alpha1.mysql.tpl index cd099a7d9d..c319c309bf 100644 --- a/CRM/Upgrade/Incremental/sql/5.24.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.24.alpha1.mysql.tpl @@ -1 +1,4 @@ {* file to handle db changes in 5.24.alpha1 during upgrade *} + +{* #16338 Convert civicrm_note.modified_date to timestamp *} +ALTER TABLE civicrm_note MODIFY COLUMN modified_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When was this note last modified/edited'; diff --git a/tests/phpunit/api/v3/NoteTest.php b/tests/phpunit/api/v3/NoteTest.php index fe4f230363..8b2021df46 100644 --- a/tests/phpunit/api/v3/NoteTest.php +++ b/tests/phpunit/api/v3/NoteTest.php @@ -172,7 +172,8 @@ class api_v3_NoteTest extends CiviUnitTestCase { public function testCreateWithoutModifiedDate($version) { $this->_apiversion = $version; unset($this->_params['modified_date']); - $apiResult = $this->callAPISuccess('note', 'create', $this->_params); + $note = $this->callAPISuccess('note', 'create', $this->_params); + $apiResult = $this->callAPISuccess('note', 'get', ['id' => $note['id']]); $this->assertAPISuccess($apiResult); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date']))); } diff --git a/xml/schema/Core/Note.xml b/xml/schema/Core/Note.xml index c04e66cbba..473277f3b5 100644 --- a/xml/schema/Core/Note.xml +++ b/xml/schema/Core/Note.xml @@ -82,8 +82,9 @@ modified_date Note Modified By - date + timestamp When was this note last modified/edited + CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 1.1 -- 2.25.1