#!/usr/bin/php
<?php
/*
$Id: reanalyze.php 102 2007-08-28 05:59:41Z randomperson83 $
Obsessive Web Statistics
Copyright (C) 2007 Dustin Spicuzza <hide@address.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$base = realpath(dirname(__FILE__) . '/../include/');
require "$base/base.inc.php";
require "$base/dimensions.inc.php";
require "$base/plugin.inc.php";
require "$base/analysis.inc.php";
require_cli();
if ($argc < 4 || in_array($argv[1], array('--help', '-help', '-h', '-?'))){
$dims = '';
$first = true;
if (load_plugins() && ($dimensions = compile_dimensions()) !== false)
foreach ($dimensions as $dname => $attrs){
if ($first)
$first = false;
else
$dims .= ' ,';
$dims .= "$dname";
}
$dims .= "\n";
echo wordwrap(
"Usage: " . $argv[0] . " (website | 'all' for all websites) (full | partial) (dimension | 'all' for all dimensions)
This script is used to reanalysis dimensional data created by analysis plugins. Reanalysis is automatically performed when you install a new analysis plugin that does not change its defined attributes.
If you have installed a new analysis plugin, you may need to run this script. Refer to the installation documentation for that particular analysis plugin.
=== Full Analysis ===
This means a complete reanalysis of the dimension, including its primary nodes. This involves reconstructing the original logfile to some degree from the database. A full analysis cannot be run on dimensions that define their primary fields to be logfile fields. If a full analysis cannot be run, a partial analysis will be run instead.
=== Partial Analysis ===
This only reanalyzes the attributes of a dimension based on the primary nodes of the dimension. This type of analysis is generally much faster than a full analysis.
=== List of dimensions ===
$dims
");
// TODO: Show possible plugins here
die;
}
// load plugins first
if (!load_plugins(''))
die;
if (($dimensions = compile_dimensions()) === false)
die;
$website = $argv[1];
if ($argv[2] == 'partial')
$partial = true;
else if ($argv[2] == 'full')
$partial = false;
else
return show_error("Invalid argument '$argv[2]'");
// setup dimensional array next, if its a partial reanalysis, then
// you need to unset pnode_is and the dimension primary node, else a
// full analysis will be triggered
if ($argv[3] == 'all'){
if ($partial)
foreach ($dimensions as $dname => $attrs)
// unset pnode_is and the primary node
if (array_key_exists('pnode_is',$attrs)){
unset($dimensions[$dname['pnode_is']]);
unset($dimensions[$argv[3]][$argv[3]]);
}
}else if (array_key_exists($argv[3],$dimensions)){
$dimensions = array($argv[3] => $dimensions[$argv[3]]);
if ($partial)
// unset pnode_is and the primary node
if (array_key_exists('pnode_is',$dimensions[$argv[3]])){
unset($dimensions[$argv[3]]['pnode_is']);
unset($dimensions[$argv[3]][$argv[3]]);
}
}else
return show_error("Invalid dimension '$argv[3]' specified!");
if ($website == 'all'){
foreach (get_website_names() as $site)
if (validate_website_table($site))
reanalyze($site,$dimensions);
}else{
// first, validate the website
if (validate_website_table($website))
reanalyze($website,$dimensions);
}
function reanalyze($website,$dimensions){
// lock DB
$lock = new AnalysisLock($website);
if ($lock->Locked())
die;
$analysis = new Analysis();
if (!$analysis->Initialize($website,$dimensions))
die;
$analysis->reAnalyze();
}
?>