diff options
Diffstat (limited to 'modules-available/statistics_reporting/hooks/cron.inc.php')
-rw-r--r-- | modules-available/statistics_reporting/hooks/cron.inc.php | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index bd427e64..a48f74c2 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -1,32 +1,23 @@ <?php -$nextReporting = Property::get("nextReporting", 0); -$time = time(); +if (RemoteReport::isReportingEnabled()) { + $nextReporting = RemoteReport::getReportingTimestamp(); -$allowReport = Property::get("reportingStatus", "on") == "on"; + // It's time to generate a new report + if ($nextReporting <= time()) { + RemoteReport::writeNextReportingTimestamp(); -if ($nextReporting < $time && $allowReport) { + $from = strtotime("-7 days", $nextReporting); + $to = $nextReporting; - Property::set("nextReporting", strtotime("Sunday 23:59:59")); + $statisticsReport = json_encode(RemoteReport::generateReport($from, $to)); - GetData::$from = strtotime("last sunday - 6 days"); - GetData::$to = strtotime("last sunday 23:59:59"); - GetData::$salt = bin2hex(random_bytes(20)); + $params = array("action" => "statistics", "data" => $statisticsReport); - $data = array_merge(GetData::total(true), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array())); - $data['perLocation'] = GetData::perLocation(true); - $data['perClient'] = GetData::perClient(true); - $data['perUser'] = GetData::perUser(true); - $data['perVM'] = GetData::perVM(true); + $result = Download::asStringPost(CONFIG_REPORTING_URL, $params, 30, $code); - - $statisticsReport = json_encode($data); - - $params = array("action" => "statistics", "data" => $statisticsReport); - - Download::asStringPost(CONFIG_REPORTING_URL, $params, 300, $code); - - if ($code != 200) { - EventLog::warning("Statistics Reporting: ".$code); + if ($code != 200) { + EventLog::warning("Statistics Reporting failed: " . $code, $result); + } } -} +}
\ No newline at end of file |