Commit 775f811a authored by skodak's avatar skodak
Browse files

MDL-16002 rewritten upgrade locking and better upgrade progress tracking;...

MDL-16002 rewritten upgrade locking and better upgrade progress tracking; MDL-16070 Do not use $a[0] syntax in lang packs + various other upgrade improvements and fixes
parent 9deded34
......@@ -32,10 +32,10 @@
* @package
*/
function xmldb_message_email_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_message_email_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
......
......@@ -32,10 +32,10 @@
* @package
*/
function xmldb_message_jabber_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_message_jabber_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
......
......@@ -32,10 +32,10 @@
* @package
*/
function xmldb_message_popup_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_message_popup_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
......
......@@ -16,23 +16,22 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_assignment_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_assignment_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007101511) {
notify('Processing assignment grades, this may take a while if there are many assignments...', 'notifysuccess');
// change grade typo to text if no grades MDL-13920
require_once $CFG->dirroot.'/mod/assignment/lib.php';
// too much debug output
$DB->set_debug(false);
assignment_update_grades();
$DB->set_debug(true);
assignment_upgrade_grades();
upgrade_mod_savepoint($result, 2007101511, 'assignment');
}
......@@ -59,10 +58,11 @@ function xmldb_assignment_upgrade($oldversion=0) {
$pbar = new progress_bar('migrateassignmentfiles', 500, true);
$olddebug = $DB->get_debug();
// $DB->set_debug(false); // lower debug level, there might be many files
$DB->set_debug(false); // lower debug level, there might be many files
$i = 0;
foreach ($rs as $submission) {
$i++;
upgrade_set_timeout(180); // set up timeout, may also abort execution
$basepath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/";
if (!file_exists($basepath)) {
//no files
......
......@@ -2212,41 +2212,60 @@ function assignment_get_user_grades($assignment, $userid=0) {
}
/**
* Update grades by firing grade_updated event
* Update activity grades
*
* @param object $assignment null means all assignments
* @param int $userid specific user only, 0 mean all
* @param object $assignment
* @param int $userid specific user only, 0 means all
*/
function assignment_update_grades($assignment=null, $userid=0, $nullifnone=true) {
function assignment_update_grades($assignment, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if ($assignment != null) {
if ($grades = assignment_get_user_grades($assignment, $userid)) {
foreach($grades as $k=>$v) {
if ($v->rawgrade == -1) {
$grades[$k]->rawgrade = null;
}
if ($assignment->grade == 0) {
assignment_grade_item_update($assignment);
} else if ($grades = assignment_get_user_grades($assignment, $userid)) {
foreach($grades as $k=>$v) {
if ($v->rawgrade == -1) {
$grades[$k]->rawgrade = null;
}
assignment_grade_item_update($assignment, $grades);
} else {
assignment_grade_item_update($assignment);
}
assignment_grade_item_update($assignment, $grades);
} else {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $assignment) {
if ($assignment->grade != 0) {
assignment_update_grades($assignment);
} else {
assignment_grade_item_update($assignment);
}
}
$rs->close();
}
assignment_grade_item_update($assignment);
}
}
/**
* Update all grades in gradebook.
*/
function assignment_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) {
// too much debug output
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('assignmentupgradegrades', 500, true);
$i=0;
foreach ($rs as $assignment) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
assignment_update_grades($assignment);
$pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
upgrade_set_timeout(); // reset to default timeout
}
}
......
......@@ -16,15 +16,18 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_chat_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_chat_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2008072400) {
/// Define table chat_messages_current to be created
......@@ -48,10 +51,8 @@ function xmldb_chat_upgrade($oldversion=0) {
$table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid'));
/// Conditionally launch create table for chat_messages_current
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// create table for chat_messages_current
$dbman->create_table($table);
/// chat savepoint reached
upgrade_mod_savepoint($result, 2008072400, 'chat');
......
......@@ -16,22 +16,16 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_choice_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_choice_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// }
//===== 1.9.0 upgrade line ======//
return $result;
......
......@@ -16,13 +16,14 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_data_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_data_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......
......@@ -798,43 +798,60 @@ function data_get_user_grades($data, $userid=0) {
}
/**
* Update grades by firing grade_updated event
* Update activity grades
*
* @param object $data null means all databases
* @param int $userid specific user only, 0 mean all
* @param object $data
* @param int $userid specific user only, 0 means all
*/
function data_update_grades($data=null, $userid=0, $nullifnone=true) {
function data_update_grades($data, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if ($data != null) {
if ($grades = data_get_user_grades($data, $userid)) {
data_grade_item_update($data, $grades);
if (!$data->assessed) {
data_grade_item_update($data);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
data_grade_item_update($data, $grade);
} else if ($grades = data_get_user_grades($data, $userid)) {
data_grade_item_update($data, $grades);
} else {
data_grade_item_update($data);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
data_grade_item_update($data, $grade);
} else {
$sql = "SELECT d.*, cm.idnumber as cmidnumber
FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $data) {
if ($data->assessed) {
data_update_grades($data, 0, false);
} else {
data_grade_item_update($data);
}
}
$rs->close();
}
data_grade_item_update($data);
}
}
/**
* Update all grades in gradebook.
*/
function data_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT d.*, cm.idnumber AS cmidnumber, d.course AS courseid
FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
if ($rs = $DB->get_recordset_sql($sql)) {
// too much debug output
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('dataupgradegrades', 500, true);
$i=0;
foreach ($rs as $data) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
data_update_grades($data, 0, false);
$pbar->update($i, $count, "Updating Database grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
}
}
......
......@@ -64,7 +64,7 @@
} else if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
if (!$DB->update_record('data_ratings', $oldrating)) {
print_error('cannotupdaterate', 'data', '', array($record->id, $rating));
print_error('cannotupdaterate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating));
}
data_update_grades($data, $record->userid);
......@@ -76,7 +76,7 @@
$newrating->recordid = $record->id;
$newrating->rating = $rating;
if (! $DB->insert_record('data_ratings', $newrating)) {
print_error('cannotinsertrate', 'data', '', array($record->id, $rating));
print_error('cannotinsertrate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating));
}
data_update_grades($data, $record->userid);
}
......
......@@ -16,13 +16,14 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_feedback_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_feedback_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2007012310) {
......
......@@ -16,35 +16,22 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_forum_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_forum_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// }
//===== 1.9.0 upgrade line ======//
if ($result and $oldversion < 2007101511) {
notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
//MDL-13866 - send forum ratins to gradebook again
require_once($CFG->dirroot.'/mod/forum/lib.php');
// too much debug output
$DB->set_debug(false);
forum_update_grades();
$DB->set_debug(true);
forum_upgrade_grades();
upgrade_mod_savepoint($result, 2007101511, 'forum');
}
......
......@@ -1424,45 +1424,62 @@ function forum_get_user_grades($forum, $userid=0) {
}
/**
* Update grades by firing grade_updated event
* Update activity grades
*
* @param object $forum null means all forums
* @param int $userid specific user only, 0 mean all
* @param object $forum
* @param int $userid specific user only, 0 means all
* @param boolean $nullifnone return null if grade does not exist
* @return void
*/
function forum_update_grades($forum=null, $userid=0, $nullifnone=true) {
function forum_update_grades($forum, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if ($forum != null) {
require_once($CFG->libdir.'/gradelib.php');
if ($grades = forum_get_user_grades($forum, $userid)) {
forum_grade_item_update($forum, $grades);
if (!$forum->assessed) {
forum_grade_item_update($forum);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
forum_grade_item_update($forum, $grade);
} else if ($grades = forum_get_user_grades($forum, $userid)) {
forum_grade_item_update($forum, $grades);
} else {
forum_grade_item_update($forum);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
forum_grade_item_update($forum, $grade);
} else {
$sql = "SELECT f.*, cm.idnumber as cmidnumber
FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $forum) {
if ($forum->assessed) {
forum_update_grades($forum, 0, false);
} else {
forum_grade_item_update($forum);
}
}
$rs->close();
}
forum_grade_item_update($forum);
}
}
/**
* Update all grades in gradebook.
*/
function forum_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
if ($rs = $DB->get_recordset_sql($sql)) {
// too much debug output
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('forumupgradegrades', 500, true);
$i=0;
foreach ($rs as $forum) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
forum_update_grades($forum, 0, false);
$pbar->update($i, $count, "Updating Forum grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
}
}
......
......@@ -71,8 +71,7 @@
$oldrating->rating = $rating;
$oldrating->time = time();
if (!$DB->update_record('forum_ratings', $oldrating)) {
print_error('cannotupdaterate', 'forum', '',
array($post->id, $rating));
print_error('cannotupdaterate', 'error', '', (object)array('id'=>$post->id, 'rating'=>$rating));
}
forum_update_grades($forum, $post->userid);
}
......@@ -85,8 +84,7 @@
$newrating->rating = $rating;
if (! $DB->insert_record('forum_ratings', $newrating)) {
print_error('cannotinsertrate', 'forum', '',
array($postid, $rating));
print_error('cannotinsertrate', 'error', '', (object)array('id'=>$postid, 'rating'=>$rating));
}
forum_update_grades($forum, $post->userid);
}
......
......@@ -16,22 +16,16 @@
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_glossary_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_glossary_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// }
//===== 1.9.0 upgrade line ======//
return $result;
......
......@@ -323,43 +323,59 @@ function glossary_get_user_grades($glossary, $userid=0) {
}
/**
* Update grades by firing grade_updated event
* Update activity grades
*
* @param object $glossary null means all glossaries
* @param int $userid specific user only, 0 mean all
* @param int $userid specific user only, 0 means all
*/
function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if ($glossary != null) {
if ($grades = glossary_get_user_grades($glossary, $userid)) {
glossary_grade_item_update($glossary, $grades);
if (!$glossary->assessed) {
glossary_grade_item_update($glossary);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
glossary_grade_item_update($glossary, $grade);
} else if ($grades = glossary_get_user_grades($glossary, $userid)) {
glossary_grade_item_update($glossary, $grades);
} else {
glossary_grade_item_update($glossary);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
glossary_grade_item_update($glossary, $grade);
} else {
$sql = "SELECT g.*, cm.idnumber as cmidnumber
FROM {glossary} g, {course_modules} cm, {modules} m