function fs_create_pending_data_table(&$fsdb) { $pending = fs_pending_date_table(); $sql = "CREATE TABLE IF NOT EXISTS `{$pending}` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t`timestamp` DATETIME NOT NULL ,\n\t\t\t\t`site_id` INT NOT NULL ,\n\t\t\t\t`user_id` INT NULL ,\n\t\t\t\t`url` TEXT NOT NULL ,\n\t\t\t\t`referrer` TEXT NOT NULL ,\n\t\t\t\t`useragent` TEXT NOT NULL ,\n\t\t\t\t`ip` VARCHAR( 40 ) NOT NULL\n\t\t\t\t) " . fs_comment("Pending data table") . fs_engine("MYISAM"); $r = $fsdb->query($sql); if ($r === FALSE) { return false; } return true; }
function fs_systest_database_test() { require_once FS_ABS_PATH . '/php/db-common.php'; $db = fs_get_db_status(); $errors = array(); if ($db['status'] == FS_DB_NOT_CONFIGURED) { $errors[] = fs_systest_error("fatal", "Database is not configured"); } else { // database is configured, we can do some serious tests. $mysql_version = fs_mysql_version(); if (!fs_mysql_newer_than("4.0.17")) { $errors[] = fs_systest_error("fatal", "Your MySQL database version is <b>{$mysql_version}</b>, FireStats requires <b>4.0.17</b> or newer"); } else { if (!fs_mysql_newer_than("4.1.14")) { $errors[] = fs_systest_error("warning", "Your MySQL database version is <b>{$mysql_version}</b>, Some features of FireStats reqruires <b>4.1.14</b> or newer"); } } if ($db['status'] != FS_DB_VALID && $db['status'] != FS_DB_NOT_CONFIGURED) { $errors[] = fs_systest_error("fatal", fs_get_database_status_message($db)); } else { $fsdb =& fs_get_db_conn(); $tables = fs_get_tables_list(); $except = array(fs_pending_date_table()); // don't check this one for InnoDB. $res = $fsdb->get_results("SHOW TABLE STATUS"); if ($res === false) { $errors[] = fs_systest_error("fatal", "Error querying database"); } else { $bad_tables = ""; $found = array(); foreach ($res as $t) { if (in_array($t->Name, $tables) === true) { $found[$t->Name] = true; if (in_array($t->Name, $except) === false) { if (isset($t->Engine) && $t->Engine != "InnoDB" || isset($t->Type) && $t->Type != "InnoDB") { if ($bad_tables == "") { $bad_tables .= $t->Name; } else { $bad_tables .= ", " . $t->Name; } } } } } foreach ($tables as $t) { if (!(isset($found[$t]) && $found[$t])) { $errors[] = fs_systest_error("fatal", "missing table <b>{$t}</b>"); } } if ($bad_tables != "") { $errors[] = fs_systest_error("fatal", "Some of your tables are not using the InnoDB engine, which is required by FireStats. wierd things may happen <b>({$bad_tables})</b>"); } } } } return $errors; }
function fs_get_tables_list() { $a = array(fs_version_table(), fs_hits_table(), fs_useragents_table(), fs_urls_table(), fs_excluded_ips_table(), fs_bots_table(), fs_options_table(), fs_sites_table(), fs_archive_ranges(), fs_archive_sites(), fs_archive_pages(), fs_archive_referrers(), fs_archive_useragents(), fs_archive_countries(), fs_users_table(), fs_pending_date_table(), fs_url_metadata_table()); return $a; }
<?php define('FS_NO_SESSION', true); require_once dirname(__FILE__) . '/init.php'; require_once dirname(__FILE__) . '/db-hit.php'; if (!defined('FS_COMMIT_MAX_CHUNK_SIZE')) { define('FS_COMMIT_MAX_CHUNK_SIZE', 1000); } /** * This flushed the hits from the pending table to the actual database. * this can be seriously optimized. */ $fsdb =& fs_get_db_conn(); $pending = fs_pending_date_table(); while (true) { $sql = "SELECT COUNT(*) FROM `{$pending}`"; $c = $fsdb->get_var($sql); if ($c === false) { die(fs_db_error()); } if ((int) $c === 0) { break; } $sql = "SELECT * FROM `{$pending}` LIMIT 0," . FS_COMMIT_MAX_CHUNK_SIZE; $res = $fsdb->get_results($sql); if ($res === false) { die(fs_db_error()); } foreach ($res as $d) { $_SERVER['REMOTE_ADDR'] = $d->ip; $_SERVER['HTTP_USER_AGENT'] = $d->useragent;
function fs_add_hit_delayed__($user_id, $site_id) { $pending = fs_pending_date_table(); $fsdb =& fs_get_db_conn(); $d = fs_get_hit_data($fsdb, $user_id, $site_id); $user_id = $d->user_id; $site_id = $d->site_id; $remoteaddr = $d->remoteaddr; $useragent = $d->useragent; $url = $d->url; $referer = $d->referer; $sql = "INSERT DELAYED INTO `{$pending}` (\n\t\t\t\t`timestamp`,\n\t\t\t\t`site_id` ,\n\t\t\t\t`user_id`,\n\t\t\t\t`url` ,\n\t\t\t\t`referrer` ,\n\t\t\t\t`useragent` ,\n\t\t\t\t`ip`\n\t\t\t)\n\t\t\tVALUES (\n\t\t\t\tNOW(), \n\t\t\t\t{$site_id}, \n\t\t\t\t" . ($user_id ? "{$user_id}" : "NULL") . " , \n\t\t\t\t{$url}, \n\t\t\t\t{$referer}, \n\t\t\t\t{$useragent}, \n\t\t\t\t{$remoteaddr}\n\t\t\t)"; if ($fsdb->query($sql) === false) { return fs_db_error(); } }