Details
-
Type: Bug
-
Status: Open
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: 4.7.17
-
Fix Version/s: None
-
Component/s: Core CiviCRM
-
Labels:None
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:None
-
Funding Source:Needs Funding
-
Verified?:No
Description
modified_date of contact (civicrm_contact table) is not updated when contact is deleted or restored.
DB schema (Contact/DAO/Contact.php) suggests modified_date (timestamp) should be updated on every change (line 1302: 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',)
But function contactTrashRestore (CRM/Contact/BAO/Contact.php line 1076) is calling
$contact->copyValues($updateParams); (line 1090)
which copies all fields values, including (old) modified_date, to be saved on update, preventing "ON UPDATE CURRENT_TIMESTAMP" to apply.
I can see three solutions:
1. add
unset($contact->modified_date); // to let ON UPDATE CURRENT_TIMESTAMP happen in DB
in function contactTrashRestore (CRM/Core/BAO.php line 1091)
2. add
if(isset($fields['modified_date'])) unset ($fields['modified_date']);
in function copyValues (CRM/Core/DAO.php line 580)
3. add a DB trigger with
// Update timestamp for civicrm_contact itself
if ($tableName == NULL || $tableName == self::getTableName())
First solution seems lighter. Please confirm it is the correct approach and I can make a patch
(#1 will only impact contact Trash and Restore and not other possible changes in contact when using copyValues function in Contact/BAO).
Thanks