Merge branch 'MDL-19391-master-1' of git://git.luns.net.uk/moodle
[moodle.git] / lib / dtl / string_xml_database_importer.php
blobfc80593361e9fc3988075e4121957b46b7c56437
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/>.
19 /**
20 * XML format importer class from memory storage
22 * @package core
23 * @subpackage dtl
24 * @copyright 2008 Andrei Bautu
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * XML format importer class from memory storage (i.e. string).
33 class string_xml_database_importer extends xml_database_importer {
34 /** String with XML data. */
35 protected $data;
37 /**
38 * Object constructor.
40 * @param string data - string with XML data
41 * @param moodle_database $mdb Connection to the target database
42 * @see xml_database_importer::__construct()
43 * @param boolean $check_schema - whether or not to check that XML database
44 * @see xml_database_importer::__construct()
46 public function __construct($data, moodle_database $mdb, $check_schema=true) {
47 parent::__construct($mdb, $check_schema);
48 $this->data = $data;
51 /**
52 * Common import method: it creates the parser, feeds the XML parser with
53 * data, releases the parser.
54 * @return void
56 public function import_database() {
57 $parser = $this->get_parser();
58 if (!xml_parse($parser, $this->data, true)) {
59 throw new dbtransfer_exception('malformedxmlexception');
61 xml_parser_free($parser);