function redhen_engagement_update_7101 in RedHen CRM 7
Add an engagement_score field to {redhen_contact}.
Set the engagement_score value for existing contacts.
File
- modules/
redhen_engagement/ redhen_engagement.install, line 233 - RedhenEngagement install file.
Code
function redhen_engagement_update_7101(&$sandbox) {
if (!db_field_exists('redhen_contact', 'engagement_score')) {
$field = array(
'description' => 'The total engagement score for a contact.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field('redhen_contact', 'engagement_score', $field);
}
$sql = 'UPDATE {redhen_contact} rc SET engagement_score = COALESCE((SELECT SUM(score) FROM {redhen_engagement} re JOIN {redhen_engagement_score} res on re.engagement_score = res.name WHERE re.contact_id = rc.contact_id), 0)';
db_query($sql);
}