. /** * @package tool * @subpackage xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This class will show all the actions available under the XMLDB editor interface * * From here, files can be created, edited, saved and deleted, plus some * extra utilities like displaying docs, xml info and performing various consistency tests * * @package tool * @subpackage xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class main_view extends XMLDBAction { /** * Init method, every subclass will have its own */ function init() { parent::init(); // Set own custom attributes $this->sesskey_protected = false; // This action doesn't need sesskey protection // Get needed strings $this->loadStrings(array( 'load' => 'tool_xmldb', 'create' => 'tool_xmldb', 'edit' => 'tool_xmldb', 'save' => 'tool_xmldb', 'revert' => 'tool_xmldb', 'unload' => 'tool_xmldb', 'delete' => 'tool_xmldb', 'reservedwords' => 'tool_xmldb', 'gotolastused' => 'tool_xmldb', 'checkindexes' => 'tool_xmldb', 'checkdefaults' => 'tool_xmldb', 'checkforeignkeys' => 'tool_xmldb', 'checkbigints' => 'tool_xmldb', 'checkoraclesemantics' => 'tool_xmldb', 'doc' => 'tool_xmldb', 'viewxml' => 'tool_xmldb', 'pendingchangescannotbesavedreload' => 'tool_xmldb' )); } /** * Invoke method, every class will have its own * returns true/false on completion, setting both * errormsg and output as necessary */ function invoke() { parent::invoke(); $result = true; // Set own core attributes $this->does_generate = ACTION_GENERATE_HTML; // These are always here global $CFG, $XMLDB, $SESSION, $DB; // Get lastused $o = ''; if (isset($SESSION->lastused)) { if ($lastused = $SESSION->lastused) { // Print link $o .= '

' . $this->str['gotolastused'] . '

'; } } else { $lastused = NULL; } // Calculate the buttons $b = '

'; // The reserved_words button $b .= ' [' . $this->str['reservedwords'] . ']'; // The docs button $b .= ' [' . $this->str['doc'] . ']'; // The check indexes button $b .= ' [' . $this->str['checkindexes'] . ']'; // The check defaults button $b .= ' [' . $this->str['checkdefaults'] . ']'; // The check bigints button (only for MySQL and PostgreSQL) MDL-11038a if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { $b .= ' [' . $this->str['checkbigints'] . ']'; } // The check semantics button (only for Oracle) MDL-29416 if ($DB->get_dbfamily() == 'oracle') { $b .= ' [' . $this->str['checkoraclesemantics'] . ']'; } $b .= ' [' . $this->str['checkforeignkeys'] . ']'; $b .= '

'; // Send buttons to output $o .= $b; // Do the job // Get the list of DB directories $result = $this->launch('get_db_directories'); // Display list of DB directories if everything is ok if ($result && !empty($XMLDB->dbdirs)) { $o .= ''; $row = 0; foreach ($XMLDB->dbdirs as $key => $dbdir) { // Detect if this is the lastused dir $hithis = false; if (str_replace($CFG->dirroot, '', $key) == $lastused) { $hithis = true; } $elementtext = str_replace($CFG->dirroot . '/', '', $key); // Calculate the dbdir has_changed field if needed if (!isset($dbdir->has_changed) && isset($dbdir->xml_loaded)) { $dbdir->xml_changed = false; if (isset($XMLDB->editeddirs[$key])) { $editeddir =& $XMLDB->editeddirs[$key]; if (isset($editeddir->xml_file)) { $structure =& $editeddir->xml_file->getStructure(); if ($structure->hasChanged()) { $dbdir->xml_changed = true; $editeddir->xml_changed = true; } } } } // The file name (link to edit if the file is loaded) if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key) && !empty($dbdir->xml_loaded)) { $f = '' . $elementtext . ''; } else { $f = $elementtext; } // Calculate the buttons $b = ' '; // include the higlight if ($hithis) { $o .= '' . $b . ''; } else { $o .= '' . $b . ''; } $row = ($row + 1) % 2; // show errors if they exist if (isset($dbdir->xml_file)) { if ($structure =& $dbdir->xml_file->getStructure()) { if ($errors = $structure->getAllErrors()) { if ($hithis) { $o .= ''; } else { $o .= ''; } } } } // TODO: Drop this check in Moodle 2.1 // Intercept loaded structure here and look for ENUM fields if (isset($dbdir->xml_file)) { if ($structure =& $dbdir->xml_file->getStructure()) { if ($tables = $structure->getTables()) { foreach ($tables as $table) { if ($fields = $table->getFields()) { foreach ($fields as $field) { if (!empty($field->hasenums)) { if ($hithis) { $o .= ''; } } } } } } } // If there are changes pending to be saved, but the file cannot be written... inform here if ($dbdir->path_exists && file_exists($key . '/install.xml') && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed) && (!is_writeable($key . '/install.xml') || !is_writeable($key))) { if ($hithis) { $o .= ''; } } $o .= '
'; // The create button if ($dbdir->path_exists && !file_exists($key . '/install.xml') && is_writeable($key)) { $b .= '[' . $this->str['create'] . ']'; } else { $b .= '[' . $this->str['create'] . ']'; } $b .= ''; // The load button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['load'] . ']'; } else { $b .= '[' . $this->str['load'] . ']'; } $b .= ''; // The edit button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key) && !empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['edit'] . ']'; } else { $b .= '[' . $this->str['edit'] . ']'; } $b .= ''; // The save button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_writeable($key . '/install.xml') && is_writeable($key) && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed)) { $b .= '[' . $this->str['save'] . ']'; // Check if the file has been manually edited while being modified in the editor if ($dbdir->filemtime != filemtime($key . '/install.xml')) { // File manually modified. Add to errors. if ($structure =& $dbdir->xml_file->getStructure()) { $structure->errormsg = 'Warning: File locally modified while using the XMLDB Editor. Saving will overwrite local changes'; } } } else { $b .= '[' . $this->str['save'] . ']'; } $b .= ''; // The document button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_readable($key)) { $b .= '[' . $this->str['doc'] . ']'; } else { $b .= '[' . $this->str['doc'] . ']'; } $b .= ''; // The view xml button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml')) { $b .= '[' . $this->str['viewxml'] . ']'; } else { $b .= '[' . $this->str['viewxml'] . ']'; } $b .= ''; // The revert button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_writeable($key) && !empty($dbdir->xml_loaded) && !empty($dbdir->xml_changed)) { $b .= '[' . $this->str['revert'] . ']'; } else { $b .= '[' . $this->str['revert'] . ']'; } $b .= ''; // The unload button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && !empty($dbdir->xml_loaded) && empty($dbdir->xml_changed)) { $b .= '[' . $this->str['unload'] . ']'; } else { $b .= '[' . $this->str['unload'] . ']'; } $b .= ''; // The delete button if ($dbdir->path_exists && file_exists($key . '/install.xml') && is_readable($key . '/install.xml') && is_writeable($key) && empty($dbdir->xml_loaded)) { $b .= '[' . $this->str['delete'] . ']'; } else { $b .= '[' . $this->str['delete'] . ']'; } $b .= '
' . $f . '
' . $f . '
' . implode (', ', $errors) . '
' . implode (', ', $errors) . '
'; } else { $o .= '
'; } $o .= 'Table ' . $table->getName() . ', field ' . $field->getName() . ' has ENUM info'; if (!empty($field->hasenumsenabled)) { $o .= ' that seems to be active (true). ENUMs support has been dropped in Moodle 2.0, ' . ' the XMLDB Editor will delete any ENUM reference next time you save this file' . ' and you MUST provide one upgrade block in your code to drop them from DB. See' . ' ' . ' Moodle Docs for more info and examples.'; } else { $o .= ' that seem to be inactive (false). ENUMs support has been dropped in Moodle 2.0,' . ' the XMLDB Editor will, simply, delete any ENUM reference next time you save this file.' . ' No further action is necessary.'; } $o .= '
'; } else { $o .= '
'; } $o .= $this->str['pendingchangescannotbesavedreload']; $o .= '
'; // Set the output $this->output = $o; } // Finally, return result return $result; } }