From a243ffeb078e0ff6cc05f820b3ed719ac40d1028 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 15 Dec 2008 21:35:47 +0000 Subject: [PATCH] MDL-17599 scheduled backup: add support for grade history setting + minor XML formatting. Merged from 19_STABLE --- admin/settings/courses.php | 1 + backup/backup_scheduled.php | 4 + backup/backuplib.php | 204 ++++++++++++++++++------------------ lang/en_utf8/moodle.php | 1 + 4 files changed, 108 insertions(+), 102 deletions(-) diff --git a/admin/settings/courses.php b/admin/settings/courses.php index dc2380acf6..c8e545564c 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -143,6 +143,7 @@ if ($hassiteconfig $temp->add(new admin_setting_configcheckbox('backup/backup_sche_userfiles', get_string('userfiles'), get_string('backupuserfileshelp'), 0)); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_coursefiles', get_string('coursefiles'), get_string('backupcoursefileshelp'), 0)); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_sitefiles', get_string('sitefiles'), get_string('backupsitefileshelp'), 0)); + $temp->add(new admin_setting_configcheckbox('backup_sche_gradebook_history', get_string('gradebookhistories', 'grades'), get_string('backupgradebookhistoryhelp'), 0)); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_messages', get_string('messages', 'message'), get_string('backupmessageshelp','message'), 0)); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_blogs', get_string('blogs', 'blog'), get_string('backupblogshelp','blog'), 0)); diff --git a/backup/backup_scheduled.php b/backup/backup_scheduled.php index 00c5ba5013..caa9f3436c 100644 --- a/backup/backup_scheduled.php +++ b/backup/backup_scheduled.php @@ -347,6 +347,9 @@ function schedule_backup_course_configure($course,$starttime = 0) { if (!isset($backup_config->backup_sche_sitefiles)) { $backup_config->backup_sche_sitefiles = 1; } + if (!isset($backup_config->backup_sche_gradebook_history)) { + $backup_config->backup_sche_gradebook_history = 0; + } if (!isset($backup_config->backup_sche_messages)) { $backup_config->backup_sche_messages = 0; } @@ -449,6 +452,7 @@ function schedule_backup_course_configure($course,$starttime = 0) { $preferences->backup_user_files = $backup_config->backup_sche_userfiles; $preferences->backup_course_files = $backup_config->backup_sche_coursefiles; $preferences->backup_site_files = $backup_config->backup_sche_sitefiles; + $preferences->backup_gradebook_history = $backup_config->backup_sche_gradebook_history; $preferences->backup_messages = $backup_config->backup_sche_messages; $preferences->backup_blogs = $backup_config->backup_sche_blogs; $preferences->backup_course = $course->id; diff --git a/backup/backuplib.php b/backup/backuplib.php index 314acd5e3c..f167b243a1 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -570,7 +570,7 @@ fwrite ($bf,full_tag("SITEFILES",3,false,"false")); } //The gradebook histories - if ($preferences->backup_gradebook_history == 1) { + if (empty($CFG->disablegradehistory) && $preferences->backup_gradebook_history == 1) { fwrite ($bf,full_tag("GRADEBOOKHISTORIES",3,false,"true")); } else { fwrite ($bf,full_tag("GRADEBOOKHISTORIES",3,false,"false")); @@ -1575,8 +1575,8 @@ $status = backup_gradebook_item_info($bf,$preferences, $backupall); - // backup gradebook histories - if ($preferences->backup_gradebook_history) { + // backup gradebook histories (only if grade history is enabled and selected) + if (empty($CFG->disablegradehistory) && $preferences->backup_gradebook_history) { $status = backup_gradebook_outcomes_history($bf, $preferences); $status = backup_gradebook_categories_history_info($bf, $preferences); $status = backup_gradebook_items_history_info($bf, $preferences); @@ -1835,28 +1835,28 @@ // find all grade categories history if ($chs = $DB->get_records('grade_categories_history', array('courseid'=>$preferences->backup_course))) { - fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORIES",3,true)); foreach ($chs as $ch) { - fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORY",6,true)); - fwrite ($bf,full_tag("ID",7,false,$ch->id)); - fwrite ($bf,full_tag("ACTION",7,false,$ch->action)); - fwrite ($bf,full_tag("OLDID",7,false,$ch->oldid)); - fwrite ($bf,full_tag("SOURCE",7,false,$ch->source)); - fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$ch->timemodified)); - fwrite ($bf,full_tag("LOGGEDUSER",7,false,$ch->loggeduser)); - fwrite ($bf,full_tag("PARENT",7,false,$ch->parent)); - fwrite ($bf,full_tag("DEPTH",7,false,$ch->depth)); - fwrite ($bf,full_tag("PATH",7,false,$ch->path)); - fwrite ($bf,full_tag("FULLNAME",7,false,$ch->fullname)); - fwrite ($bf,full_tag("AGGRETGATION",7,false,$ch->aggregation)); - fwrite ($bf,full_tag("KEEPHIGH",7,false,$ch->keephigh)); - fwrite ($bf,full_tag("DROPLOW",7,false,$ch->droplow)); - fwrite ($bf,full_tag("AGGREGATEONLYGRADED",7,false,$ch->aggregateonlygraded)); - fwrite ($bf,full_tag("AGGREGATEOUTCOMES",7,false,$ch->aggregateoutcomes)); - fwrite ($bf,full_tag("AGGREGATESUBCATS",7,false,$ch->aggregatesubcats)); - fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORY",6,true)); - } - $status = fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORY",4,true)); + fwrite ($bf,full_tag("ID",5,false,$ch->id)); + fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); + fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); + fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); + fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); + fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); + fwrite ($bf,full_tag("PARENT",5,false,$ch->parent)); + fwrite ($bf,full_tag("DEPTH",5,false,$ch->depth)); + fwrite ($bf,full_tag("PATH",5,false,$ch->path)); + fwrite ($bf,full_tag("FULLNAME",5,false,$ch->fullname)); + fwrite ($bf,full_tag("AGGRETGATION",5,false,$ch->aggregation)); + fwrite ($bf,full_tag("KEEPHIGH",5,false,$ch->keephigh)); + fwrite ($bf,full_tag("DROPLOW",5,false,$ch->droplow)); + fwrite ($bf,full_tag("AGGREGATEONLYGRADED",5,false,$ch->aggregateonlygraded)); + fwrite ($bf,full_tag("AGGREGATEOUTCOMES",5,false,$ch->aggregateoutcomes)); + fwrite ($bf,full_tag("AGGREGATESUBCATS",5,false,$ch->aggregatesubcats)); + fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORY",4,true)); + } + $status = fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORIES",3,true)); } return $status; } @@ -1870,39 +1870,39 @@ FROM {grade_grades_history} ggh JOIN {grade_item} gi ON gi.id = ggh.itemid WHERE gi.courseid = ?", array($preferences->backup_course))) { - fwrite ($bf,start_tag("GRADE_GRADES_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_GRADES_HISTORIES",3,true)); foreach ($chs as $ch) { /// Grades are only sent to backup if the user is one target user if (backup_getid($preferences->backup_unique_code, 'user', $ch->userid)) { - fwrite ($bf,start_tag("GRADE_GRADES_HISTORY",6,true)); - fwrite ($bf,full_tag("ID",7,false,$ch->id)); - fwrite ($bf,full_tag("ACTION",7,false,$ch->action)); - fwrite ($bf,full_tag("OLDID",7,false,$ch->oldid)); - fwrite ($bf,full_tag("SOURCE",7,false,$ch->source)); - fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$ch->timemodified)); - fwrite ($bf,full_tag("LOGGEDUSER",7,false,$ch->loggeduser)); - fwrite ($bf,full_tag("ITEMID",7,false,$ch->itemid)); - fwrite ($bf,full_tag("USERID",7,false,$ch->userid)); - fwrite ($bf,full_tag("RAWGRADE",7,false,$ch->rawgrade)); - fwrite ($bf,full_tag("RAWGRADEMAX",7,false,$ch->rawgrademax)); - fwrite ($bf,full_tag("RAWGRADEMIN",7,false,$ch->rawgrademin)); - fwrite ($bf,full_tag("RAWSCALEID",7,false,$ch->rawscaleid)); - fwrite ($bf,full_tag("USERMODIFIED",7,false,$ch->usermodified)); - fwrite ($bf,full_tag("FINALGRADE",7,false,$ch->finalgrade)); - fwrite ($bf,full_tag("HIDDEN",7,false,$ch->hidden)); - fwrite ($bf,full_tag("LOCKED",7,false,$ch->locked)); - fwrite ($bf,full_tag("LOCKTIME",7,false,$ch->locktime)); - fwrite ($bf,full_tag("EXPORTED",7,false,$ch->exported)); - fwrite ($bf,full_tag("OVERRIDDEN",7,false,$ch->overridden)); - fwrite ($bf,full_tag("EXCLUDED",7,false,$ch->excluded)); - fwrite ($bf,full_tag("FEEDBACK",7,false,$ch->feedback)); - fwrite ($bf,full_tag("FEEDBACKFORMAT",7,false,$ch->feedbackformat)); - fwrite ($bf,full_tag("INFORMATION",7,false,$ch->information)); - fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$ch->informationformat)); - fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",6,true)); - } - } - $status = fwrite ($bf,end_tag("GRADE_GRADES_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_GRADES_HISTORY",4,true)); + fwrite ($bf,full_tag("ID",5,false,$ch->id)); + fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); + fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); + fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); + fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); + fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); + fwrite ($bf,full_tag("ITEMID",5,false,$ch->itemid)); + fwrite ($bf,full_tag("USERID",5,false,$ch->userid)); + fwrite ($bf,full_tag("RAWGRADE",5,false,$ch->rawgrade)); + fwrite ($bf,full_tag("RAWGRADEMAX",5,false,$ch->rawgrademax)); + fwrite ($bf,full_tag("RAWGRADEMIN",5,false,$ch->rawgrademin)); + fwrite ($bf,full_tag("RAWSCALEID",5,false,$ch->rawscaleid)); + fwrite ($bf,full_tag("USERMODIFIED",5,false,$ch->usermodified)); + fwrite ($bf,full_tag("FINALGRADE",5,false,$ch->finalgrade)); + fwrite ($bf,full_tag("HIDDEN",5,false,$ch->hidden)); + fwrite ($bf,full_tag("LOCKED",5,false,$ch->locked)); + fwrite ($bf,full_tag("LOCKTIME",5,false,$ch->locktime)); + fwrite ($bf,full_tag("EXPORTED",5,false,$ch->exported)); + fwrite ($bf,full_tag("OVERRIDDEN",5,false,$ch->overridden)); + fwrite ($bf,full_tag("EXCLUDED",5,false,$ch->excluded)); + fwrite ($bf,full_tag("FEEDBACK",5,false,$ch->feedback)); + fwrite ($bf,full_tag("FEEDBACKFORMAT",5,false,$ch->feedbackformat)); + fwrite ($bf,full_tag("INFORMATION",5,false,$ch->information)); + fwrite ($bf,full_tag("INFORMATIONFORMAT",5,false,$ch->informationformat)); + fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",4,true)); + } + } + $status = fwrite ($bf,end_tag("GRADE_GRADES_HISTORIES",3,true)); } return $status; } @@ -1913,43 +1913,43 @@ // find all grade categories history if ($chs = $DB->get_records('grade_items_history', array('courseid'=>$preferences->backup_course))) { - fwrite ($bf,start_tag("GRADE_ITEM_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_ITEM_HISTORIES",3,true)); foreach ($chs as $ch) { - fwrite ($bf,start_tag("GRADE_ITEM_HISTORY",6,true)); - fwrite ($bf,full_tag("ID",7,false,$ch->id)); - fwrite ($bf,full_tag("ACTION",7,false,$ch->action)); - fwrite ($bf,full_tag("OLDID",7,false,$ch->oldid)); - fwrite ($bf,full_tag("SOURCE",7,false,$ch->source)); - fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$ch->timemodified)); - fwrite ($bf,full_tag("LOGGEDUSER",7,false,$ch->loggeduser)); - fwrite ($bf,full_tag("CATEGORYID",7,false,$ch->categoryid)); - fwrite ($bf,full_tag("ITEMNAME",7,false,$ch->itemname)); - fwrite ($bf,full_tag("ITEMTYPE",7,false,$ch->itemtype)); - fwrite ($bf,full_tag("ITEMMODULE",7,false,$ch->itemmodule)); - fwrite ($bf,full_tag("ITEMINSTANCE",7,false,$ch->iteminstance)); - fwrite ($bf,full_tag("ITEMNUMBER",7,false,$ch->itemnumber)); - fwrite ($bf,full_tag("ITEMINFO",7,false,$ch->iteminfo)); - fwrite ($bf,full_tag("IDNUMBER",7,false,$ch->idnumber)); - fwrite ($bf,full_tag("CALCULATION",7,false,$ch->calculation)); - fwrite ($bf,full_tag("GRADETYPE",7,false,$ch->gradetype)); - fwrite ($bf,full_tag("GRADEMAX",7,false,$ch->grademax)); - fwrite ($bf,full_tag("GRADEMIN",7,false,$ch->grademin)); - fwrite ($bf,full_tag("SCALEID",7,false,$ch->scaleid)); - fwrite ($bf,full_tag("OUTCOMEID",7,false,$ch->outcomeid)); - fwrite ($bf,full_tag("GRADEPASS",7,false,$ch->gradepass)); - fwrite ($bf,full_tag("MULTFACTOR",7,false,$ch->multfactor)); - fwrite ($bf,full_tag("PLUSFACTOR",7,false,$ch->plusfactor)); - fwrite ($bf,full_tag("AGGREGATIONCOEF",7,false,$ch->aggregationcoef)); - fwrite ($bf,full_tag("SORTORDER",7,false,$ch->sortorder)); + fwrite ($bf,start_tag("GRADE_ITEM_HISTORY",4,true)); + fwrite ($bf,full_tag("ID",5,false,$ch->id)); + fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); + fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); + fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); + fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); + fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); + fwrite ($bf,full_tag("CATEGORYID",5,false,$ch->categoryid)); + fwrite ($bf,full_tag("ITEMNAME",5,false,$ch->itemname)); + fwrite ($bf,full_tag("ITEMTYPE",5,false,$ch->itemtype)); + fwrite ($bf,full_tag("ITEMMODULE",5,false,$ch->itemmodule)); + fwrite ($bf,full_tag("ITEMINSTANCE",5,false,$ch->iteminstance)); + fwrite ($bf,full_tag("ITEMNUMBER",5,false,$ch->itemnumber)); + fwrite ($bf,full_tag("ITEMINFO",5,false,$ch->iteminfo)); + fwrite ($bf,full_tag("IDNUMBER",5,false,$ch->idnumber)); + fwrite ($bf,full_tag("CALCULATION",5,false,$ch->calculation)); + fwrite ($bf,full_tag("GRADETYPE",5,false,$ch->gradetype)); + fwrite ($bf,full_tag("GRADEMAX",5,false,$ch->grademax)); + fwrite ($bf,full_tag("GRADEMIN",5,false,$ch->grademin)); + fwrite ($bf,full_tag("SCALEID",5,false,$ch->scaleid)); + fwrite ($bf,full_tag("OUTCOMEID",5,false,$ch->outcomeid)); + fwrite ($bf,full_tag("GRADEPASS",5,false,$ch->gradepass)); + fwrite ($bf,full_tag("MULTFACTOR",5,false,$ch->multfactor)); + fwrite ($bf,full_tag("PLUSFACTOR",5,false,$ch->plusfactor)); + fwrite ($bf,full_tag("AGGREGATIONCOEF",5,false,$ch->aggregationcoef)); + fwrite ($bf,full_tag("SORTORDER",5,false,$ch->sortorder)); //fwrite ($bf,full_tag("DISPLAY",7,false,$ch->display)); //fwrite ($bf,full_tag("DECIMALS",7,false,$ch->decimals)); - fwrite ($bf,full_tag("HIDDEN",7,false,$ch->hidden)); - fwrite ($bf,full_tag("LOCKED",7,false,$ch->locked)); - fwrite ($bf,full_tag("LOCKTIME",7,false,$ch->locktime)); - fwrite ($bf,full_tag("NEEDSUPDATE",7,false,$ch->needsupdate)); - fwrite ($bf,end_tag("GRADE_ITEM_HISTORY",6,true)); + fwrite ($bf,full_tag("HIDDEN",5,false,$ch->hidden)); + fwrite ($bf,full_tag("LOCKED",5,false,$ch->locked)); + fwrite ($bf,full_tag("LOCKTIME",5,false,$ch->locktime)); + fwrite ($bf,full_tag("NEEDSUPDATE",5,false,$ch->needsupdate)); + fwrite ($bf,end_tag("GRADE_ITEM_HISTORY",4,true)); } - $status = fwrite ($bf,end_tag("GRADE_ITEM_HISTORIES",5,true)); + $status = fwrite ($bf,end_tag("GRADE_ITEM_HISTORIES",3,true)); } return $status; @@ -1961,22 +1961,22 @@ // find all grade categories history if ($chs = $DB->get_records('grade_outcomes_history', array('courseid'=>$preferences->backup_course))) { - fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORIES",3,true)); foreach ($chs as $ch) { - fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORY",6,true)); - fwrite ($bf,full_tag("ID",7,false,$ch->id)); - fwrite ($bf,full_tag("OLDID",7,false,$ch->oldid)); - fwrite ($bf,full_tag("ACTION",7,false,$ch->action)); - fwrite ($bf,full_tag("SOURCE",7,false,$ch->source)); - fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$ch->timemodified)); - fwrite ($bf,full_tag("LOGGEDUSER",7,false,$ch->loggeduser)); - fwrite ($bf,full_tag("SHORTNAME",7,false,$ch->shortname)); - fwrite ($bf,full_tag("FULLNAME",7,false,$ch->fullname)); - fwrite ($bf,full_tag("SCALEID",7,false,$ch->scaleid)); - fwrite ($bf,full_tag("DESCRIPTION",7,false,$ch->description)); - fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORY",6,true)); - } - $status = fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORIES",5,true)); + fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORY",4,true)); + fwrite ($bf,full_tag("ID",5,false,$ch->id)); + fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); + fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); + fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); + fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); + fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); + fwrite ($bf,full_tag("SHORTNAME",5,false,$ch->shortname)); + fwrite ($bf,full_tag("FULLNAME",5,false,$ch->fullname)); + fwrite ($bf,full_tag("SCALEID",5,false,$ch->scaleid)); + fwrite ($bf,full_tag("DESCRIPTION",5,false,$ch->description)); + fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORY",4,true)); + } + $status = fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORIES",3,true)); } return $status; } diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 35604f57d3..2443c054cd 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -151,6 +151,7 @@ $string['backupexecuteathelp'] = 'Choose what time automated backups should run $string['backupfailed'] = 'Some of your courses weren\'t saved!!'; $string['backupfilename'] = 'backup'; $string['backupfinished'] = 'Backup completed successfully'; +$string['backupgradebookhistoryhelp'] = 'If enabled then gradebook history will be included in automated backups. Note that grade history must not be disabled in server settings (disablegradehistory) in order for this to work'; $string['backupincludemoduleshelp'] = 'Choose whether you want to include course modules, with or without user data, in automated backups'; $string['backupincludemoduleuserdatahelp'] = 'Choose whether you want to include module user data in automated backups.'; $string['backupkeephelp'] = 'How many recent backups for each course do you want to keep? (older ones will be deleted automatically)'; -- 2.39.5