MDL-15094 fixed stats regression and prefix cleanup
This commit is contained in:
@@ -129,7 +129,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
|
||||
if ($courses = get_courses($id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
|
||||
// move it off the range
|
||||
$count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1
|
||||
FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
|
||||
FROM {course} WHERE category=' . $category->id);
|
||||
$count = $count->max + 100;
|
||||
begin_sql();
|
||||
foreach ($courses as $course) {
|
||||
@@ -242,7 +242,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
|
||||
// TODO something like fix_course_sortorder() ?
|
||||
|
||||
// we are going to need to know the range
|
||||
$max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
|
||||
$max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course_categories} WHERE id=' . $category->id);
|
||||
$max = $max->max + 100;
|
||||
|
||||
if (!empty($moveup)) {
|
||||
|
||||
@@ -208,9 +208,9 @@
|
||||
}
|
||||
|
||||
$countsql = "SELECT COUNT(DISTINCT(ra.userid))
|
||||
FROM {$CFG->prefix}role_assignments ra
|
||||
JOIN {$CFG->prefix}user u ON u.id = ra.userid
|
||||
LEFT OUTER JOIN {$CFG->prefix}log l ON l.userid = ra.userid
|
||||
FROM {role_assignments} ra
|
||||
JOIN {user} u ON u.id = ra.userid
|
||||
LEFT OUTER JOIN {log} l ON l.userid = ra.userid
|
||||
WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND
|
||||
(l.id IS NULL OR
|
||||
(l.cmid = :instanceid AND l.time > :timefrom AND $actionsql)
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
// TODO: cleanup this ugly mess!
|
||||
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
|
||||
.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
|
||||
.' FROM {stats_'.$param->table.'} WHERE '
|
||||
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
|
||||
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
|
||||
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
|
||||
|
||||
@@ -32,15 +32,16 @@
|
||||
function report_stats_timeoptions($mode) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$tableprefix = $CFG->prefix.'stats_';
|
||||
|
||||
if ($mode == STATS_MODE_DETAILED) {
|
||||
$tableprefix = $CFG->prefix.'stats_user_';
|
||||
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
|
||||
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
|
||||
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
|
||||
} else {
|
||||
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend');
|
||||
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend');
|
||||
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend');
|
||||
}
|
||||
|
||||
$earliestday = $DB->get_field_sql('SELECT timeend FROM {daily} ORDER BY timeend');
|
||||
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {weekly} ORDER BY timeend');
|
||||
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {monthly} ORDER BY timeend');
|
||||
|
||||
if (empty($earliestday)) $earliestday = time();
|
||||
if (empty($earliestweek)) $earliestweek = time();
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
//TODO: lceanup this ugly mess
|
||||
$sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber
|
||||
FROM '.$CFG->prefix.'stats_user_'.$param->table.' s
|
||||
JOIN '.$CFG->prefix.'user u ON u.id = s.userid
|
||||
FROM {stats_user_'.$param->table.'} s
|
||||
JOIN {user} u ON u.id = s.userid
|
||||
WHERE courseid = '.$course->id
|
||||
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
|
||||
. ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '')
|
||||
|
||||
@@ -15,7 +15,7 @@ function setup_enrolments(&$user) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// NOTE: if $this->enrol_connect() succeeds you MUST remember to call
|
||||
// $this->enrol_disconnect() as it is doing some nasty vodoo with $CFG->prefix
|
||||
// $this->enrol_disconnect() as it is doing some nasty vodoo with table prefix
|
||||
$enroldb = $this->enrol_connect();
|
||||
if (!$enroldb) {
|
||||
error_log('[ENROL_DB] Could not make a connection');
|
||||
@@ -632,7 +632,7 @@ function create_course ($course,$skip_fix_course_sortorder=0){
|
||||
/// DB Connect
|
||||
/// NOTE: You MUST remember to disconnect
|
||||
/// when you stop using it -- as this call will
|
||||
/// sometimes modify $CFG->prefix for the whole of Moodle!
|
||||
/// sometimes modify table prefix for the whole of Moodle!
|
||||
function enrol_connect() {
|
||||
global $CFG;
|
||||
|
||||
|
||||
+1
-1
@@ -4522,7 +4522,7 @@ function db_replace($search, $replace) {
|
||||
$DB->set_debug(true);
|
||||
foreach ($columns as $column => $data) {
|
||||
if (in_array($data->meta_type, array('C', 'X'))) { // Text stuff only
|
||||
$DB->execute("UPDATE {$CFG->prefix}$table SET $column = REPLACE($column, ?, ?)", array($search, $replace));
|
||||
$DB->execute("UPDATE {".$table."} SET $column = REPLACE($column, ?, ?)", array($search, $replace));
|
||||
}
|
||||
}
|
||||
$DB->set_debug(false);
|
||||
|
||||
+2
-2
@@ -3691,7 +3691,7 @@ function reset_course_userdata($data) {
|
||||
// change course start data
|
||||
$DB->set_field('course', 'startdate', $data->reset_start_date, array('id'=>$data->courseid));
|
||||
// update all course and group events - do not move activity events
|
||||
$updatesql = "UPDATE {$CFG->prefix}event
|
||||
$updatesql = "UPDATE {event}
|
||||
SET timestart = timestart + ?
|
||||
WHERE courseid=? AND instance=0";
|
||||
$DB->execute($updatesql, array($data->timeshift, $data->courseid));
|
||||
@@ -6321,7 +6321,7 @@ function notify_login_failures() {
|
||||
/// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
|
||||
/// and insert them into the cache_flags temp table
|
||||
$sql = "SELECT info, count(*)
|
||||
FROM {$CFG->prefix}log
|
||||
FROM {log}
|
||||
WHERE module = 'login' AND action = 'error'
|
||||
AND time > ?
|
||||
GROUP BY info
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ function tag_get_tags($record_type, $record_id, $type=null) {
|
||||
// the tag has been deleted. This shouldn't happen, but if it did, using
|
||||
// this query could help "clean it up". This causes bugs at this time.
|
||||
//$tags = $DB->get_records_sql("SELECT ti.tagid, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ".
|
||||
// "FROM {$CFG->prefix}tag_instance ti LEFT JOIN {$CFG->prefix}tag tg ON ti.tagid = tg.id ".
|
||||
// "FROM {tag_instance} ti LEFT JOIN {tag} tg ON ti.tagid = tg.id ".
|
||||
// "WHERE ti.itemtype = '{$record_type}' AND ti.itemid = '{$record_id}' {$type} ".
|
||||
// "ORDER BY ti.ordering ASC");
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class user_filter_globalrole extends user_filter_type {
|
||||
$timenow = round(time(), 100);
|
||||
|
||||
$sql = "id IN (SELECT userid
|
||||
FROM {$CFG->prefix}role_assignments a
|
||||
FROM {role_assignments} a
|
||||
WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value AND a.timestart<$timenow
|
||||
AND (a.timeend=0 OR a.timeend>$timenow))";
|
||||
return array($sql, array());
|
||||
|
||||
Reference in New Issue
Block a user