$this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml'));
}
- if (backup_plan_dbops::require_gradebook_backup($this->get_courseid(), $this->get_backupid())) {
- $this->add_step(new backup_gradebook_structure_step('course_gradebook','gradebook.xml'));
- }
-
-
// Generate the logs file (conditionally)
if ($this->get_setting_value('logs')) {
//$this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
$coursectxid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
$this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid));
+ // Set the backup::VAR_COURSEID setting to course, we'll need that in some steps
+ $courseid = $this->get_courseid();
+ $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $courseid));
+
// Generate the groups file with the final annotated groups and groupings
// including membership based on setting
$this->add_step(new backup_groups_structure_step('groups', 'groups.xml'));
// This must be executed before backup files
$this->add_step(new move_inforef_annotations_to_final('migrate_inforef'));
+ // Generate the gradebook file with categories and course grade items. Do it conditionally, using
+ // execute_condition() so only will be excuted if ALL module grade_items in course have been exported
+ $this->add_step(new backup_gradebook_structure_step('course_gradebook','gradebook.xml'));
+
// Generate the files.xml file with all the (final) annotated files. At the same
// time copy all the files from moodle storage to backup storage (uses custom
// backup_nested_element for that)
*/
class backup_gradebook_structure_step extends backup_structure_step {
+ /**
+ * We need to decide conditionally, based on dynamic information
+ * about the execution of this step. Only will be executed if all
+ * the module gradeitems have been already included in backup
+ */
+ protected function execute_condition() {
+ return backup_plan_dbops::require_gradebook_backup($this->get_courseid(), $this->get_backupid());
+ }
+
protected function define_structure() {
// are we including user info?
//grade_categories
$grade_categories = new backup_nested_element('grade_categories');
- $grade_category = new backup_nested_element('grade_category', null, array('courseid',
- 'parent', 'depth', 'path', 'fullname', 'aggregation', 'keephigh',
+ $grade_category = new backup_nested_element('grade_category', null, array('courseid',
+ 'parent', 'depth', 'path', 'fullname', 'aggregation', 'keephigh',
'dropload', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats',
'timecreated', 'timemodified'));
//if itemtype == manual then item is a calculated item so isn't attached to an activity and we need to back it up here
$grade_items_array = grade_item::fetch_all(array('itemtype' => 'manual', 'courseid' => $this->get_courseid()));
-
+
//$grade_items_array==false and not an empty array if no items. set_source_array() fails if you pass a bool
if ($grade_items_array) {
$grade_item->set_source_array($grade_items_array);