MDL-37774 Do not pass trailing slash if the method does not want it
[moodle.git] / mod / folder / backup / moodle1 / lib.php
CommitLineData
5da3af58
AD
1<?php
2
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.
14//
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/>.
17
18/**
19 * Provides support for the conversion of moodle1 backup to the moodle2 format
20 *
21 * @package mod
22 * @subpackage folder
23 * @copyright 2011 Andrew Davis <andrew@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29/**
30 * Folder conversion handler. This resource handler is called by moodle1_mod_resource_handler
31 */
9e3e8c80 32class moodle1_mod_folder_handler extends moodle1_resource_successor_handler {
93dd33b4 33
5da3af58
AD
34 /** @var moodle1_file_manager instance */
35 protected $fileman = null;
36
5da3af58
AD
37 /**
38 * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
39 * Called by moodle1_mod_resource_handler::process_resource()
40 */
caee6e6c 41 public function process_legacy_resource(array $data, array $raw = null) {
5da3af58 42 // get the course module id and context id
93dd33b4
DM
43 $instanceid = $data['id'];
44 $currentcminfo = $this->get_cminfo($instanceid);
45 $moduleid = $currentcminfo['id'];
46 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
5da3af58 47
93dd33b4
DM
48 // convert legacy data into the new folder record
49 $folder = array();
50 $folder['id'] = $data['id'];
51 $folder['name'] = $data['name'];
52 $folder['intro'] = $data['intro'];
53 $folder['introformat'] = $data['introformat'];
54 $folder['revision'] = 1;
55 $folder['timemodified'] = $data['timemodified'];
56
57 // get a fresh new file manager for this instance
58 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_folder');
5da3af58 59
93dd33b4 60 // migrate the files embedded into the intro field
baa44e3d
DM
61 $this->fileman->filearea = 'intro';
62 $this->fileman->itemid = 0;
63 $folder['intro'] = moodle1_converter::migrate_referenced_files($folder['intro'], $this->fileman);
5da3af58 64
93dd33b4
DM
65 // migrate the folder files
66 $this->fileman->filearea = 'content';
67 $this->fileman->itemid = 0;
b3c00549
DM
68 if (empty($data['reference'])) {
69 $this->fileman->migrate_directory('course_files');
70 } else {
71 $this->fileman->migrate_directory('course_files/'.$data['reference']);
72 }
5da3af58 73
93dd33b4
DM
74 // write folder.xml
75 $this->open_xml_writer("activities/folder_{$moduleid}/folder.xml");
76 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
77 'modulename' => 'folder', 'contextid' => $contextid));
78 $this->write_xml('folder', $folder, array('/folder/id'));
5da3af58
AD
79 $this->xmlwriter->end_tag('activity');
80 $this->close_xml_writer();
81
93dd33b4
DM
82 // write inforef.xml
83 $this->open_xml_writer("activities/folder_{$moduleid}/inforef.xml");
5da3af58
AD
84 $this->xmlwriter->begin_tag('inforef');
85 $this->xmlwriter->begin_tag('fileref');
86 foreach ($this->fileman->get_fileids() as $fileid) {
87 $this->write_xml('file', array('id' => $fileid));
88 }
89 $this->xmlwriter->end_tag('fileref');
90 $this->xmlwriter->end_tag('inforef');
91 $this->close_xml_writer();
92 }
9e3e8c80 93}