diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index 547b2f0154a..a6e0f81becc 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -396,59 +396,3 @@ function upgrade_cleanup_unwanted_block_contexts($contextidarray) { $DB->delete_records_select('role_names', 'contextid IN ('.$blockcontextidsstring.')'); $DB->delete_records_select('context', 'id IN ('.$blockcontextidsstring.')'); } - -/** - * Shifts ratings from modules into the central rating table - * - * @param string $ratingssql sql to return the module's rating - * @param string $modulename the name of the module - * @return boolean success flag - */ -/*function upgrade_module_ratings($ratingssql, $modulename) { - global $DB; - $contextid = null; - $contextarray = array(); - $result = true; - $i=0; - - $ratings = $DB->get_recordset_sql($ratingssql); - - foreach ($ratings as $old_rating) { - if($i++%500==0) { - upgrade_set_timeout(60);//prevent a timeout - } - - //all posts within a given forum, glossary etc will have the same context id so store them in an array - if( !array_key_exists($old_rating->mid, $contextarray) ) { - $sql = "SELECT cxt.id - FROM {context} cxt - JOIN {course_modules} cm ON cm.id = cxt.instanceid - JOIN {modules} m ON cm.module = m.id - WHERE m.name = :modulename AND cm.instance = :moduleinstanceid AND cxt.contextlevel = :contextmodule"; - $params = array(); - $params['modulename'] = $modulename; - $params['moduleinstanceid'] = $old_rating->mid; - $params['contextmodule'] = CONTEXT_MODULE; - $results = $DB->get_record_sql($sql, $params); - $contextarray[$old_rating->mid] = $results->id; - } - $contextid = $contextarray[$old_rating->mid]; - - $rating = new stdclass(); - $rating->contextid = $contextid; - $rating->scaleid = $old_rating->scale; - $rating->itemid = $old_rating->itemid; - $rating->rating = $old_rating->rating; - $rating->userid = $old_rating->userid; - $rating->timecreated = $old_rating->timecreated; - $rating->timemodified = $old_rating->timemodified; - - if( !$DB->insert_record('rating', $rating) ) { - return false; - } - } - - $ratings->close(); - - return true; -}*/ \ No newline at end of file diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index a3e59dbf890..e9e6e6646e0 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -256,7 +256,6 @@ function xmldb_data_upgrade($oldversion) { if ($oldversion < 2010042800) { //migrate data ratings to the central rating table - require_once($CFG->dirroot . '/lib/db/upgradelib.php'); $table = new xmldb_table('data_ratings'); if ($dbman->table_exists($table)) { //data ratings didnt store time created and modified so Im using the times from the record the rating was attached to diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 9876b4d70ea..d5a62750381 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -258,20 +258,20 @@ function xmldb_forum_upgrade($oldversion) { if ($oldversion < 2010042800) { //migrate forumratings to the central rating table - require_once($CFG->dirroot . '/lib/db/upgradelib.php'); $table = new xmldb_table('forum_ratings'); if ($dbman->table_exists($table)) { //forum ratings only have a single time column so use it for both time created and modified $sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified) - SELECT cxt.id, f.scale, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified - FROM {forum_ratings} r - JOIN {forum_posts} p ON p.id=r.post - JOIN {forum_discussions} d ON d.id=p.discussion - JOIN {forum} f ON f.id=d.forum - JOIN {course_modules} cm ON cm.instance=f.id - JOIN {context} cxt ON cxt.instanceid=cm.id - JOIN {modules} m ON m.id=cm.module - WHERE m.name = :modname AND cxt.contextlevel = :contextlevel"; + + SELECT cxt.id, f.scale, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified + FROM {forum_ratings} r + JOIN {forum_posts} p ON p.id=r.post + JOIN {forum_discussions} d ON d.id=p.discussion + JOIN {forum} f ON f.id=d.forum + JOIN {course_modules} cm ON cm.instance=f.id + JOIN {context} cxt ON cxt.instanceid=cm.id + JOIN {modules} m ON m.id=cm.module + WHERE m.name = :modname AND cxt.contextlevel = :contextlevel"; $params['modname'] = 'forum'; $params['contextlevel'] = CONTEXT_MODULE; diff --git a/mod/glossary/db/upgrade.php b/mod/glossary/db/upgrade.php index f21c7767cdf..d13535ec595 100644 --- a/mod/glossary/db/upgrade.php +++ b/mod/glossary/db/upgrade.php @@ -262,8 +262,6 @@ function xmldb_glossary_upgrade($oldversion) { if ($oldversion < 2010042800) { //migrate glossary_ratings to the central rating table - require_once($CFG->dirroot . '/lib/db/upgradelib.php'); - $table = new xmldb_table('glossary_ratings'); if ($dbman->table_exists($table)) { //glossary ratings only have a single time column so use it for both time created and modified