You are here

function redhen_engagement_update_7100 in RedHen CRM 7

Change engagement_score_id from int to varchar/change column name.

Required to use machine names for engagement scores.

File

modules/redhen_engagement/redhen_engagement.install, line 204
RedhenEngagement install file.

Code

function redhen_engagement_update_7100(&$sandbox) {
  module_load_include('module', 'redhen_engagement');
  db_change_field('redhen_engagement', 'engagement_score_id', 'engagement_score', array(
    'description' => 'The {redhen_engagement_score}.name of this redhen_engagement.',
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  ));
  $scores = redhen_engagement_get_scores();

  // Iterate through each defined engagement score and update redhen_engagement
  // with machine names of the scores.
  foreach ($scores as $score) {
    $num_updated = db_update('redhen_engagement')
      ->fields(array(
      'engagement_score' => $score
        ->identifier(),
    ))
      ->condition('engagement_score', $score->engagement_score_id)
      ->execute();
  }
}