/** * Processing functions go here * * @global moodledatabase $DB * @param stdClass $data */ public function process_course($data) { global $CFG, $DB; $data = (object) $data; $fullname = $this->get_setting_value('course_fullname'); $shortname = $this->get_setting_value('course_shortname'); $startdate = $this->get_setting_value('course_startdate'); // Calculate final course names, to avoid dupes list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname); // Need to change some fields before updating the course record $data->id = $this->get_courseid(); $data->fullname = $fullname; $data->shortname = $shortname; // Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by // another course on this site. $context = context::instance_by_id($this->task->get_contextid()); if (!empty($data->idnumber) && has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid()) && $this->task->is_samesite() && !$DB->record_exists('course', array('idnumber' => $data->idnumber))) { // Do not reset idnumber. } else { $data->idnumber = ''; } // Any empty value for course->hiddensections will lead to 0 (default, show collapsed). // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532 if (empty($data->hiddensections)) { $data->hiddensections = 0; } // Set legacyrestrictmodules to true if the course was resticting modules. If so // then we will need to process restricted modules after execution. $this->legacyrestrictmodules = !empty($data->restrictmodules); $data->startdate = $this->apply_date_offset($data->startdate); if ($data->defaultgroupingid) { $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid); } if (empty($CFG->enablecompletion)) { $data->enablecompletion = 0; $data->completionstartonenrol = 0; $data->completionnotify = 0; } $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search if (!array_key_exists($data->lang, $languages)) { $data->lang = ''; } $themes = get_list_of_themes(); // Get themes for quick search later if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) { $data->theme = ''; } // Check if this is an old SCORM course format. if ($data->format == 'scorm') { $data->format = 'singleactivity'; $data->activitytype = 'scorm'; } // Course record ready, update it $DB->update_record('course', $data); course_get_format($data)->update_course_format_options($data); // Role name aliases restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid()); }
/** * Processing functions go here * * @global moodledatabase $DB * @param stdClass $data */ public function process_course($data) { global $CFG, $DB; $data = (object)$data; $oldid = $data->id; // We'll need this later $fullname = $this->get_setting_value('course_fullname'); $shortname = $this->get_setting_value('course_shortname'); $startdate = $this->get_setting_value('course_startdate'); // Calculate final course names, to avoid dupes list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname); // Need to change some fields before updating the course record $data->id = $this->get_courseid(); $data->fullname = $fullname; $data->shortname= $shortname; $data->idnumber = ''; // Only restrict modules if original course was and target site too for new courses $data->restrictmodules = $data->restrictmodules && !empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor == 'all'; $data->startdate= $this->apply_date_offset($data->startdate); if ($data->defaultgroupingid) { $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid); } if (empty($CFG->enablecompletion)) { $data->enablecompletion = 0; $data->completionstartonenrol = 0; $data->completionnotify = 0; } $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search if (!array_key_exists($data->lang, $languages)) { $data->lang = ''; } $themes = get_list_of_themes(); // Get themes for quick search later if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) { $data->theme = ''; } // Course record ready, update it $DB->update_record('course', $data); // Role name aliases restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid()); }
/** * Processes the destination stage. * @return bool * @throws coding_exception * @throws restore_ui_exception */ public function process() { global $CFG, $DB; if (!file_exists("{$CFG->tempdir}/backup/" . $this->filepath) || !is_dir("{$CFG->tempdir}/backup/" . $this->filepath)) { throw new restore_ui_exception('invalidrestorepath'); } if (optional_param('searchcourses', false, PARAM_BOOL)) { return false; } $this->target = optional_param('target', backup::TARGET_NEW_COURSE, PARAM_INT); $targetid = optional_param('targetid', null, PARAM_INT); if (!is_null($this->target) && !is_null($targetid) && confirm_sesskey()) { if ($this->target == backup::TARGET_NEW_COURSE) { list($fullname, $shortname) = restore_dbops::calculate_course_names(0, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup')); $this->courseid = restore_dbops::create_new_course($fullname, $shortname, $targetid); } else { $this->courseid = $targetid; } return $DB->record_exists('course', array('id' => $this->courseid)); } return false; }
/** * Processing functions go here * * @global moodledatabase $DB * @param stdClass $data */ public function process_course($data) { global $CFG, $DB; $data = (object) $data; $fullname = $this->get_setting_value('course_fullname'); $shortname = $this->get_setting_value('course_shortname'); $startdate = $this->get_setting_value('course_startdate'); // Calculate final course names, to avoid dupes list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname); // Need to change some fields before updating the course record $data->id = $this->get_courseid(); $data->fullname = $fullname; $data->shortname = $shortname; $context = get_context_instance_by_id($this->task->get_contextid()); if (has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) { $data->idnumber = ''; } else { unset($data->idnumber); } // Any empty value for course->hiddensections will lead to 0 (default, show collapsed). // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532 if (empty($data->hiddensections)) { $data->hiddensections = 0; } // Only restrict modules if original course was and target site too for new courses $data->restrictmodules = $data->restrictmodules && !empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor == 'all'; $data->startdate = $this->apply_date_offset($data->startdate); if ($data->defaultgroupingid) { $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid); } if (empty($CFG->enablecompletion)) { $data->enablecompletion = 0; $data->completionstartonenrol = 0; $data->completionnotify = 0; } $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search if (!array_key_exists($data->lang, $languages)) { $data->lang = ''; } $themes = get_list_of_themes(); // Get themes for quick search later if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) { $data->theme = ''; } // Course record ready, update it $DB->update_record('course', $data); // Role name aliases restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid()); }
/** * Processing functions go here * * @global moodledatabase $DB * @param stdClass $data */ public function process_course($data) { global $CFG, $DB; $data = (object) $data; $coursetags = isset($data->tags['tag']) ? $data->tags['tag'] : array(); $coursemodules = isset($data->allowed_modules['module']) ? $data->allowed_modules['module'] : array(); $oldid = $data->id; // We'll need this later $fullname = $this->get_setting_value('course_fullname'); $shortname = $this->get_setting_value('course_shortname'); $startdate = $this->get_setting_value('course_startdate'); // Calculate final course names, to avoid dupes list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname); // Need to change some fields before updating the course record $data->id = $this->get_courseid(); $data->fullname = $fullname; $data->shortname = $shortname; $data->idnumber = ''; // Category is set by UI when choosing the destination unset($data->category); $data->startdate = $this->apply_date_offset($data->startdate); if ($data->defaultgroupingid) { $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid); } if (empty($CFG->enablecompletion)) { $data->enablecompletion = 0; $data->completionstartonenrol = 0; $data->completionnotify = 0; } $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search if (!array_key_exists($data->lang, $languages)) { $data->lang = ''; } $themes = get_list_of_themes(); // Get themes for quick search later if (!in_array($data->theme, $themes) || empty($CFG->allowcoursethemes)) { $data->theme = ''; } // Course record ready, update it $DB->update_record('course', $data); // Course tags if (!empty($CFG->usetags) && isset($coursetags)) { // if enabled in server and present in backup $tags = array(); foreach ($coursetags as $coursetag) { $coursetag = (object) $coursetag; $tags[] = $coursetag->rawname; } tag_set('course', $this->get_courseid(), $tags); } // Course allowed modules if (!empty($data->restrictmodules) && !empty($coursemodules)) { $available = get_plugin_list('mod'); foreach ($coursemodules as $coursemodule) { $mname = $coursemodule['modulename']; if (array_key_exists($mname, $available)) { if ($module = $DB->get_record('modules', array('name' => $mname, 'visible' => 1))) { $rec = new stdclass(); $rec->course = $this->get_courseid(); $rec->module = $module->id; if (!$DB->record_exists('course_allowed_modules', (array) $rec)) { $DB->insert_record('course_allowed_modules', $rec); } } } } } // Role name aliases restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid()); }
require_login($course, null, $cm); require_capability('moodle/restore:restorecourse', $context); if ($stage & restore_ui::STAGE_CONFIRM + restore_ui::STAGE_DESTINATION) { $restore = restore_ui::engage_independent_stage($stage, $contextid); } else { if ($_POST['searchcourses'] || !$_POST['targetid']) { // $restore = restore_ui::engage_independent_stage($stage, $contextid); $restore = restore_ui::engage_independent_stage(restore_ui::STAGE_DESTINATION, $contextid); $restore->process(); } else { $target = required_param('target', PARAM_INT); $filepath = $_SESSION['filepath']; if ($target == backup::TARGET_NEW_COURSE) { $transaction = $DB->start_delegated_transaction(); $targetid = required_param('targetid', PARAM_INT); list($fullname, $shortname) = restore_dbops::calculate_course_names($course->id, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup')); $courseid = restore_dbops::create_new_course($fullname, $shortname, $targetid); $controller = new restore_controller($filepath, $courseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, $target); $controller->execute_precheck(); $controller->execute_plan(); $transaction->allow_commit(); } elseif ($target == backup::TARGET_CURRENT_DELETING || $target == backup::TARGET_CURRENT_ADDING) { $transaction = $DB->start_delegated_transaction(); $courseid = $course->id; if ($target == backup::TARGET_CURRENT_DELETING) { $options = array(); $options['keep_roles_and_enrolments'] = new restore_course_generic_setting('keep_roles_and_enrolments', base_setting::IS_BOOLEAN, true); $options['keep_groups_and_groupings'] = new restore_course_generic_setting('keep_groups_and_groupings', base_setting::IS_BOOLEAN, true); restore_dbops::delete_course_content($courseid, $options); } $controller = new restore_controller($filepath, $courseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, $target);