|
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 new_index extends XMLDBAction { 00033 00037 function init() { 00038 parent::init(); 00039 00040 // Set own custom attributes 00041 00042 // Get needed strings 00043 $this->loadStrings(array( 00044 // 'key' => 'module', 00045 )); 00046 } 00047 00053 function invoke() { 00054 parent::invoke(); 00055 00056 $result = true; 00057 00058 // Set own core attributes 00059 $this->does_generate = ACTION_NONE; 00060 //$this->does_generate = ACTION_GENERATE_HTML; 00061 00062 // These are always here 00063 global $CFG, $XMLDB; 00064 00065 // Do the job, setting result as needed 00066 // Get the dir containing the file 00067 $dirpath = required_param('dir', PARAM_PATH); 00068 $dirpath = $CFG->dirroot . $dirpath; 00069 00070 // Get the correct dirs 00071 if (!empty($XMLDB->dbdirs)) { 00072 $dbdir =& $XMLDB->dbdirs[$dirpath]; 00073 } else { 00074 return false; 00075 } 00076 if (!empty($XMLDB->editeddirs)) { 00077 $editeddir =& $XMLDB->editeddirs[$dirpath]; 00078 $structure =& $editeddir->xml_file->getStructure(); 00079 } 00080 00081 $tableparam = required_param('table', PARAM_CLEAN); 00082 00083 $table =& $structure->getTable($tableparam); 00084 00085 // If the changeme index exists, just get it and continue 00086 $changeme_exists = false; 00087 if ($indexes =& $table->getIndexes()) { 00088 if ($index =& $table->getIndex('changeme')) { 00089 $changeme_exists = true; 00090 } 00091 } 00092 if (!$changeme_exists) { // Lets create the Index 00093 $index = new xmldb_index('changeme'); 00094 $table->addIndex($index); 00095 00096 // We have one new key, so the structure has changed 00097 $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); 00098 $structure->setChanged(true); 00099 } 00100 // Launch postaction if exists (leave this here!) 00101 if ($this->getPostAction() && $result) { 00102 return $this->launch($this->getPostAction()); 00103 } 00104 00105 // Return ok if arrived here 00106 return $result; 00107 } 00108 } 00109