Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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