moodle-expcontent/backup/moodle2/restore_expcontent_stepslib.php

74 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2021-11-30 10:20:49 +00:00
<?php
// This file is part of the expcontent 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/>.
/**
* Define all the restore steps that will be used by the restore_expcontent_activity_task.
*
* @package mod_expcontent
* @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.');
/**
* Define the complete expcontent structure for restore, with file and id annotations.
*
* @package mod_expcontent
* @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
*/
class restore_expcontent_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();
// The expcontent instance.
2021-11-30 10:20:49 +00:00
$paths[] = new restore_path_element('expcontent', '/activity/expcontent');
// Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
}
/**
* Handles restoring the expcontent activity.
2021-11-30 10:20:49 +00:00
*
* @param stdClass $data the expcontent data
2021-11-30 10:20:49 +00:00
*/
protected function process_expcontent($data) {
2021-11-30 11:32:05 +00:00
global $DB, $USER;
2021-11-30 10:20:49 +00:00
$data = (object) $data;
$data->course = $this->get_courseid();
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);
$data->usermodified = $USER->id;
// Insert the expcontent record.
2021-11-30 10:20:49 +00:00
$newitemid = $DB->insert_record('expcontent', $data);
// Immediately after inserting record call this.
$this->apply_activity_instance($newitemid);
}
}