View source
<?php
function prod_monitor_schema() {
return array(
'prod_monitor_sites' => array(
'description' => 'Holds all sites and data monitored by Production monitor.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for a site.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'url' => array(
'description' => 'URL of the website to monitor.',
'type' => 'text',
'size' => 'normal',
'default' => NULL,
),
'settings' => array(
'description' => 'All settings related to the site.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
),
'data' => array(
'description' => 'All data collected through XMLRPC in serialized form.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
),
'added' => array(
'description' => 'The Unix timestamp when the site was added.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'lastupdate' => array(
'description' => 'The Unix timestamp when the data was most recently updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'id',
),
),
'prod_monitor_site_modules' => array(
'description' => 'Holds all retrieved module data for a specific site.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for a site.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'projects' => array(
'description' => 'All modules installed on the remote site.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
),
'sitekey' => array(
'description' => 'The unique key for the site.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'lastfetch' => array(
'description' => 'The Unix timestamp when the data was most recently retrieved from the remote site.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'available' => array(
'description' => 'All module updates available for the remote site.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
),
'updates' => array(
'description' => '0 = unknown, 1 = no updates, 2 = regular updates, 3 = security updates.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'lastupdate' => array(
'description' => 'The Unix timestamp of the most recent module update check.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'foreign keys' => array(
'prod_monitor_sites' => array(
'table' => 'prod_monitor_sites',
'columns' => array(
'id' => 'id',
),
),
),
'primary key' => array(
'id',
),
),
'prod_monitor_site_performance' => array(
'description' => 'Holds all retrieved performance data for a specific site.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for a site.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'module' => array(
'description' => 'The module that reported the performance data.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'data' => array(
'description' => 'The actual performance data.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
),
'annotation' => array(
'description' => 'A short annotation to this specific dataset.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'fetched' => array(
'description' => 'The Unix timestamp when the data was retrieved from the remote site.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'foreign keys' => array(
'prod_monitor_sites' => array(
'table' => 'prod_monitor_sites',
'columns' => array(
'id' => 'id',
),
),
),
'primary key' => array(
'id',
'module',
'fetched',
),
),
);
}
function prod_monitor_install() {
drupal_install_schema('prod_monitor');
}
function prod_monitor_uninstall() {
drupal_uninstall_schema('prod_monitor');
db_query('DELETE FROM {variable} WHERE name LIKE "prod_monitor\\_%"');
}
function prod_monitor_update_6101() {
$ret = array();
$schema = prod_monitor_schema();
db_create_table($ret, 'prod_monitor_site_modules', $schema['prod_monitor_site_modules']);
return $ret;
}
function prod_monitor_update_6102() {
$ret = array();
db_change_field($ret, 'prod_monitor_sites', 'settings', 'settings', array(
'description' => 'All settings related to the site.',
'type' => 'text',
'size' => 'medium',
'default' => NULL,
));
return $ret;
}
function prod_monitor_update_6103(&$sandbox) {
$prefix = '_prod_check_';
$ret = array();
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_site'] = 0;
$sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT id) FROM {prod_monitor_sites}'));
}
$sites = db_query_range("SELECT id, settings FROM {prod_monitor_sites} WHERE id > %d ORDER BY id ASC", $sandbox['current_site'], 0, 5);
while ($site = db_fetch_object($sites)) {
$change = FALSE;
$site->settings = unserialize($site->settings);
foreach ($site->settings['functions'] as $set => &$data) {
foreach ($data['functions'] as $function => $title) {
if (stripos($function, $prefix) === FALSE) {
unset($data['functions'][$function]);
$data['functions'][$prefix . $function] = $title;
$change = TRUE;
}
}
}
unset($data, $function);
foreach ($site->settings['checks'] as $set => &$calls) {
foreach ($calls as $key => &$function) {
if (stripos($function, $prefix) === FALSE) {
$function = $prefix . $function;
$change = TRUE;
}
}
}
if ($change) {
$site->settings = serialize($site->settings);
$sql = "UPDATE {prod_monitor_sites} SET settings = '%s' WHERE id = {$site->id}";
$result = db_query($sql, $site->settings);
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
}
$sandbox['progress']++;
$sandbox['current_site'] = $site->id;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
return $ret;
}
function prod_monitor_update_6104() {
$ret = array();
$schema = prod_monitor_schema();
db_create_table($ret, 'prod_monitor_site_performance', $schema['prod_monitor_site_performance']);
return $ret;
}
function prod_monitor_update_6105() {
$ret = array();
db_change_field($ret, 'prod_monitor_site_modules', 'sitekey', 'sitekey', array(
'description' => 'The unique key for the site.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
));
return $ret;
}
function prod_monitor_update_6106() {
$ret = array();
$table = 'prod_monitor_sites';
$result = db_query("SELECT id, settings FROM {%s}", $table);
while ($site = db_fetch_object($result)) {
$settings = unserialize($site->settings);
$settings['dbconnect_path'] = '';
$site->settings = serialize($settings);
drupal_write_record($table, $site, array(
'id',
));
}
return $ret;
}