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
......@@ -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_lesson_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_lesson_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......
......@@ -385,43 +385,57 @@ function lesson_get_user_grades($lesson, $userid=0) {
/**
* Update grades in central gradebook
*
* @param object $lesson null means all lessons
* @param int $userid specific user only, 0 mean all
* @param object $lesson
* @param int $userid specific user only, 0 means all
*/
function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) {
function lesson_update_grades($lesson, $userid=0, $nullifnone=true) {
global $CFG, $DB;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
}
require_once($CFG->libdir.'/gradelib.php');
if ($lesson != null) {
if ($grades = lesson_get_user_grades($lesson, $userid)) {
lesson_grade_item_update($lesson, $grades);
if ($lesson->grade == 0) {
lesson_grade_item_update($lesson);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
lesson_grade_item_update($lesson, $grade);
} else if ($grades = lesson_get_user_grades($lesson, $userid)) {
lesson_grade_item_update($lesson, $grades);
} else {
lesson_grade_item_update($lesson);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
lesson_grade_item_update($lesson, $grade);
} else {
$sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid
FROM {lesson} l, {course_modules} cm, {modules} m
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $lesson) {
if ($lesson->grade != 0) {
lesson_update_grades($lesson, 0, false);
} else {
lesson_grade_item_update($lesson);
}
}
$rs->close();
lesson_grade_item_update($lesson);
}
}
/**
* Update all grades in gradebook.
*/
function lesson_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {lesson} l, {course_modules} cm, {modules} m
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid
FROM {lesson} l, {course_modules} cm, {modules} m
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
if ($rs = $DB->get_recordset_sql($sql)) {
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('lessonupgradegrades', 500, true);
$i=0;
foreach ($rs as $lesson) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
lesson_update_grades($lesson, 0, false);
$pbar->update($i, $count, "Updating Lesson grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
}
}
......
......@@ -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_quiz_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_quiz_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......
......@@ -310,43 +310,57 @@ function quiz_format_grade($quiz, $grade) {
/**
* Update grades in central gradebook
*
* @param object $quiz null means all quizs
* @param int $userid specific user only, 0 mean all
* @param object $quiz
* @param int $userid specific user only, 0 means all
*/
function quiz_update_grades($quiz=null, $userid=0, $nullifnone=true) {
function quiz_update_grades($quiz, $userid=0, $nullifnone=true) {
global $CFG, $DB;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
}
require_once($CFG->libdir.'/gradelib.php');
if ($quiz != null) {
if ($grades = quiz_get_user_grades($quiz, $userid)) {
quiz_grade_item_update($quiz, $grades);
if ($quiz->grade == 0) {
quiz_grade_item_update($quiz);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
quiz_grade_item_update($quiz, $grade);
} else if ($grades = quiz_get_user_grades($quiz, $userid)) {
quiz_grade_item_update($quiz, $grades);
} else {
quiz_grade_item_update($quiz);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
quiz_grade_item_update($quiz, $grade);
} else {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
FROM {quiz} a, {course_modules} cm, {modules} m
WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $quiz) {
if ($quiz->grade != 0) {
quiz_update_grades($quiz, 0, false);
} else {
quiz_grade_item_update($quiz);
}
}
$rs->close();
quiz_grade_item_update($quiz);
}
}
/**
* Update all grades in gradebook.
*/
function quiz_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {quiz} a, {course_modules} cm, {modules} m
WHERE m.name='quiz' 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 {quiz} a, {course_modules} cm, {modules} m
WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) {
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('quizupgradegrades', 500, true);
$i=0;
foreach ($rs as $quiz) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
quiz_update_grades($quiz, 0, false);
$pbar->update($i, $count, "Updating Quiz grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
}
}
......
......@@ -20,7 +20,7 @@ class page_quiz extends page_generic_activity {
function init_quick($data) {
if(empty($data->pageid)) {
print_error('cannotinitpage', '', '', null);
print_error('cannotinitpage', 'debug', '', (object)array('name'=>'quiz', 'id'=>'?'));
}
$this->activityname = 'quiz';
parent::init_quick($data);
......
<?php // $Id$
function xmldb_quizreport_overview_upgrade($oldversion=0) {
function xmldb_quizreport_overview_upgrade($oldversion) {
global $CFG, $DB;
global $CFG, $THEME, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......
<?php // $Id$
function xmldb_quizreport_statistics_upgrade($oldversion=0) {
function xmldb_quizreport_statistics_upgrade($oldversion) {
global $DB;
......
......@@ -16,21 +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_resource_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_resource_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_scorm_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_scorm_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......@@ -34,7 +35,7 @@ function xmldb_scorm_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'grademethod');
/// Launch add field whatgrade
if(!$dbman->field_exists($table,$field)) {
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
......
......@@ -441,39 +441,54 @@ function scorm_get_user_grades($scorm, $userid=0) {
/**
* Update grades in central gradebook
*
* @param object $scorm null means all scormbases
* @param object $scorm
* @param int $userid specific user only, 0 mean all
*/
function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
function scorm_update_grades($scorm, $userid=0, $nullifnone=true) {
global $CFG, $DB;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
}
require_once($CFG->libdir.'/gradelib.php');
if ($scorm != null) {
if ($grades = scorm_get_user_grades($scorm, $userid)) {
scorm_grade_item_update($scorm, $grades);
if ($grades = scorm_get_user_grades($scorm, $userid)) {
scorm_grade_item_update($scorm, $grades);
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
scorm_grade_item_update($scorm, $grade);
} else {
scorm_grade_item_update($scorm);
}
} else if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
scorm_grade_item_update($scorm, $grade);
} else {
$sql = "SELECT s.*, cm.idnumber as cmidnumber
FROM {scorm} s, {course_modules} cm, {modules} m
WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $scorm) {
scorm_update_grades($scorm, 0, false);
}
$rs->close();
scorm_grade_item_update($scorm);
}
}
/**
* Update all grades in gradebook.
*/
function scorm_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {scorm} s, {course_modules} cm, {modules} m
WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid
FROM {scorm} s, {course_modules} cm, {modules} m
WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
if ($rs = $DB->get_recordset_sql($sql)) {
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('scormupgradegrades', 500, true);
$i=0;
foreach ($rs as $scorm) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
scorm_update_grades($scorm, 0, false);
$pbar->update($i, $count, "Updating Scorm grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
}
}
......
......@@ -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_survey_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_survey_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,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_wiki_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_wiki_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,11 +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_qtype_calculated_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_calculated_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
......
......@@ -16,11 +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_qtype_datasetdependent_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_datasetdependent_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
......
......@@ -16,11 +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_qtype_essay_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_essay_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
......
......@@ -16,11 +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_qtype_match_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_match_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
......
......@@ -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_qtype_multianswer_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_multianswer_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
/// }
if ($result && $oldversion < 2008050800) {
question_multianswer_fix_subquestion_parents_and_categories();
}
......
......@@ -16,11 +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_qtype_multichoice_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_multichoice_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
return $result;
......
......@@ -16,11 +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_qtype_numerical_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_numerical_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
......
......@@ -16,11 +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_qtype_randomsamatch_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
function xmldb_qtype_randomsamatch_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment