Merge branch 'w22_MDL-39676_m24_whereparam' of git://github.com/skodak/moodle into...
[moodle.git] / lib / dtl / string_xml_database_importer.php
blob94095e94125710a36618432cdfd40816a050beae
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * XML format importer class from memory storage
20 * @package core_dtl
21 * @copyright 2008 Andrei Bautu
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * XML format importer class from memory storage (i.e. string).
30 class string_xml_database_importer extends xml_database_importer {
31 /** @var string String with XML data. */
32 protected $data;
34 /**
35 * Object constructor.
37 * @param string $data - string with XML data
38 * @param moodle_database $mdb Connection to the target database
39 * @see xml_database_importer::__construct()
40 * @param boolean $check_schema - whether or not to check that XML database
41 * @see xml_database_importer::__construct()
43 public function __construct($data, moodle_database $mdb, $check_schema=true) {
44 parent::__construct($mdb, $check_schema);
45 $this->data = $data;
48 /**
49 * Common import method: it creates the parser, feeds the XML parser with
50 * data, releases the parser.
51 * @return void
53 public function import_database() {
54 $parser = $this->get_parser();
55 if (!xml_parse($parser, $this->data, true)) {
56 throw new dbtransfer_exception('malformedxmlexception');
58 xml_parser_free($parser);