You are here

function ultimate_cron_update_7104 in Ultimate Cron 7

Same name and namespace in other branches
  1. 7.2 ultimate_cron.install \ultimate_cron_update_7104()

Switch from fid to function name in ultimate_cron_log

File

./ultimate_cron.install, line 290
Installation file for Ultimate Cron

Code

function ultimate_cron_update_7104() {
  if (!db_field_exists('ultimate_cron_log', 'name') && !db_field_exists('ultimate_cron_log', 'function')) {

    // 'name' doesn't exist, so update ultimate_cron_update_7106() has never
    // run and was never run when it was previously called
    // ultimate_cron_update_6106(). If one of these updates had run, we would
    // have already done this update and could safely skip it.
    // 'function' also does not exist, so this update has never run and was never run when
    // it was previously called ultimate_cron_update_6003() or
    // ultimate_cron_update_7003() - hence, it needs to be run
    db_add_field('ultimate_cron_log', 'function', array(
      'description' => 'Function name',
      'type' => 'varchar',
      'length' => 127,
      'not null' => TRUE,
      'default' => '',
      'initial' => 'function',
    ));
    $fids = db_select('ultimate_cron_log', 'u')
      ->fields('u', array(
      'fid',
    ))
      ->distinct()
      ->execute();
    while ($fid = $fids
      ->fetchObject()) {
      $function = db_select('ultimate_cron', 'u')
        ->fields('u', array(
        'function',
      ))
        ->condition('fid', $fid->fid, '=')
        ->execute()
        ->fetchObject();
      db_update('ultimate_cron_log')
        ->fields(array(
        'function' => $function->function,
      ))
        ->condition('fid', $fid->fid, '=')
        ->execute();
    }
    db_drop_field('ultimate_cron_log', 'fid');
    db_drop_index('ultimate_cron_log', 'idx_last');
    db_drop_index('ultimate_cron_log', 'idx_count');
    db_add_index('ultimate_cron_log', 'idx_last', array(
      'function',
      'start',
    ));
    db_add_index('ultimate_cron_log', 'idx_count', array(
      'function',
      'end',
    ));
  }
}