You are here

function ultimate_cron_update_7200 in Ultimate Cron 7.2

Rename columns and indices to 2.x style.

File

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

Code

function ultimate_cron_update_7200() {
  $schema = array();
  $class = variable_get('ultimate_cron_class_job', 'UltimateCronJob');
  $schema['ultimate_cron_job'] = array(
    'description' => 'Cron jobs',
    'export' => array(
      'admin_title' => 'title',
      'key' => 'name',
      'primary key' => 'jid',
      'identifier' => 'job',
      'load callback' => '_ultimate_cron_job_load',
      'load all callback' => '_ultimate_cron_job_load_all',
      'load multiple callback' => '_ultimate_cron_job_load_multiple',
      'save callback' => '_ultimate_cron_job_save',
      'delete callback' => '_ultimate_cron_job_delete',
      'status callback' => '_ultimate_cron_job_set_status',
      'import callback' => '_ultimate_cron_job_import',
      'export callback' => '_ultimate_cron_job_export',
      'cache defaults' => TRUE,
      'default cache bin' => 'cache_ultimate_cron',
      'object' => $class,
      'api' => array(
        'owner' => 'ultimate_cron',
        'api' => 'ultimate_cron',
        'minimum_version' => 3,
        'current_version' => 3,
      ),
    ),
    'fields' => array(
      'jid' => array(
        'description' => 'Job ID',
        'type' => 'serial',
        'size' => 'normal',
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'description' => 'Name',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
      ),
      'title' => array(
        'description' => 'Title',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'Settings',
        'type' => 'text',
        'serialize' => TRUE,
        'not null' => FALSE,
        'object default' => array(
          'scheduler' => array(),
          'launcher' => array(),
          'logger' => array(),
          'settings' => array(),
        ),
        'export callback' => '_ultimate_cron_job_export_settings',
      ),
    ),
    'primary key' => array(
      'jid',
    ),
    'unique keys' => array(
      'machine_name' => array(
        'name',
      ),
    ),
  );
  $schema['ultimate_cron_log'] = array(
    'description' => 'Logs',
    'fields' => array(
      'lid' => array(
        'description' => 'Lock ID',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Name',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
      ),
      'start_time' => array(
        'description' => 'Timestamp of execution start',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'end_time' => array(
        'description' => 'Timestamp of execution end',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'User ID',
        'type' => 'int',
        'size' => 'normal',
        'not null' => TRUE,
        'default' => 0,
      ),
      'init_message' => array(
        'description' => 'Initial message',
        'type' => 'text',
        'not null' => FALSE,
      ),
      'message' => array(
        'description' => 'Message',
        'type' => 'text',
        'not null' => FALSE,
      ),
      'severity' => array(
        'description' => 'Max severity level of the execution',
        'type' => 'int',
        'size' => 'normal',
        'not null' => FALSE,
        'default' => -1,
      ),
    ),
    'primary key' => array(
      'lid',
    ),
    'indexes' => array(
      'idx_last' => array(
        'name',
        'start_time',
        'end_time',
      ),
    ),
  );
  $schema['ultimate_cron_lock'] = array(
    'description' => 'Locks',
    'fields' => array(
      'lid' => array(
        'description' => 'Lock ID',
        'type' => 'serial',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Name',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
      ),
      'current' => array(
        'description' => 'Current lock',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'expire' => array(
        'description' => 'Expiration time of lock',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'lid',
    ),
    'unique keys' => array(
      'idx_name' => array(
        'name',
        'current',
      ),
    ),
  );
  $schema['ultimate_cron_signal'] = array(
    'description' => 'Signals',
    'fields' => array(
      'job_name' => array(
        'description' => 'Name of job',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
      ),
      'signal_name' => array(
        'description' => 'Name of signal',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
      ),
      'claimed' => array(
        'description' => 'Is signal claimed',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'job_name',
      'signal_name',
    ),
  );
  db_create_table('ultimate_cron_lock', $schema['ultimate_cron_lock']);
  db_create_table('ultimate_cron_job', $schema['ultimate_cron_job']);
  db_create_table('ultimate_cron_signal', $schema['ultimate_cron_signal']);

  // Rebuild registry so the Drupals auto loader may find our classes.
  registry_rebuild();

  // New table is ready. Let's migrate the settings.
  ctools_include('export');
  ctools_include('plugins');
  ctools_plugin_get_plugin_type_info(TRUE);
  $old_jobs = array();
  foreach (db_query("SELECT * FROM {ultimate_cron}") as $old_job) {
    $old_job->settings = unserialize($old_job->settings);
    $old_jobs[$old_job->name] = $old_job;
  }
  foreach (module_implements('ctools_plugin_api') as $module) {
    if (module_invoke($module, 'ctools_plugin_api', 'ultimate_cron', 'default_ultimate_cron_functions')) {
      print "including for module: {$module}\n";
      module_load_include('default_ultimate_cron_functions.inc', $module);
    }
  }
  $old_features = module_invoke_all('default_ultimate_cron_function');
  $old_jobs += $old_features;
  $jobs = _ultimate_cron_job_load_all();
  foreach ($old_jobs as $name => $old_job) {
    if (isset($jobs[$name])) {
      $jobs[$name]->settings['scheduler'] = array(
        'name' => 'crontab',
        'crontab' => array(),
      );
      if (!empty($old_job->settings['rules'])) {
        $jobs[$name]->settings['scheduler']['crontab']['rules'] = $old_job->settings['rules'];
      }
      if (!empty($old_job->settings['catch_up'])) {
        $jobs[$name]->settings['scheduler']['crontab']['catch_up'] = $old_job->settings['catch_up'];
      }
      $jobs[$name]->settings['launcher'] = array(
        'name' => 'background_process_legacy',
        'background_process_legacy' => array(),
      );
      if (!empty($old_job->settings['catch_up'])) {
        $jobs[$name]->settings['launcher']['background_process_legacy']['service_group'] = $old_job->settings['service_group'];
      }
      if (!empty($old_job->settings['queue_polling_throttle'])) {
        $jobs[$name]->settings['settings']['queue']['polling_throttle'] = $old_job->settings['queue_polling_throttle'];
      }
      $jobs[$name]->dont_log = TRUE;
      ctools_export_crud_save('ultimate_cron_job', $jobs[$name]);
    }
    $status = isset($old_job->settings['enabled']) ? $old_job->settings['enabled'] : TRUE;
    variable_set('default_ultimate_cron_job_' . $name, !$status ? TRUE : FALSE);
  }

  // Don't need the old one anymore.
  db_drop_table('ultimate_cron');

  // Update log table to new format.
  db_drop_field('ultimate_cron_log', 'exec_status');
  db_drop_index('ultimate_cron_log', 'idx_last');
  db_drop_index('ultimate_cron_log', 'idx_count');
  db_change_field('ultimate_cron_log', 'lid', 'lid', array(
    'description' => 'Lock ID',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ));
  db_change_field('ultimate_cron_log', 'start_stamp', 'start_time', array(
    'description' => 'Timestamp of execution start',
    'type' => 'float',
    'size' => 'big',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_change_field('ultimate_cron_log', 'end_stamp', 'end_time', array(
    'description' => 'Timestamp of execution start',
    'type' => 'float',
    'size' => 'big',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_change_field('ultimate_cron_log', 'service_host', 'init_message', array(
    'description' => 'Initial message',
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_change_field('ultimate_cron_log', 'msg', 'message', array(
    'description' => 'Message',
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_add_field('ultimate_cron_log', 'uid', array(
    'description' => 'User ID',
    'type' => 'int',
    'size' => 'normal',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index('ultimate_cron_log', 'idx_last', array(
    'name',
    'start_time',
    'end_time',
  ));

  // Old version of Ultimate Cron used Background Process for launching jobs,
  // and crontab for scheduling jobs.
  variable_set('ultimate_cron_plugin_scheduler_default', 'crontab');
  variable_set('ultimate_cron_plugin_launcher_default', 'background_process_legacy');

  // Migrate settings.
  $bgpl = _ultimate_cron_plugin_require('launcher', 'background_process_legacy');
  $bgpl->settings['max_threads'] = variable_get('ultimate_cron_simultaneous_connections', 40) == 40 ? 2 : variable_get('ultimate_cron_simultaneous_connections', 40);
  $bgpl->settings['service_group'] = variable_get('ultimate_cron_service_group', 'default');
  $bgpl
    ->setSettings();
  $crontab = _ultimate_cron_plugin_require('scheduler', 'crontab');
  $crontab->settings['rules'] = array(
    variable_get('ultimate_cron_rule', '*/10+@ * * * *'),
  );
  $crontab->settings['catch_up'] = variable_get('ultimate_cron_catch_up', 86400);
  $crontab
    ->setSettings();
  $database = _ultimate_cron_plugin_require('logger', 'database');
  $database->settings['method'] = ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_EXPIRE;
  $database->settings['expire'] = variable_get('ultimate_cron_cleanup_log', 86400 * 30);
  $database
    ->setSettings();
  $queue = _ultimate_cron_plugin_require('settings', 'queue');
  $queue->settings['lease_time'] = variable_get('ultimate_cron_queue_lease_time', 30);
  $queue->settings['empty_delay'] = variable_get('ultimate_cron_queue_polling_latency', 0);
  $queue
    ->setSettings();
  $poorman = _ultimate_cron_plugin_require('settings', 'poorman');
  $poorman->settings['launcher'] = variable_get('ultimate_cron_poorman', FALSE) ? 'background_process_legacy' : '';
  $poorman
    ->setSettings();
}