l(st('You can run cron manually.'), 'admin/reports/status/run-cron')) )); } /** * Implementation of hook_uninstall(). */ function statspro_uninstall() { drupal_uninstall_schema('statspro'); db_query("DELETE FROM {variable} WHERE name LIKE 'statspro_%%'"); } /** * Implementation of hook_schema(). */ function statspro_schema() { $schema['statspro'] = array( 'fields' => array( 'day' => array('type' => 'varchar', 'pgsql_type' => 'date', 'mysql_type' => 'date', 'sqlite_type' => 'date', 'not null' => TRUE, 'disp-width' => '10'), 'nuser' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'auser' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'nnode' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'cnode' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'comment' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'pi' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'upi' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'error' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'uerror' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'warning' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'uwarning' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'emergency' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'uemergency' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'alert' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'ualert' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'critical' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'ucritical' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')), 'primary key' => array('day'), ); $schema['statspro_term'] = array( 'fields' => array( 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'ncount' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')), 'primary key' => array('tid'), 'indexes' => array('ncount' => array('ncount')), ); $schema['statspro_path_aggregator'] = array( 'fields' => array( 'spaid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'name' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'paths' => array( 'type' => 'text', 'not null' => TRUE, ), 'weight' => array( 'type' => 'int', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('spaid'), ); return $schema; } /** * Implementation of hook_requirements(). */ function statspro_requirements($phase) { $requirements = array(); // Ensure translations don't break at install time. $t = get_t(); if ($phase == 'runtime') { $last_run = variable_get('statspro_last_run', 0); if (empty($last_run)) { $requirements['statspro_cron'] = array( 'title' => $t('Statistics Pro'), 'description' => $t('Statistics Pro requires to run cron. !url', array('!url' => l('You can run cron manually.', 'admin/reports/status/run-cron'))), 'severity' => REQUIREMENT_ERROR, 'value' => $t('No data generated'), ); } /** * This check indicates that the Aggegate Statistics module should be * removed. */ if (module_exists('aggregate_statistics')) { $requirements['statspro_aggregate_statistics'] = array( 'title' => $t('@module module', array('@module' => $t('Aggregate Statistics'))), 'value' => $t('Enabled'), 'severity' => REQUIREMENT_WARNING, 'description' => $t( 'The @aggregate_statistics_module module should be uninstalled as the @this_module module implements all @aggregate_statistics_module module features since version 6.x-2.x', array( '@aggregate_statistics_module' => $t('Aggregate Statistics'), '@this_module' => $t('Statistics Pro'), ) ), ); } /** * Only show recommended modules if the optional dependencies are met. */ if (module_exists('statistics') && (variable_get('statistics_enable_access_log', 0) != 0)) { if (!module_exists('statistics_advanced')) { // Statistics Advanced module is recommended. $requirements['statspro_statistics_advanced'] = array( 'title' => $t('@module module', array('@module' => $t('Statistics Advanced'))), 'value' => $t('Disabled'), 'severity' => REQUIREMENT_WARNING, 'description' => $t( 'The !statistics_advanced_module module is recommended as it fixes core %statistics_module module bugs. Please consider installing and enabling it.', array( '!statistics_advanced_module' => l(t('Statistics Advanced'), 'http://drupal.org/project/statistics_advanced'), '%statistics_module' => t('Statistics'), ) ), ); } if (!module_exists('browscap')) { $requirements['statspro_browscap'] = array( 'title' => $t('@module module', array('@module' => $t('Browscap'))), 'value' => $t('Disabled'), 'severity' => REQUIREMENT_WARNING, 'description' => $t( 'The !browscap_module module is recommended as with it the %statistics_advanced_module module can separate regular traffic from webcrawler traffic. Please consider installing and enabling it.', array( '!browscap_module' => l(t('Browscap'), 'http://drupal.org/project/browscap'), '%statistics_advanced_module' => t('Statistics Advanced'), ) ), ); } } } return $requirements; } function statspro_update_1() { statspro_reset_stats(); return array(); } function statspro_update_2() { $ret = array(); $schema = statspro_schema(); db_create_table($ret, 'statspro_term', $schema['statspro_term']); variable_set('statspro_term_rebuild', TRUE); return $ret; } /** * Creates a temporary statspro table with the day column already as DATE. * * @return array */ function statspro_update_6100() { $ret = array(); $new_table = array( 'fields' => array( 'day' => array('type' => 'varchar', 'pgsql_type' => 'date', 'mysql_type' => 'date', 'sqlite_type' => 'date', 'not null' => TRUE, 'disp-width' => '10'), 'nuser' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'auser' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'nnode' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'cnode' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'comment' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'pi' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'upi' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'error' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'uerror' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'warning' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), 'uwarning' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')), 'primary key' => array('day'), ); db_create_table($ret, 'statspro_day_to_date_temp', $new_table); return $ret; } /** * Moves the data from the old statspro table which has the column 'day' as * TIMESTAMP to the temporary statspro_temp table which already has the 'day' * column as DATE. * * @return array */ function statspro_update_6101() { $qt_per_call = 20; // See if we are being called for the first time if (!isset($_SESSION['statspro_update_6101_current'])) { // These variables keep track of our progress $_SESSION['statspro_update_6101_current'] = 0; $_SESSION['statspro_update_6101_max'] = db_result(db_query('SELECT COUNT(*) FROM {statspro}')) - 1; } // Fetch the next $qt_per_call nodes $result = db_query_range('SELECT *, DATE(FROM_UNIXTIME(day)) AS day_date FROM {statspro} ORDER BY day', $_SESSION['statspro_update_6101_current'], $_SESSION['statspro_update_6101_current'] + $qt_per_call); while ($row = db_fetch_array($result)) { $found = db_result(db_query("SELECT * FROM {statspro_day_to_date_temp} WHERE day = '%s'", $row['day_date'])); $_SESSION['statspro_update_6101_current']++; if ($found) { db_query( "UPDATE {statspro_day_to_date_temp} SET nuser = nuser + %d, auser = auser + %d, nnode = nnode + %d, cnode = cnode + %d, comment = comment + %d, pi = pi + %d, upi = upi + %d, error = error + %d, uerror = uerror + %d, warning = warning + %d, uwarning = uwarning + %d WHERE day = '%s'", $row['nuser'], $row['auser'], $row['nnode'], $row['cnode'], $row['comment'], $row['pi'], $row['upi'], $row['error'], $row['uerror'], $row['warning'], $row['uwarning'], $row['day_date'] ); } else { db_query( "INSERT INTO {statspro_day_to_date_temp} (nuser, auser, nnode, cnode, comment, pi, upi, error, uerror, warning, uwarning, day) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s')", $row['nuser'], $row['auser'], $row['nnode'], $row['cnode'], $row['comment'], $row['pi'], $row['upi'], $row['error'], $row['uerror'], $row['warning'], $row['uwarning'], $row['day_date'] ); } } // See if we are done if ($_SESSION['statspro_update_6101_current'] < $_SESSION['statspro_update_6101_max']) { // Not done yet. Return the progress. return array('#finished' => $_SESSION['statspro_update_6101_current'] / $_SESSION['statspro_update_6101_max']); } else { // Done. Clean up and indicate we're finished. unset($_SESSION['statspro_update_6101_current']); unset($_SESSION['statspro_update_6101_max']); return array('#finished' => 1); } } /** * Drops the old statspro table. * * @return array */ function statspro_update_6102() { $ret = array(); db_drop_table($ret, 'statspro'); db_rename_table($ret, 'statspro_day_to_date_temp', 'statspro'); return $ret; } /** * Should not be used. * * Jump straight to statspro_update_6104(). * * @return array */ function statspro_update_6103() { // $ret = array(); // db_rename_table(&$ret, 'statspro_day_to_date_temp', 'statspro_day_to_date_temp2'); // if($ret['success']) { // $ret = array(); // db_rename_table(&$ret, 'statspro_day_to_date_temp2', 'statspro'); // } // else { // $ret = array('success' => TRUE, 'query' => check_plain('SELECT COUNT(*) FROM {statspro}')); // } // return $ret; $ret = array(); $ret[] = array('success' => TRUE, 'query' => check_plain('SELECT COUNT(*) FROM {statspro}')); return $ret; } /** * Includes new fields in the statspro table: emergency, uemergency, alert, * ualert, critical, ucritical. */ function statspro_update_6200() { $ret = array(); $table = 'statspro'; $spec = array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10', ); db_add_field($ret, $table, 'emergency', $spec); db_add_field($ret, $table, 'uemergency', $spec); db_add_field($ret, $table, 'alert', $spec); db_add_field($ret, $table, 'ualert', $spec); db_add_field($ret, $table, 'critical', $spec); db_add_field($ret, $table, 'ucritical', $spec); return $ret; } /** * Creates the new 'statspro_path_aggregator' table which will hold the path * aggregator definitions. */ function statspro_update_6201() { $ret = array(); $table = array( 'fields' => array( 'spaid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'name' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'paths' => array( 'type' => 'text', 'not null' => TRUE, ), 'weight' => array( 'type' => 'int', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('spaid'), ); db_create_table($ret, 'statspro_path_aggregator', $table); drupal_flush_all_caches(); return $ret; }