/** * 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_NONE; //$this->does_generate = ACTION_GENERATE_HTML; /// These are always here global $CFG, $XMLDB; /// Do the job, setting $result as needed /// Lets go to add all the db directories available inside Moodle /// Create the array if it doesn't exists if (!isset($XMLDB->dbdirs)) { $XMLDB->dbdirs = array(); } /// get list of all dirs and create objects with status $db_direcotries = get_db_directories(); foreach ($db_direcotries as $path) { $dbdir = new stdClass(); $dbdir->path = $path; if (!isset($XMLDB->dbdirs[$dbdir->path])) { $XMLDB->dbdirs[$dbdir->path] = $dbdir; } $XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status } /// Sort by key ksort($XMLDB->dbdirs); /// Return ok if arrived here return true; }
/** * 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; /// Do the job, setting $result as needed /// Add link back to home $b = ' <p class="centerpara buttons">'; $b .= ' <a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>'; $b .= '</p>'; $this->output = $b; $c = ' <p class="centerpara">'; $c .= $this->str['documentationintro']; $c .= '</p>'; $this->output .= $c; $this->docs = ''; if (class_exists('XSLTProcessor')) { $doc = new DOMDocument(); $xsl = new XSLTProcessor(); $doc->load(dirname(__FILE__) . '/../generate_documentation/xmldb.xsl'); $xsl->importStyleSheet($doc); $dbdirs = get_db_directories(); sort($dbdirs); $index = $this->str['docindex'] . ' '; foreach ($dbdirs as $path) { if (!file_exists($path . '/install.xml')) { continue; } $dir = trim(dirname(str_replace($CFG->dirroot, '', $path)), '/'); $index .= '<a href="#file_' . str_replace('/', '_', $dir) . '">' . $dir . '</a>, '; $this->docs .= '<div class="file" id="file_' . str_replace('/', '_', $dir) . '">'; $this->docs .= '<h2>' . $dir . '</h2>'; $doc->load($path . '/install.xml'); $this->docs .= $xsl->transformToXML($doc); $this->docs .= '</div>'; } $this->output .= '<div id="file_idex">' . trim($index, ' ,') . '</div>' . $this->docs; $this->output .= $b; } else { $this->output .= get_string('extensionrequired', 'tool_xmldb', 'xsl'); } /// Launch postaction if exists (leave this unmodified) if ($this->getPostAction() && $result) { return $this->launch($this->getPostAction()); } return $result; }
/** * Returns names of all known tables == tables that moodle knowns about. * @return array of lowercase table names */ function get_used_table_names() { $table_names = array(); $dbdirs = get_db_directories(); foreach ($dbdirs as $dbdir) { $file = $dbdir . '/install.xml'; $xmldb_file = new xmldb_file($file); if (!$xmldb_file->fileExists()) { continue; } $loaded = $xmldb_file->loadXMLStructure(); $structure = $xmldb_file->getStructure(); if ($loaded and $tables = $structure->getTables()) { foreach ($tables as $table) { $table_names[] = strtolower($table->name); } } } return $table_names; }
/** * Reads the install.xml files for Moodle core and modules and returns an array of * xmldb_structure object with xmldb_table from these files. * @return xmldb_structure schema from install.xml files */ public function get_install_xml_schema() { global $CFG; require_once $CFG->libdir . '/adminlib.php'; $schema = new xmldb_structure('export'); $schema->setVersion($CFG->version); $dbdirs = get_db_directories(); foreach ($dbdirs as $dbdir) { $xmldb_file = new xmldb_file($dbdir . '/install.xml'); if (!$xmldb_file->fileExists() or !$xmldb_file->loadXMLStructure()) { continue; } $structure = $xmldb_file->getStructure(); $tables = $structure->getTables(); foreach ($tables as $table) { $table->setPrevious(null); $table->setNext(null); $schema->addTable($table); } } return $schema; }