You are here

function webform_civicrm_civicrm_merge in Webform CiviCRM Integration 7.3

Same name and namespace in other branches
  1. 8.5 webform_civicrm.module \webform_civicrm_civicrm_merge()
  2. 6.2 webform_civicrm.module \webform_civicrm_civicrm_merge()
  3. 6 webform_civicrm.module \webform_civicrm_civicrm_merge()
  4. 7.5 webform_civicrm.module \webform_civicrm_civicrm_merge()
  5. 7 webform_civicrm.module \webform_civicrm_civicrm_merge()
  6. 7.2 webform_civicrm.module \webform_civicrm_civicrm_merge()
  7. 7.4 webform_civicrm.module \webform_civicrm_civicrm_merge()

Implements hook_civicrm_merge(). Update submission data to reflect new cids when contacts are merged.

File

./webform_civicrm.module, line 297
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_civicrm_merge($type, $data, $new_id = NULL, $old_id = NULL, $tables = NULL) {
  if (!empty($new_id) && !empty($old_id) && $type == 'sqls') {

    // Update civicrm submissions table
    db_update('webform_civicrm_submissions')
      ->expression('contact_id', 'REPLACE(contact_id, :old, :new)', array(
      ':old' => '-' . $old_id . '-',
      ':new' => '-' . $new_id . '-',
    ))
      ->condition('contact_id', '%-' . $old_id . '-%', 'LIKE')
      ->execute();

    // Update contact reference field data
    db_query("UPDATE {webform_submitted_data} d, {webform_component} c SET d.data = :new\n      WHERE d.data = :old AND d.cid = c.cid AND d.nid = c.nid AND c.type = 'civicrm_contact'", array(
      ':new' => $new_id,
      ':old' => $old_id,
    ));
  }
}