Merge branch 'MDL-42012-310-alt' of git://github.com/andrewnicols/moodle into MOODLE_...
[moodle.git] / backup / util / factories / restore_factory.class.php
blob46ff79413321705fbbecd2a2c21aa1b1e8216ff5
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * @package moodlecore
20 * @subpackage backup-factories
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 /**
26 * Non instantiable factory class providing different restore object instances
28 * This class contains various methods available in order to easily
29 * create different parts of the restore architecture in an easy way
31 * TODO: Finish phpdocs
33 abstract class restore_factory {
35 public static function get_restore_activity_task($info) {
37 $classname = 'restore_' . $info->modulename . '_activity_task';
38 if (class_exists($classname)) {
39 return new $classname($info->title, $info);
43 public static function get_restore_block_task($blockname, $basepath) {
45 $classname = 'restore_default_block_task';
46 $testname = 'restore_' . $blockname . '_block_task';
47 // If the block has custom backup/restore task class (testname), use it
48 if (class_exists($testname)) {
49 $classname = $testname;
51 return new $classname($blockname, $basepath);
54 public static function get_restore_section_task($info) {
56 return new restore_section_task($info->title, $info);
59 public static function get_restore_course_task($info, $courseid) {
60 global $DB;
62 // Check course exists
63 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
64 throw new restore_task_exception('course_task_course_not_found', $courseid);
67 return new restore_course_task($info->title, $info);