예제 #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);
 }
 /**
  * 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);
 }