From ffdd703a99baccb9e2192767b3c821a1566940cb Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 23 Mar 2009 05:19:53 +0000 Subject: [PATCH] MDL-18637 fix Moodle 1.9-style {$CFG->prefix}tablename in HEAD, and a few missing $DB->s. I did not fix all the DB problems in search, there are too many there for me to be prepared to clean up other people's mess. (For once, it was not me making this mistake ;-)) --- admin/replace.php | 4 ++-- auth/shibboleth/logout.php | 4 ++-- grade/report/stats/lib.php | 6 +++--- grade/report/visual/lib.php | 10 +++++----- lib/accesslib.php | 24 ++++++++++++------------ mod/feedback/lib.php | 2 +- search/add.php | 4 ++-- search/delete.php | 4 ++-- search/documents/data_document.php | 8 ++++---- search/documents/forum_document.php | 12 ++++++------ search/documents/resource_document.php | 14 +++++++------- search/update.php | 4 ++-- 12 files changed, 48 insertions(+), 48 deletions(-) diff --git a/admin/replace.php b/admin/replace.php index 67fd9da523..bf54affd65 100644 --- a/admin/replace.php +++ b/admin/replace.php @@ -43,8 +43,8 @@ print_simple_box_end(); /// Try to replace some well-known serialised contents (html blocks) notify('Replacing in html blocks...'); $sql = "SELECT bi.* - FROM {$CFG->prefix}block_instance bi - JOIN {$CFG->prefix}block b ON b.id = bi.blockid + FROM {block_instance} bi + JOIN {block} b ON b.id = bi.blockid WHERE b.name = 'html'"; if ($instances = $DB->get_records_sql($sql)) { foreach ($instances as $instance) { diff --git a/auth/shibboleth/logout.php b/auth/shibboleth/logout.php index 24ab73a7b7..783419b28d 100644 --- a/auth/shibboleth/logout.php +++ b/auth/shibboleth/logout.php @@ -126,7 +126,7 @@ WSDL; function LogoutNotification($SessionID){ - global $CFG, $SESSION; + global $CFG, $SESSION, $DB; // Delete session of user using $SessionID if(empty($CFG->dbsessions)) { @@ -169,7 +169,7 @@ function LogoutNotification($SessionID){ $ADODB_SESS_LIFE = $CFG->sessiontimeout; } - if ($user_session_data = get_records_sql('SELECT sesskey, sessdata FROM '. $CFG->prefix .'sessions2 WHERE expiry > NOW()')) { + if ($user_session_data = $DB->get_records_sql('SELECT sesskey, sessdata FROM {sessions2} WHERE expiry > NOW()')) { foreach ($user_session_data as $session_data) { // Get user session diff --git a/grade/report/stats/lib.php b/grade/report/stats/lib.php index 976a714c98..a67b58ca4d 100755 --- a/grade/report/stats/lib.php +++ b/grade/report/stats/lib.php @@ -247,11 +247,11 @@ class grade_report_stats extends grade_report { } else { /// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it! $sql = "SELECT g.* - FROM {$CFG->prefix}grade_items gi, - {$CFG->prefix}grade_grades g + FROM {grade_items} gi, + {grade_grades} g WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}"; - $grades = get_records_sql($sql); + $grades = $DB->get_records_sql($sql); } $userids = array_keys($this->users); diff --git a/grade/report/visual/lib.php b/grade/report/visual/lib.php index 8ead22c790..2875a94322 100755 --- a/grade/report/visual/lib.php +++ b/grade/report/visual/lib.php @@ -240,14 +240,14 @@ class grade_report_visual extends grade_report { $this->users = $DB->get_records_sql($sql, $params); } else { $sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber - FROM {$CFG->prefix}user u - JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid + FROM {user) u + JOIN {role_assignments} ra ON u.id = ra.userid $this->groupsql WHERE ra.roleid in ($this->gradebookroles) $this->groupwheresql AND ra.contextid ".get_related_contexts_string($this->context); - $this->users = get_records_sql($sql); + $this->users = $DB->get_records_sql($sql); } if (empty($this->users)) { @@ -290,8 +290,8 @@ class grade_report_visual extends grade_report { } else { /// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it! $sql = "SELECT g.* - FROM {$CFG->prefix}grade_items gi, - {$CFG->prefix}grade_grades g + FROM {grade_items} gi, + {grade_grades} g WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}"; $grades = get_records_sql($sql); diff --git a/lib/accesslib.php b/lib/accesslib.php index 122bea7bf7..0e84f05d29 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1135,24 +1135,24 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort=' ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, cc.path AS categorypath - FROM {$CFG->prefix}course c - JOIN {$CFG->prefix}course_categories cc + FROM {course} c + JOIN {course_categories} cc ON c.category=cc.id - JOIN {$CFG->prefix}context ctx + JOIN {context} ctx ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") - JOIN {$CFG->prefix}role_assignments ra + JOIN {role_assignments} ra ON (ra.contextid=ctx.id AND ra.userid=:userid) UNION SELECT c.id, ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, cc.path AS categorypath - FROM {$CFG->prefix}course c - JOIN {$CFG->prefix}course_categories cc + FROM {course} c + JOIN {course_categories} cc ON c.category=cc.id - JOIN {$CFG->prefix}context ctx + JOIN {context} ctx ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") - JOIN {$CFG->prefix}role_capabilities rc + JOIN {role_capabilities} rc ON (rc.contextid=ctx.id AND (rc.capability=:cap $capany)) "; if (!empty($catclause)) { /// If we have found the right in categories, add child courses here too @@ -1162,10 +1162,10 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort=' ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, cc.path AS categorypath - FROM {$CFG->prefix}course c - JOIN {$CFG->prefix}course_categories cc + FROM {course} c + JOIN {course_categories} cc ON c.category=cc.id - JOIN {$CFG->prefix}context ctx + JOIN {context} ctx ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") $catclause"; } @@ -1173,7 +1173,7 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort=' /// Close the inline_view and join with courses table to get requested $coursefields $sql .= " ) inline_view - INNER JOIN {$CFG->prefix}course c + INNER JOIN {course} c ON inline_view.id = c.id"; /// To keep cross-db we need to strip any prefix in the ORDER BY clause for queries using UNION diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 0a2c7be728..ffa869d316 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -197,7 +197,7 @@ function feedback_get_recent_mod_activity(&$activities, &$index, $timemodified, if ($groupid) { $groupselect = "AND gm.groupid = $groupid"; - $groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id"; + $groupjoin = "JOIN {groups_members} gm ON gm.userid=u.id"; } else { $groupselect = ""; $groupjoin = ""; diff --git a/search/add.php b/search/add.php index 26eb4159d9..42c80bb719 100644 --- a/search/add.php +++ b/search/add.php @@ -88,7 +88,7 @@ docid, itemtype FROM - {$CFG->prefix}{$table} + {" . $table . "} WHERE doctype = ? $itemtypes @@ -100,7 +100,7 @@ SELECT id, {$values[0]} as docid FROM - {$CFG->prefix}{$values[1]} + {" . $values[1] . " WHERE id NOT IN ('{$docIdList}') and {$values[2]} > {$indexdate} diff --git a/search/delete.php b/search/delete.php index 5ab8d5e3bb..b6b4bc56b6 100644 --- a/search/delete.php +++ b/search/delete.php @@ -75,7 +75,7 @@ id, {$values[0]} FROM - {$CFG->prefix}{$values[1]} + {" . $values[1] . "} $where "; $docIds = get_records_sql($query); @@ -87,7 +87,7 @@ id, docid FROM - {$CFG->prefix}{$table} + {" . $table . "} WHERE doctype = '{$mod->name}' AND $itemtypes diff --git a/search/documents/data_document.php b/search/documents/data_document.php index 3462c123bd..510b8b66dc 100644 --- a/search/documents/data_document.php +++ b/search/documents/data_document.php @@ -117,8 +117,8 @@ function data_get_records($database_id, $typematch = '*') { SELECT c.* FROM - {$CFG->prefix}data_content as c, - {$CFG->prefix}data_records as r + {data_content} as c, + {data_records} as r WHERE c.recordid = r.id AND r.dataid = {$database_id} @@ -161,8 +161,8 @@ function data_get_comments($database_id) { c.modified, r.dataid FROM - {$CFG->prefix}data_comments as c, - {$CFG->prefix}data_records as r + {data_comments} as c, + {data_records} as r WHERE c.recordid = r.id "; diff --git a/search/documents/forum_document.php b/search/documents/forum_document.php index 5393752841..832142bb48 100644 --- a/search/documents/forum_document.php +++ b/search/documents/forum_document.php @@ -193,13 +193,13 @@ function forum_get_discussions_fast($forum_id) { u.firstname, u.lastname FROM - {$CFG->prefix}forum_discussions d + {forum_discussions} d JOIN - {$CFG->prefix}forum_posts p + {forum_posts} p ON p.discussion = d.id JOIN - {$CFG->prefix}user u + {user} u ON p.userid = u.id WHERE @@ -235,13 +235,13 @@ function forum_get_child_posts_fast($parent, $forum_id) { u.firstname, u.lastname FROM - {$CFG->prefix}forum_discussions d + {forum_discussions} d JOIN - {$CFG->prefix}forum_posts p + {forum_posts} p ON p.discussion = d.id JOIN - {$CFG->prefix}user u + {user} u ON p.userid = u.id WHERE diff --git a/search/documents/resource_document.php b/search/documents/resource_document.php index bc73bf89d7..3c2ee64887 100644 --- a/search/documents/resource_document.php +++ b/search/documents/resource_document.php @@ -88,7 +88,7 @@ function resource_get_content_for_index(&$notneeded) { id as trueid, r.* FROM - {$CFG->prefix}resource as r + {resource} as r WHERE alltext != '' AND alltext != ' ' AND @@ -125,9 +125,9 @@ function resource_get_content_for_index(&$notneeded) { r.type as type, r.timemodified as timemodified FROM - {$CFG->prefix}resource as r, - {$CFG->prefix}course_modules as cm, - {$CFG->prefix}modules as m + {resource} as r, + {course_modules} as cm, + {modules} as m WHERE r.type = 'file' AND cm.instance = r.id AND @@ -237,9 +237,9 @@ function resource_single_document($id, $itemtype) { r.type as type, r.timemodified as timemodified FROM - {$CFG->prefix}resource as r, - {$CFG->prefix}course_modules as cm, - {$CFG->prefix}modules as m + {resource} as r, + {course_modules} as cm, + {modules} as m WHERE cm.instance = r.id AND cm.course = r.course AND diff --git a/search/update.php b/search/update.php index ab5d56d95e..ec081a6df4 100644 --- a/search/update.php +++ b/search/update.php @@ -83,7 +83,7 @@ docid, itemtype FROM - {$CFG->prefix}{$table} + {" . $table . "} WHERE doctype = ? $itemtypes @@ -96,7 +96,7 @@ id, {$values[0]} as docid FROM - {$CFG->prefix}{$values[1]} + {" . $values[1] . "} WHERE {$values[3]} > {$indexdate} AND id IN ('{$docIdList}') -- 2.39.5