|
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 00037 class save_xml_file extends XMLDBAction { 00038 00042 function init() { 00043 parent::init(); 00044 00045 // Set own custom attributes 00046 00047 // Get needed strings 00048 $this->loadStrings(array( 00049 'filenotwriteable' => 'tool_xmldb' 00050 )); 00051 } 00052 00058 function invoke() { 00059 parent::invoke(); 00060 00061 $result = true; 00062 00063 // Set own core attributes 00064 $this->does_generate = ACTION_NONE; 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 $unload = optional_param('unload', true, PARAM_BOOL); 00075 00076 // Get the edited dir 00077 if (!empty($XMLDB->editeddirs)) { 00078 if (isset($XMLDB->editeddirs[$dirpath])) { 00079 $editeddir =& $XMLDB->editeddirs[$dirpath]; 00080 } 00081 } 00082 // Copy the edited dir over the original one 00083 if (!empty($XMLDB->dbdirs)) { 00084 if (isset($XMLDB->dbdirs[$dirpath])) { 00085 $XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir)); 00086 $dbdir =& $XMLDB->dbdirs[$dirpath]; 00087 } 00088 } 00089 00090 // Chech for perms 00091 if (!is_writeable($dirpath . '/install.xml')) { 00092 $this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)'; 00093 return false; 00094 } 00095 00096 // Save the original dir 00097 $result = $dbdir->xml_file->saveXMLFile(); 00098 00099 if ($result) { 00100 // Delete the edited dir 00101 unset ($XMLDB->editeddirs[$dirpath]); 00102 // Unload de originaldir 00103 unset($XMLDB->dbdirs[$dirpath]->xml_file); 00104 unset($XMLDB->dbdirs[$dirpath]->xml_loaded); 00105 unset($XMLDB->dbdirs[$dirpath]->xml_changed); 00106 unset($XMLDB->dbdirs[$dirpath]->xml_exists); 00107 unset($XMLDB->dbdirs[$dirpath]->xml_writeable); 00108 } else { 00109 $this->errormsg = 'Error saving XML file (' . $dirpath . ')'; 00110 return false; 00111 } 00112 00113 // If unload has been disabled, simulate it by reloading the file now 00114 if (!$unload) { 00115 return $this->launch('load_xml_file'); 00116 } 00117 00118 // Launch postaction if exists (leave this here!) 00119 if ($this->getPostAction() && $result) { 00120 return $this->launch($this->getPostAction()); 00121 } 00122 00123 // Return ok if arrived here 00124 return $result; 00125 } 00126 } 00127