ultimate_cron.install in Ultimate Cron 6
Same filename and directory in other branches
Installation file for Ultimate Cron
File
ultimate_cron.installView source
<?php
/**
* @file
*
* Installation file for Ultimate Cron
*/
/**
* Implementation of 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,
),
'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,
),
'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,
),
'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;
}
/**
* Implementation of hook_install().
*/
function ultimate_cron_install() {
drupal_install_schema('ultimate_cron');
}
/**
* Implementation of hook_uninstall().
*/
function ultimate_cron_uninstall() {
drupal_uninstall_schema('ultimate_cron');
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');
}
/**
* Implementation of hook_enable().
*/
function ultimate_cron_enable() {
// Max modules weight
module_load_include('module', 'ultimate_cron');
ultimate_cron_reclaim();
}
/**
* Implementation of 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'),
));
}
elseif ($functions = ultimate_cron_unsafe_hooks()) {
$response['severity'] = REQUIREMENT_WARNING;
$response['value'] = $t('Running in degraded mode');
$response['description'] = $t('Ultimate Cron is not the first module. Please reclaim position through !settings to enable Ultimate Cron handling for all functions.', array(
'!settings' => l(t('settings'), 'admin/settings/cron/settings'),
));
$response['description'] .= '<br/>';
$response['description'] .= $t('Functions not handled by Ultimate Cron because they are unsafe:<br/>%functions', array(
'%functions' => join(', ', array_keys($functions)),
));
}
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;
}
}
/**
* Implements hook_update_N().
*/
function ultimate_cron_update_6000() {
$ret = array();
db_add_field($ret, 'ultimate_cron_log', 'msg', array(
'description' => 'Message',
'type' => 'text',
'not null' => FALSE,
));
$ret[] = update_sql("UPDATE {ultimate_cron_log} l JOIN {ultimate_cron_log_message} m ON l.lid = m.lid SET l.msg = m.msg");
db_drop_table($ret, 'ultimate_cron_log_message');
return $ret;
}
/**
* Implements hook_update_N().
*/
function ultimate_cron_update_6001() {
$ret = array();
// Convert polling latency from microseconds to miliseconds.
$polling_latency = variable_get('ultimate_cron_queue_polling_latency', NULL);
if ($polling_latency) {
$polling_latency /= 1000;
variable_set('ultimate_cron_queue_polling_latency', $polling_latency);
}
return $ret;
}
/**
* Merge ultimate_cron_function and ultimate_cron_configuration into ultimate_cron
*/
function ultimate_cron_update_6002() {
$ret = array();
$schema = ultimate_cron_schema();
db_create_table($ret, 'ultimate_cron', $schema['ultimate_cron']);
$ret[] = update_sql("INSERT INTO {ultimate_cron} SELECT f.fid, f.function, c.configuration AS settings FROM ultimate_cron_function f LEFT JOIN {ultimate_cron_configuration} c ON f.fid = c.fid");
db_drop_table($ret, 'ultimate_cron_function');
db_drop_table($ret, 'ultimate_cron_configuration');
return $ret;
}
/**
* Switch from fid to function name in ultimate_cron_log
*/
function ultimate_cron_update_6003() {
$ret = array();
db_add_field($ret, 'ultimate_cron_log', 'function', array(
'description' => 'Function name',
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'initial' => 'function',
));
$fids = db_query("SELECT DISTINCT fid FROM {ultimate_cron_log}");
while ($fid = db_fetch_object($fids)) {
$function = db_result(db_query("SELECT `function` FROM {ultimate_cron} WHERE fid = %d", $fid->fid));
$ret[] = update_sql("UPDATE {ultimate_cron_log} SET `function` = '" . $function . "' WHERE fid = " . $fid->fid);
}
db_drop_field($ret, 'ultimate_cron_log', 'fid');
db_drop_index($ret, 'ultimate_cron_log', 'idx_last');
db_drop_index($ret, 'ultimate_cron_log', 'idx_count');
db_add_index($ret, 'ultimate_cron_log', 'idx_last', array(
'function',
'start',
));
db_add_index($ret, 'ultimate_cron_log', 'idx_count', array(
'function',
'end',
));
return $ret;
}
/**
* Add missing index to database
*/
function ultimate_cron_update_6105() {
$result = db_query("SELECT fid, `function` FROM {ultimate_cron} ORDER BY fid ASC");
$fids = array();
$keep = array();
$ret = array();
while ($item = db_fetch_array($result)) {
if (isset($keep[$item['function']])) {
$fids[] = $keep[$item['function']];
}
$keep[$item['function']] = $item['fid'];
}
if ($fids) {
db_query("DELETE FROM {ultimate_cron} WHERE fid IN (" . db_placeholders($fids) . ")", $fids);
}
db_add_unique_key($ret, 'ultimate_cron', 'uniq_function', array(
'function',
));
return $ret;
}
/**
* Change schema to SQL 99 compliance.
*/
function ultimate_cron_update_6106() {
$ret = array();
db_drop_unique_key($ret, 'ultimate_cron', 'idx_function');
db_change_field($ret, 'ultimate_cron', 'function', 'name', array(
'description' => 'Function name',
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
));
db_add_unique_key($ret, 'ultimate_cron', 'idx_name', array(
'name',
));
db_change_field($ret, 'ultimate_cron_log', 'function', 'name', array(
'description' => 'Function name',
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
));
db_change_field($ret, 'ultimate_cron_log', 'start', 'start_stamp', array(
'description' => 'Timstamp of execution start',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'ultimate_cron_log', 'end', 'end_stamp', array(
'description' => 'Timstamp of execution end',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'ultimate_cron_log', 'status', 'exec_status', array(
'description' => 'Status of the execution',
'type' => 'int',
'size' => 'normal',
'not null' => FALSE,
'default' => NULL,
));
db_add_field($ret, 'ultimate_cron_log', 'service_host', array(
'description' => 'Service host',
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
));
return $ret;
}
/**
* Add severity level to log.
*/
function ultimate_cron_update_6107(&$context) {
$ret = array();
db_add_field($ret, 'ultimate_cron_log', 'severity', array(
'description' => 'Log level severity',
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'default' => -1,
));
return $ret;
}
Functions
Name | Description |
---|---|
ultimate_cron_enable | Implementation of hook_enable(). |
ultimate_cron_install | Implementation of hook_install(). |
ultimate_cron_requirements | Implementation of hook_requirements(). |
ultimate_cron_schema | Implementation of hook_schema(). |
ultimate_cron_uninstall | Implementation of hook_uninstall(). |
ultimate_cron_update_6000 | Implements hook_update_N(). |
ultimate_cron_update_6001 | Implements hook_update_N(). |
ultimate_cron_update_6002 | Merge ultimate_cron_function and ultimate_cron_configuration into ultimate_cron |
ultimate_cron_update_6003 | Switch from fid to function name in ultimate_cron_log |
ultimate_cron_update_6105 | Add missing index to database |
ultimate_cron_update_6106 | Change schema to SQL 99 compliance. |
ultimate_cron_update_6107 | Add severity level to log. |