Beispiel #1
0
 /**
  * Build aggregated stats for a period
  *
  * @param string $start         Start date time
  * @param string $end           End date time
  * @param string $period_format Period format
  * @param string $module_name   Module name
  * @param string $action_name   Action name
  * @param string $human_bot     Human/bot filter
  *
  * @return CAccessLog[]
  */
 static function loadPeriodAggregation($start, $end, $period_format, $module_name, $action_name, $human_bot = null)
 {
     $al = new static();
     $table = $al->_spec->table;
     // Convert date format from PHP to MySQL
     $period_format = str_replace("%M", "%i", $period_format);
     $query = "SELECT\n        `accesslog_id`,\n        `period`,\n        SUM(hits)             AS hits,\n        SUM(size)             AS size,\n        SUM(duration)         AS duration,\n        SUM(processus)        AS processus,\n        SUM(processor)        AS processor,\n        SUM(request)          AS request,\n        SUM(nb_requests)      AS nb_requests,\n        SUM(peak_memory)      AS peak_memory,\n        SUM(errors)           AS errors,\n        SUM(warnings)         AS warnings,\n        SUM(notices)          AS notices,\n      DATE_FORMAT(`period`, '{$period_format}') AS `gperiod`\n      FROM {$table}\n      WHERE `period` BETWEEN '{$start}' AND '{$end}'";
     // 2 means for both of them
     if ($human_bot === '0' || $human_bot === '1') {
         $query .= "\nAND bot = '{$human_bot}' ";
     }
     if ($module_name) {
         $actions = CModuleAction::getActions($module_name);
         if ($action_name) {
             $action_id = $actions[$action_name];
             $query .= "\nAND `module_action_id` = '{$action_id}'";
         } else {
             $query .= "\nAND `module_action_id` " . CSQLDataSource::prepareIn(array_values($actions));
         }
     }
     $query .= "\nGROUP BY `gperiod`";
     return $al->loadQueryList($query);
 }
if (CAppUI::conf("readonly") || !CAppUI::conf("log_access")) {
    return;
}
global $m, $action, $dosql;
if (!$action) {
    $action = $dosql;
}
// $action may not defined when the module is inactive
if (!$action) {
    return;
}
// Check prerequisites
$ds = CSQLDataSource::get("std");
// Key initialisation
$log = new CAccessLog();
$log->module_action_id = CModuleAction::getID($m, $action);
// 10-minutes period aggregation
// Don't CMbDT::datetime() to get rid of CAppUI::conf("system_date") if ever used
$period = strftime("%Y-%m-%d %H:%M:00");
$period[15] = "0";
$log->period = $period;
// 10 minutes granularity
$log->aggregate = 10;
// One hit
$log->hits++;
// Keep the scalar conversion
$log->bot = CApp::$is_robot ? 1 : 0;
// Stop chrono if not already done
$chrono = CApp::$chrono;
if ($chrono->step > 0) {
    $chrono->stop();
 /**
  * Build aggregated stats for a period
  *
  * @param string $start         Start date time
  * @param string $end           End date time
  * @param string $period_format Period format
  * @param string $module_name   Module name
  * @param string $action_name   Action name
  * @param string $human_bot     Human/bot filter
  *
  * @return CAccessLog[]
  */
 static function loadPeriodAggregation($start, $end, $period_format, $module_name, $action_name, $human_bot = null)
 {
     $dl = new static();
     $table = $dl->_spec->table;
     // Convert date format from PHP to MySQL
     $period_format = str_replace("%M", "%i", $period_format);
     $query = "SELECT\n        {$table}.`datasourcelog_id`,\n        {$table}.`period`,\n        {$table}.`datasource`,\n        SUM({$table}.`requests`) AS requests,\n        SUM({$table}.`duration`) AS duration,\n        DATE_FORMAT({$table}.`period`, '{$period_format}') AS `gperiod`\n      FROM {$table}\n      WHERE {$table}.`period` BETWEEN '{$start}' AND '{$end}'";
     if ($module_name) {
         $actions = CModuleAction::getActions($module_name);
         if ($action_name) {
             $action_id = $actions[$action_name];
             $query .= "\nAND `module_action_id` = '{$action_id}'";
         } else {
             $query .= "\nAND `module_action_id` " . CSQLDataSource::prepareIn(array_values($actions));
         }
     }
     // 2 means for both of them
     if ($human_bot === '0' || $human_bot === '1') {
         $query .= "\nAND bot = '{$human_bot}' ";
     }
     $query .= "\nGROUP BY `gperiod`, {$table}.`datasource` ORDER BY `period`";
     return $dl->loadQueryList($query);
 }