if (!empty($CFG->statsmaxruntime)) {
$time = $CFG->statsmaxruntime+(60*30); // add on half an hour just to make sure (it could take that long to break out of the loop)
}
- if (!get_field_sql('SELECT id FROM '.$CFG->prefix.'stats_daily LIMIT 1')) {
+ if (!get_field_sql('SELECT id FROM '.$CFG->prefix.'stats_daily')) {
// first run, set another lock. we'll check for this in subsequent runs to set the timeout to later for the normal lock.
set_cron_lock('statsfirstrunlock',true,$time,true);
$firsttime = true;
$tableprefix = $CFG->prefix.'stats_';
- $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend LIMIT 1');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend LIMIT 1');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend LIMIT 1');
+ $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
+ $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
+ $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
if (!empty($param->sql)) {
- $sql = $param->sql ." LIMIT ".$numcourses;
+ $sql = $param->sql;
} else {
$sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table
." WHERE timeend >= ".$param->timeafter.' AND stattype = \'activity\''
." GROUP BY courseid "
.$param->extras
- ." ORDER BY ".$param->orderby
- ." LIMIT ".$numcourses;
+ ." ORDER BY ".$param->orderby;
}
error_log($sql);
- $courses = get_records_sql($sql);
+ $courses = get_records_sql($sql, 0, $numcourses);
if (empty($courses)) {
notify(get_string('statsnodata'));
$tableprefix = $CFG->prefix.'stats_user_';
}
- $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend LIMIT 1');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend LIMIT 1');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend LIMIT 1');
+ $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
+ $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
+ $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
}
-?>
\ No newline at end of file
+?>
notify ($statsstatus);
}
- $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend LIMIT 1');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend LIMIT 1');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend LIMIT 1');
+ $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend');
+ $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend');
+ $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
global $CFG;
// if it's not our first run, just return the most recent.
- if ($timeend = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_'.$str.' ORDER BY timeend DESC LIMIT 1')) {
+ if ($timeend = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_'.$str.' ORDER BY timeend DESC')) {
return $timeend;
}
$function = 'stats_get_base_'.$str;
switch ($CFG->statsfirstrun) {
case 'all':
- return $function(get_field_sql('SELECT time FROM '.$CFG->prefix.'log ORDER BY time LIMIT 1'));
+ return $function(get_field_sql('SELECT time FROM '.$CFG->prefix.'log ORDER BY time'));
break;
case 'none':
return $function(strtotime('-1 day',time()));