moodle-mod_htmlcert/backup/moodle2/restore_customcert_stepslib.php

137 lines
4.8 KiB
PHP
Raw Normal View History

<?php
2021-11-24 07:29:43 +00:00
// This file is part of the htmlcert module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
2021-11-24 07:29:43 +00:00
* Define all the restore steps that will be used by the restore_htmlcert_activity_task.
*
2021-11-24 07:29:43 +00:00
* @package mod_htmlcert
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
/**
2021-11-24 07:29:43 +00:00
* Define the complete htmlcert structure for restore, with file and id annotations.
2017-02-16 12:12:19 +00:00
*
2021-11-24 07:29:43 +00:00
* @package mod_htmlcert
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
2017-02-16 12:12:19 +00:00
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
2021-11-24 07:29:43 +00:00
class restore_htmlcert_activity_structure_step extends restore_activity_structure_step {
/**
* Define the different items to restore.
*
* @return array the restore paths
*/
protected function define_structure() {
// The array used to store the path to the items we want to restore.
$paths = array();
2021-11-24 07:29:43 +00:00
// The htmlcert instance.
$paths[] = new restore_path_element('htmlcert', '/activity/htmlcert');
// The templates.
2021-11-24 07:29:43 +00:00
$paths[] = new restore_path_element('htmlcert_template', '/activity/htmlcert/template');
// Check if we want the issues as well.
if ($this->get_setting_value('userinfo')) {
2021-11-24 07:29:43 +00:00
$paths[] = new restore_path_element('htmlcert_issue', '/activity/htmlcert/issues/issue');
}
// Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
}
/**
2021-11-24 07:29:43 +00:00
* Handles restoring the htmlcert activity.
*
2021-11-24 07:29:43 +00:00
* @param stdClass $data the htmlcert data
*/
2021-11-24 07:29:43 +00:00
protected function process_htmlcert($data) {
global $DB;
$data = (object) $data;
$data->course = $this->get_courseid();
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);
2021-11-24 07:29:43 +00:00
// Insert the htmlcert record.
$newitemid = $DB->insert_record('htmlcert', $data);
// Immediately after inserting record call this.
$this->apply_activity_instance($newitemid);
}
/**
2021-11-24 07:29:43 +00:00
* Handles restoring a htmlcert templage.
*
2021-11-24 07:29:43 +00:00
* @param stdClass $data the htmlcert data
*/
2021-11-24 07:29:43 +00:00
protected function process_htmlcert_template($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
$data->contextid = $this->task->get_contextid();
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);
2021-11-24 07:29:43 +00:00
$newitemid = $DB->insert_record('htmlcert_templates', $data);
$this->set_mapping('htmlcert_template', $oldid, $newitemid);
2021-11-24 07:29:43 +00:00
// Update the template id for the htmlcert.
$htmlcert = new stdClass();
$htmlcert->id = $this->get_new_parentid('htmlcert');
$htmlcert->templateid = $newitemid;
$DB->update_record('htmlcert', $htmlcert);
}
/**
2021-11-24 07:29:43 +00:00
* Handles restoring a htmlcert issue.
*
2021-11-24 07:29:43 +00:00
* @param stdClass $data the htmlcert data
*/
2021-11-24 07:29:43 +00:00
protected function process_htmlcert_issue($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
2021-11-24 07:29:43 +00:00
$data->htmlcertid = $this->get_new_parentid('htmlcert');
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->userid = $this->get_mappingid('user', $data->userid);
2021-11-24 07:29:43 +00:00
$newitemid = $DB->insert_record('htmlcert_issues', $data);
$this->set_mapping('htmlcert_issue', $oldid, $newitemid);
}
/**
* Called immediately after all the other restore functions.
*/
protected function after_execute() {
parent::after_execute();
// Add the files.
2021-11-24 07:29:43 +00:00
$this->add_related_files('mod_htmlcert', 'intro', null);
// Note - we can't use get_old_contextid() as it refers to the module context.
2021-11-24 07:29:43 +00:00
$this->add_related_files('mod_htmlcert', 'image', null, $this->get_task()->get_info()->original_course_contextid);
}
}