summaryrefslogblamecommitdiffstats
path: root/modules-available/statistics_reporting/hooks/cron.inc.php
blob: afb18a2302d352418d53528a35870ddd10c59abf (plain) (tree)
1
2
3
4
5
6
7
8
9

     

                                                               
 
                                             
                                          
                                                            
 

                                                             
 
                                                                                          
 
                                                                                       
 
                                                                                           
 

                                                                                            

                                                                                            
                 
                                                                      
         
 
<?php

if (RemoteReport::isReportingEnabled()) {
	$nextReporting = RemoteReport::getReportingTimestamp();

	// It's time to generate a new report
	while ($nextReporting <= time()) {
		RemoteReport::writeNextReportingTimestamp();

		$from = strtotime("-7 days", $nextReporting);
		$to = $nextReporting;

		$statisticsReport = json_encode(RemoteReport::generateReport($from, $to));

		$params = array("action" => "statistics", "data" => $statisticsReport);

		$result = Download::asStringPost(CONFIG_REPORTING_URL, $params, 30, $code);

		if ($code != 200) {
			EventLog::warning("Statistics Reporting failed: " . $code, $result);
		} else {
			EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL);
		}
		$nextReporting = strtotime("+7 days", $nextReporting);
	}
}