You are here

ultimate_cron.install in Ultimate Cron 8

Installation file for Ultimate Cron

File

ultimate_cron.install
View source
<?php

/**
 * @file
 *
 * Installation file for Ultimate Cron
 */

/**
 * Implements hook_schema().
 */
function ultimate_cron_schema() {
  $schema = array();
  $schema['ultimate_cron'] = array(
    'description' => 'Cron job function list',
    'export' => array(
      'key' => 'name',
      'key name' => 'Function name',
      'primary key' => 'fid',
      'identifier' => 'name',
      'default hook' => 'default_ultimate_cron_function',
      'save callback' => 'ultimate_cron_crud_save',
      'api' => array(
        'owner' => 'ultimate_cron',
        'api' => 'default_ultimate_cron_functions',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'fid' => array(
        'description' => 'Function ID',
        'type' => 'serial',
        'size' => 'normal',
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'description' => 'Function name',
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'Settings',
        'type' => 'text',
        'serialize' => TRUE,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'fid',
    ),
    'unique keys' => array(
      'uniq_name' => array(
        'name',
      ),
    ),
  );
  $schema['ultimate_cron_log'] = array(
    'description' => 'Logs',
    'fields' => array(
      'lid' => array(
        'description' => 'Log ID',
        'type' => 'serial',
        'size' => 'normal',
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Function name',
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'default' => '',
      ),
      'start_stamp' => array(
        'description' => 'Timstamp of execution start',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'end_stamp' => array(
        'description' => 'Timstamp of execution end',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'service_host' => array(
        'description' => 'Service host',
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'default' => '',
      ),
      'exec_status' => array(
        'description' => 'Status of the execution',
        'type' => 'int',
        'size' => 'normal',
        'not null' => FALSE,
        'default' => NULL,
      ),
      'severity' => array(
        'description' => 'Log level severity',
        'type' => 'int',
        'size' => 'normal',
        'not null' => TRUE,
        'default' => -1,
      ),
      'msg' => array(
        'description' => 'Message',
        'type' => 'text',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'lid',
    ),
    'indexes' => array(
      'idx_last' => array(
        'name',
        'start_stamp',
      ),
      'idx_count' => array(
        'name',
        'end_stamp',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_enable().
 */
function ultimate_cron_enable() {

  // Disable built-in poor mans cron
  variable_set('cron_safe_threshold', 0);
}

/**
 * Implements hook_uninstall().
 */
function ultimate_cron_uninstall() {
  variable_del('ultimate_cron_simultaneous_connections');
  variable_del('ultimate_cron_rule');
  variable_del('ultimate_cron_cleanup_log');
  variable_del('ultimate_cron_catch_up');
  variable_del('ultimate_cron_queue_polling_latency');
  variable_del('ultimate_cron_queue_lease_time');
  variable_del('ultimate_cron_poorman');
  variable_del('ultimate_cron_launch_window');
  variable_del('ultimate_cron_max_execution_time');
}

/**
 * Implements hook_requirements().
 */
function ultimate_cron_requirements($phase) {
  $response = array();
  switch ($phase) {
    case 'install':
      return $response;
    case 'runtime':
      $t = get_t();
      $response['title'] = 'Ultimate Cron';
      $response['value'] = $t('OK');
      $response['severity'] = REQUIREMENT_OK;
      if ($modules = _ultimate_cron_incompatible_modules()) {
        $response['severity'] = REQUIREMENT_ERROR;
        $response['value'] = $t('Ultimate Cron is DISABLED!');
        $response['description'] = $t('%modules is installed on the system, but is incompatible with Ultimate Cron.<br/>Please disable the modules %modules.<br/>You might want to !url settings first.', array(
          '%modules' => join(', ', $modules),
          '!url' => l(t('import'), 'admin/settings/cron/import'),
        ));
      }
      if (ini_get('safe_mode')) {
        $desc = $t('Safe mode enabled. Ultimate Cron is unable to control maximum execution time for cron jobs. This may cause cron jobs to end prematurely.');
        if ($response['severity'] < REQUIREMENT_WARNING) {
          $response['severity'] = REQUIREMENT_WARNING;
          $response['value'] = $t('Safe mode enabled');
          $response['description'] = $desc;
        }
        else {
          $response['description'] .= '<br/>' . $desc;
        }
      }
      $result = array();
      $result['ultimate_cron'] = $response;
      return $result;
  }
}

Functions