Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-20315

modified_date not update on delete or restore contact

    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())

      { $info[] = array( 'table' => array(self::getTableName()), 'when' => 'AFTER', 'event' => array('UPDATE'), 'sql' => "\nSET NEW.modified_date = CURRENT_TIMESTAMP;\n", ); }

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              f2boot Fred BOOT
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: