You are here

function redhen_org_update_7006 in RedHen CRM 7

Fix any redhen_org objects stranded by a bug in 1.4's update 7005.

File

modules/redhen_org/redhen_org.install, line 480
Schema and installation hooks for redhen_org module.

Code

function redhen_org_update_7006() {
  $orgs = db_select('redhen_org', 'org')
    ->fields('org', array(
    'name',
    'org_id',
    'label',
  ))
    ->condition('name', '', '=')
    ->orderBy('org_id', 'ASC')
    ->execute();
  $count = 0;
  foreach ($orgs as $org) {
    $count++;
    $machine_name = redhen_org_machine_name($org->label);
    db_update('redhen_org')
      ->fields(array(
      'name' => $machine_name,
    ))
      ->condition('org_id', $org->org_id)
      ->execute();
  }
  if ($count) {
    return t('@count additional RedHen organization(s) updated with machine name(s).', array(
      '@count' => $count,
    ));
  }
}