Skip to content

Commit

Permalink
rating MDL-21657 added something to upgrade script to ensure there ar…
Browse files Browse the repository at this point in the history
…e no problems due to db/install.php having lagged behind unpgrade.php
  • Loading branch information
Andrew Davis committed Mar 17, 2010
1 parent e32a064 commit 019cf6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3090,27 +3090,25 @@ function xmldb_main_upgrade($oldversion) {

//migrate forumratings
//forum ratings only have a single time column so use it for both time created and modified
$ratingssql = 'select r.id as rid, r.post as itemid, r.rating, r.userid, r.time as timecreated, r.time as timemodified, f.scale, f.id as mid from {forum_ratings} r
inner join {forum_posts} p on p.id=r.post
inner join {forum_discussions} d on d.id=p.discussion
inner join {forum} f on f.id=d.forum';
echo "migrating forum ratings<br>";
$ratingssql = 'SELECT r.id AS rid, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified, f.scale, f.id AS mid
FROM {forum_ratings} r
INNER JOIN {forum_posts} p on p.id=r.post
INNER JOIN {forum_discussions} d on d.id=p.discussion
INNER JOIN {forum} f on f.id=d.forum';
$result = $result && upgrade_module_ratings($ratingssql,'forum');

//migrate glossary_ratings
//glossary ratings only have a single time column so use it for both time created and modified
$ratingssql = 'select r.id as rid, r.entryid as itemid, r.rating, r.userid, r.time as timecreated, r.time as timemodified, g.id as mid, g.scale
from {glossary_ratings} r inner join {glossary_entries} ge on ge.id=r.entryid
inner join {glossary} g on g.id=ge.glossaryid';
echo "migrating glossary ratings<br>";
$ratingssql = 'SELECT r.id AS rid, r.entryid AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified, g.id AS mid, g.scale
FROM {glossary_ratings} r INNER JOIN {glossary_entries} ge ON ge.id=r.entryid
INNER JOIN {glossary} g ON g.id=ge.glossaryid';
$result = $result && upgrade_module_ratings($ratingssql,'glossary');

//migrate data_ratings
//data ratings didnt store time created and modified so Im using the times from the record the rating was attached to
$ratingssql = 'select r.id as rid, r.recordid as itemid, r.rating, r.userid, re.timecreated, re.timemodified, d.scale, d.id as mid
from {data_ratings} r inner join {data_records} re on r.recordid=re.id
inner join {data} d on d.id=re.dataid';
echo "migrating data ratings<br>";
$ratingssql = 'SELECT r.id AS rid, r.recordid AS itemid, r.rating, r.userid, re.timecreated, re.timemodified, d.scale, d.id AS mid
FROM {data_ratings} r INNER JOIN {data_records} re ON r.recordid=re.id
INNER JOIN {data} d ON d.id=re.dataid';
$result = $result && upgrade_module_ratings($ratingssql,'data');

//add assesstimestart and assesstimefinish columns to data
Expand All @@ -3133,6 +3131,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2010031602);
}

//upgrade.php was out of step with install.xml for 16 hours. Its theoretically possible someone could
//have done a fresh install during that time with version 2010031602 and wound up with a table called 'ratings'
if ($result && $oldversion < 2010031700) {
$table = new xmldb_table('ratings');

if ( $dbman->table_exists($table) ) {
$dbman->rename_table($table, 'rating');
}

upgrade_main_savepoint($result, 2010031700);
}


return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)

$version = 2010031602; // YYYYMMDD = date of the last version bump
$version = 2010031700; // YYYYMMDD = date of the last version bump
// XX = daily increments

$release = '2.0 dev (Build: 20100317)'; // Human-friendly version name
Expand Down

0 comments on commit 019cf6c

Please sign in to comment.