updated accounting

This commit is contained in:
SJ 2013-08-21 10:50:43 +02:00
parent 60e41da7be
commit 4bc2dadc15
2 changed files with 23 additions and 22 deletions

View File

@ -3,7 +3,7 @@
$webuidir = '';
$process_all = false;
$start = NULL;
$end = NULL;
$stop = NULL;
$timestart = microtime(true);
// get options from command line
@ -11,7 +11,7 @@ $opts = 'h::';
$lopts = array(
'webui:',
'start::',
'end::',
'stop::',
);
if ( $options = getopt( $opts, $lopts ) )
@ -31,12 +31,14 @@ if ( $options = getopt( $opts, $lopts ) )
{
display_help();
exit;
} elseif ( isset($options['start']) )
}
if ( isset($options['start']) )
{
$start = $options['start'];
} elseif ( isset($options['end']) )
}
if ( isset($options['stop']) )
{
$end = $options['end'];
$stop = $options['stop'];
}
} else {
display_help();
@ -72,16 +74,15 @@ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
extract($language->data);
//$day_to_process = strtotime($day_to_process);
$records = $messagestats->run_counters($start,$end);
$records = $messagestats->run_counters($start,$stop);
$timeend = microtime(true);
$timegone = $timeend - $timestart;
echo("\nFinished Executing Statistics Generation\n");
echo("*************************************************\n");
echo("Start Date: ".date("d M Y",$records['starttimestamp'])."\n");
echo("Stop Date: ".date("d M Y",$records['endtimestamp'])."\n");
echo("Start Date: ".date(DATE_TEMPLATE,$records['starttimestamp'])."\n");
echo("Stop Date: ".date(DATE_TEMPLATE,$records['stoptimestamp'])."\n");
echo("Removed ".$records['deletedstats']." records\n");
echo("Added ".$records['addedstats']." records\n");
echo("Completed Run in ".$timegone." seconds\n\n");
@ -97,4 +98,4 @@ function display_help() {
echo("\t--start=\"Beginning of date range to process, ok values are today, yesterday or DDMMMYYYY...anything php's strtotime can process. Optional, will default to beginning of current day.\"\n");
echo("\t--stop=\"End of date range, same parameters as above. Optional (will default to end of current day)\"\n\n");
}
?>
?>

View File

@ -3,14 +3,14 @@
class ModelAccountingAccounting extends Model
{
public function run_counters( $start=NULL, $end = NULL )
public function run_counters( $start=NULL, $stop = NULL )
{
$now = time();
$counter = array();
$accepteddomains = array_flip( $this->__getAcceptedDomains() );
$return = array(
'starttimestamp' => 0,
'endtimestamp' => 0,
'stoptimestamp' => 0,
'addedstats' => 0,
'deletedstats' => 0,
);
@ -24,23 +24,23 @@ class ModelAccountingAccounting extends Model
$start = $this->__decodeDate( "00:00:00" );
}
if ( !is_null($end) )
if ( !is_null($stop) )
{
$end = $this->__decodeDate( $end );
$end = $end + 86400;
} elseif ( is_null($end) )
$stop = $this->__decodeDate( $stop );
$stop = $stop + 86400;
} elseif ( is_null($stop) )
{
//if we are passed nothing, operate on today
$end = $this->__decodeDate( "00:00:00" );
$end = $end + 86400;
$stop = $this->__decodeDate( "00:00:00" );
$stop = $stop + 86400;
}
$return['starttimestamp'] = $start;
$return['endtimestamp'] = $end;
$return['stoptimestamp'] = $stop;
// run query to return all messages
$tousers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`to`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$end.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `to`;');
$fromusers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`from`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$end.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `from`;');
$tousers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`to`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$stop.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `to`;');
$fromusers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`from`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$stop.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `from`;');
// process results from above four queries
if($tousers->num_rows > 0)
@ -85,7 +85,7 @@ class ModelAccountingAccounting extends Model
}
if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("processed %s to %s: %d records deleted, %d records added",date(DATE_TEMPLATE, $return['starttimestamp']),date(DATE_TEMPLATE, $return['endtimestamp']),$return['deletedstats'],$return['addedstats'])); }
if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("processed %s to %s: %d records deleted, %d records added",date(DATE_TEMPLATE, $return['starttimestamp']),date(DATE_TEMPLATE, $return['stoptimestamp']),$return['deletedstats'],$return['addedstats'])); }
return $return;
}