moodle-expcontent/backup/moodle2/restore_expcontent_stepslib.php

73 lines
2.6 KiB
PHP

<?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.
$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.
*
* @param stdClass $data the expcontent data
*/
protected function process_expcontent($data) {
global $DB, $USER;
$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.
$newitemid = $DB->insert_record('expcontent', $data);
// Immediately after inserting record call this.
$this->apply_activity_instance($newitemid);
}
}