function webform_civicrm_update_6101 in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 6.2 webform_civicrm.install \webform_civicrm_update_6101()
- 6 webform_civicrm.install \webform_civicrm_update_6101()
- 7 webform_civicrm.install \webform_civicrm_update_6101()
- 7.2 webform_civicrm.install \webform_civicrm_update_6101()
- 7.3 webform_civicrm.install \webform_civicrm_update_6101()
- 7.4 webform_civicrm.install \webform_civicrm_update_6101()
Add missing activity targets.
File
- ./
webform_civicrm.install, line 159 - 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', [
':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 = [];
foreach ($db as $row) {
$params[$n] = [
$row->activity_id,
'Integer',
];
$params[$n + 1] = [
$row->contact_id,
'Integer',
];
if ($n > 1) {
$sql .= ',(%' . $n . ',%' . ($n + 1) . ')';
}
$n += 2;
++$c;
}
if ($n > 1) {
CRM_Core_DAO::executeQuery($sql, $params);
}
return st('@num activity target contacts added.', [
'@num' => $c,
]);
}