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. 13 // 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/>. 16 17 /** 18 * XML format exporter class to file storage 19 * 20 * @package core_dtl 21 * @copyright 2008 Andrei Bautu 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * XML format exporter class to file storage. 29 */ 30 class file_xml_database_exporter extends xml_database_exporter { 31 /** @var string Path to the XML data file. */ 32 protected $filepath; 33 /** @var resource File descriptor for the output file. */ 34 protected $file; 35 36 /** 37 * Object constructor. 38 * 39 * @param string $filepath - path to the XML data file. Use 'php://output' for PHP 40 * output stream. 41 * @param moodle_database $mdb Connection to the source database 42 * @see xml_database_exporter::__construct() 43 * @param boolean $check_schema - whether or not to check that XML database 44 * @see xml_database_exporter::__construct() 45 */ 46 public function __construct($filepath, moodle_database $mdb, $check_schema=true) { 47 parent::__construct($mdb, $check_schema); 48 $this->filepath = $filepath; 49 } 50 51 /** 52 * Specific output method for the file XML sink. 53 * @param string $text 54 */ 55 protected function output($text) { 56 fwrite($this->file, $text); 57 } 58 59 /** 60 * Specific implementation for file exporting the database: it opens output stream, calls 61 * superclass @see database_exporter::export_database() and closes output stream. 62 * 63 * @throws dbtransfer_exception if any checking (e.g. database schema) fails 64 * 65 * @param string $description a user description of the data. 66 */ 67 public function export_database($description=null) { 68 global $CFG; 69 // TODO: add exception if file creation fails 70 $this->file = fopen($this->filepath, 'wb'); 71 parent::export_database($description); 72 fclose($this->file); 73 @chmod($this->filepath, $CFG->filepermissions); 74 } 75 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body