From: skodak Date: Thu, 5 Jun 2008 20:35:28 +0000 (+0000) Subject: MDL-15094 fixed stats regression and prefix cleanup X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5183f0cc5b441c8262d842ff6bd617181a049d9a;p=moodle.git MDL-15094 fixed stats regression and prefix cleanup --- diff --git a/course/editcategory.php b/course/editcategory.php index dfe7d2bb1c..269eb6f241 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -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)) { diff --git a/course/report/participation/index.php b/course/report/participation/index.php index 54fc6dc938..5e59d69a4d 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -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) diff --git a/course/report/stats/graph.php b/course/report/stats/graph.php index f3a402fb38..aa45cb5bb3 100644 --- a/course/report/stats/graph.php +++ b/course/report/stats/graph.php @@ -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 ' : '') diff --git a/course/report/stats/lib.php b/course/report/stats/lib.php index a3fc32ad42..9cee9848e3 100644 --- a/course/report/stats/lib.php +++ b/course/report/stats/lib.php @@ -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(); diff --git a/course/report/stats/report.php b/course/report/stats/report.php index 69fe80e52d..184d2c9463 100644 --- a/course/report/stats/report.php +++ b/course/report/stats/report.php @@ -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 : '') diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index 1c5086e04e..aa5a3c141d 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -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; diff --git a/lib/adminlib.php b/lib/adminlib.php index 3a9db94b8d..f99daf0c1b 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 6d0e8c9146..38f45727d2 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 diff --git a/tag/lib.php b/tag/lib.php index 3f92316c06..46c117a53d 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -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"); } diff --git a/user/filters/globalrole.php b/user/filters/globalrole.php index c959790c32..e802339ea3 100644 --- a/user/filters/globalrole.php +++ b/user/filters/globalrole.php @@ -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());