|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00032 class load_xml_file extends XMLDBAction { 00033 00037 function init() { 00038 parent::init(); 00039 // Set own core attributes 00040 $this->can_subaction = ACTION_NONE; 00041 //$this->can_subaction = ACTION_HAVE_SUBACTIONS; 00042 00043 // Set own custom attributes 00044 $this->sesskey_protected = false; // This action doesn't need sesskey protection 00045 00046 // Get needed strings 00047 $this->loadStrings(array( 00048 // 'key' => 'module', 00049 )); 00050 } 00051 00057 function invoke() { 00058 parent::invoke(); 00059 00060 $result = true; 00061 00062 // Set own core attributes 00063 $this->does_generate = ACTION_NONE; 00064 //$this->does_generate = ACTION_GENERATE_HTML; 00065 00066 // These are always here 00067 global $CFG, $XMLDB; 00068 00069 // Do the job, setting $result as needed 00070 00071 // Get the dir containing the file 00072 $dirpath = required_param('dir', PARAM_PATH); 00073 $dirpath = $CFG->dirroot . $dirpath; 00074 00075 // Get the correct dir 00076 if (!empty($XMLDB->dbdirs)) { 00077 $dbdir =& $XMLDB->dbdirs[$dirpath]; 00078 if ($dbdir) { 00079 // Set some defaults 00080 $dbdir->xml_exists = false; 00081 $dbdir->xml_writeable = false; 00082 $dbdir->xml_loaded = false; 00083 // Only if the directory exists 00084 if (!$dbdir->path_exists) { 00085 return false; 00086 } 00087 $xmldb_file = new xmldb_file($dbdir->path . '/install.xml'); 00088 // Set the XML DTD and schema 00089 $xmldb_file->setDTD($CFG->dirroot . '/lib/xmldb/xmldb.dtd'); 00090 $xmldb_file->setSchema($CFG->dirroot . '/lib/xmldb/xmldb.xsd'); 00091 // Set dbdir as necessary 00092 if ($xmldb_file->fileExists()) { 00093 $dbdir->xml_exists = true; 00094 } 00095 if ($xmldb_file->fileWriteable()) { 00096 $dbdir->xml_writeable = true; 00097 } 00098 // Load the XML contents to structure 00099 $loaded = $xmldb_file->loadXMLStructure(); 00100 if ($loaded && $xmldb_file->isLoaded()) { 00101 $dbdir->xml_loaded = true; 00102 $dbdir->filemtime = filemtime($dbdir->path . '/install.xml'); 00103 } 00104 $dbdir->xml_file = $xmldb_file; 00105 } else { 00106 $this->errormsg = 'Wrong directory (' . $dirpath . ')'; 00107 $result = false; 00108 } 00109 } else { 00110 $this->errormsg = 'XMLDB structure not found'; 00111 $result = false; 00112 } 00113 // Launch postaction if exists 00114 if ($this->getPostAction() && $result) { 00115 return $this->launch($this->getPostAction()); 00116 } 00117 00118 return $result; 00119 } 00120 } 00121