2013-02-16 12:33:25 +01:00
< ? php
2017-01-01 14:49:36 +01:00
2013-02-16 12:33:25 +01:00
$webuidir = '' ;
$process_all = false ;
$start = NULL ;
2013-08-21 10:50:43 +02:00
$stop = NULL ;
2013-02-16 12:33:25 +01:00
$timestart = microtime ( true );
2015-04-27 14:26:56 +02:00
ini_set ( " session.save_path " , " /tmp " );
2013-02-16 12:33:25 +01:00
$opts = 'h::' ;
$lopts = array (
2017-01-01 14:49:36 +01:00
'start:' ,
'stop:' ,
'webui:' ,
);
2013-02-16 12:33:25 +01:00
2017-01-01 14:49:36 +01:00
if ( $options = getopt ( $opts , $lopts )) {
if ( isset ( $options [ 'h' ])) {
display_help ();
}
if ( isset ( $options [ 'start' ])) {
$start = $options [ 'start' ];
}
if ( isset ( $options [ 'stop' ])) {
$stop = $options [ 'stop' ];
}
if ( isset ( $options [ 'webui' ])) {
$webuidir = $options [ 'webui' ];
}
2013-02-16 12:33:25 +01:00
} else {
display_help ();
}
2017-01-01 14:49:36 +01:00
2017-05-15 18:36:20 +02:00
if ( $webuidir == '' ) {
2018-11-03 15:53:17 +01:00
echo " \n Error: must provide path to WebUI directory \n \n " ;
2017-01-01 14:49:36 +01:00
display_help ();
}
2013-02-16 12:33:25 +01:00
require_once ( $webuidir . " /config.php " );
require ( DIR_SYSTEM . " /startup.php " );
date_default_timezone_set ( TIMEZONE );
$loader = new Loader ();
$language = new Language ();
Registry :: set ( 'language' , $language );
if ( MEMCACHED_ENABLED ) {
$memcache = new Memcache ();
foreach ( $memcached_servers as $m ){
$memcache -> addServer ( $m [ 0 ], $m [ 1 ]);
}
Registry :: set ( 'memcache' , $memcache );
}
$db = new DB ( DB_DRIVER , DB_HOSTNAME , DB_USERNAME , DB_PASSWORD , DB_DATABASE , DB_PREFIX );
Registry :: set ( 'db' , $db );
$loader -> model ( 'accounting/accounting' );
2017-01-01 14:49:36 +01:00
$loader -> model ( 'domain/domain' );
2013-02-16 12:33:25 +01:00
$messagestats = new ModelAccountingAccounting ();
$_SESSION [ 'username' ] = 'cli-admin' ;
$_SERVER [ 'REMOTE_ADDR' ] = '127.0.0.1' ;
extract ( $language -> data );
2017-01-01 14:49:36 +01:00
$records = $messagestats -> run_counters ( $start , $stop , 'sent' );
2013-02-16 12:33:25 +01:00
$timeend = microtime ( true );
$timegone = $timeend - $timestart ;
2018-11-03 15:53:17 +01:00
echo " \n Finished Executing Statistics Generation \n " ;
echo " ************************************************* \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 " ;
2013-02-16 12:33:25 +01:00
2017-01-01 14:49:36 +01:00
2013-02-16 12:33:25 +01:00
function display_help () {
2017-01-01 14:49:36 +01:00
$phpself = basename ( __FILE__ );
2018-11-03 15:53:17 +01:00
echo " \n Usage: $phpself --webui [PATH] [OPTIONS...] \n \n " ;
echo " \t --webui= \" [REQUIRED: path to the Piler WebUI Directory] \" \n \n " ;
echo " options: \n " ;
echo " \t -a Reruns statistics for all records in the message view \n " ;
echo " \t -h Prints this help screen and exits \n " ;
echo " \t --start= \" Beginning of date range to process, ok values are today, yesterday or MYYYY/MM/DD...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 " ;
2017-01-01 14:49:36 +01:00
exit ;
2013-02-16 12:33:25 +01:00
}