You are here

function webform_civicrm_update_6101 in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm.install \webform_civicrm_update_6101()
  2. 6 webform_civicrm.install \webform_civicrm_update_6101()
  3. 7.5 webform_civicrm.install \webform_civicrm_update_6101()
  4. 7 webform_civicrm.install \webform_civicrm_update_6101()
  5. 7.3 webform_civicrm.install \webform_civicrm_update_6101()
  6. 7.4 webform_civicrm.install \webform_civicrm_update_6101()

Add missing activity targets.

File

./webform_civicrm.install, line 131
Webform CiviCRM module's install, uninstall and upgrade code.

Code

function webform_civicrm_update_6101() {
  civicrm_initialize();
  $db = db_query('SELECT * FROM {webform_civicrm_submissions} WHERE contact_id <> :contact_id AND activity_id <> :activity_id', array(
    ':contact_id' => 0,
    ':activity_id' => 0,
  ));
  $sql = 'INSERT INTO civicrm_activity_target (activity_id, target_contact_id) VALUES (%1,%2)';
  $n = 1;
  $c = 0;
  $params = array();
  foreach ($db as $row) {
    $params[$n] = array(
      $row->activity_id,
      'Integer',
    );
    $params[$n + 1] = array(
      $row->contact_id,
      'Integer',
    );
    if ($n > 1) {
      $sql .= ',(%' . $n . ',%' . ($n + 1) . ')';
    }
    $n += 2;
    ++$c;
  }
  if ($n > 1) {
    CRM_Core_DAO::executeQuery($sql, $params);
  }
  return t('@num activity target contacts added.', array(
    '@num' => $c,
  ));
}