本文整理汇总了PHP中XMLDBAction::invoke方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLDBAction::invoke方法的具体用法?PHP XMLDBAction::invoke怎么用?PHP XMLDBAction::invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDBAction
的用法示例。
在下文中一共展示了XMLDBAction::invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invoke
/**
* 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_XML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the file parameter
$file = required_param('file', PARAM_PATH);
$file = $CFG->dirroot . $file;
/// File must be under $CFG->wwwroot and
/// under one db directory (simple protection)
if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot && substr(dirname($file), -2, 2) == 'db') {
/// Everything is ok. Load the file to memory
$this->output = file_get_contents($file);
} else {
/// Switch to HTML and error
$this->does_generate = ACTION_GENERATE_HTML;
$this->errormsg = 'File not viewable (' . $file . ')';
$result = false;
}
/// Return ok if arrived here
return $result;
}
示例2: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例3: invoke
/**
* 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
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
// If the changeme table exists, just get it and continue
$changeme_exists = false;
if ($tables =& $structure->getTables()) {
if ($table =& $structure->getTable('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
// Lets create the table
$field = new xmldb_field('id');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setUnsigned(true);
$field->setSequence(true);
$field->setLoaded(true);
$field->setChanged(true);
$key = new xmldb_key('primary');
$key->setType(XMLDB_KEY_PRIMARY);
$key->setFields(array('id'));
$key->setLoaded(true);
$key->setChanged(true);
$table = new xmldb_table('changeme');
$table->setComment('Default comment for the table, please edit me');
$table->addField($field);
$table->addKey($key);
// Finally, add the whole retrofitted table to the structure
// in the place specified
$structure->addTable($table);
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
示例4: invoke
/**
* 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;
}
示例5: invoke
/**
* 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_XML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
/// Get the file parameter
$select = required_param('select', PARAM_ALPHA);
//original/edited
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dir
if ($select == 'original') {
if (!empty($XMLDB->dbdirs)) {
$base =& $XMLDB->dbdirs[$dirpath];
}
} else {
if ($select == 'edited') {
if (!empty($XMLDB->editeddirs)) {
$base =& $XMLDB->editeddirs[$dirpath];
}
} else {
$this->errormsg = 'Cannot access to ' . $select . ' info';
$result = false;
}
}
if ($base) {
/// Only if the directory exists and it has been loaded
if (!$base->path_exists || !$base->xml_loaded) {
$this->errormsg = 'Directory ' . $dirpath . ' not loaded';
return false;
}
} else {
$this->errormsg = 'Problem handling ' . $select . ' files';
return false;
}
/// Get the structure
if ($result) {
if (!($structure =& $base->xml_file->getStructure())) {
$this->errormsg = 'Error retrieving ' . $select . ' structure';
$result = false;
}
}
if ($result) {
/// Everything is ok. Generate the XML output
$this->output = $structure->xmlOutput();
} else {
/// Switch to HTML and error
$this->does_generate = ACTION_GENERATE_HTML;
}
/// Return ok if arrived here
return $result;
}
示例6: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dir
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
if ($dbdir) {
/// Set some defaults
$dbdir->xml_exists = false;
$dbdir->xml_writeable = false;
$dbdir->xml_loaded = false;
///Only if the directory exists
if (!$dbdir->path_exists) {
return false;
}
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
///Set the XML DTD and schema
$xmldb_file->setDTD($CFG->dirroot . '/lib/xmldb/xmldb.dtd');
$xmldb_file->setSchema($CFG->dirroot . '/lib/xmldb/xmldb.xsd');
/// Set dbdir as necessary
if ($xmldb_file->fileExists()) {
$dbdir->xml_exists = true;
}
if ($xmldb_file->fileWriteable()) {
$dbdir->xml_writeable = true;
}
/// Load the XML contents to structure
$loaded = $xmldb_file->loadXMLStructure();
if ($loaded && $xmldb_file->isLoaded()) {
$dbdir->xml_loaded = true;
$dbdir->filemtime = filemtime($dbdir->path . '/install.xml');
}
$dbdir->xml_file = $xmldb_file;
} else {
$this->errormsg = 'Wrong directory (' . $dirpath . ')';
$result = false;
}
} else {
$this->errormsg = 'XMLDB structure not found';
$result = false;
}
/// Launch postaction if exists
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
return $result;
}
示例7: invoke
/**
* 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;
// These are always here
global $CFG, $XMLDB;
// Do the job, setting result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
$unload = optional_param('unload', true, PARAM_BOOL);
// Get the edited dir
if (!empty($XMLDB->editeddirs)) {
if (isset($XMLDB->editeddirs[$dirpath])) {
$editeddir = $XMLDB->editeddirs[$dirpath];
}
}
// Copy the edited dir over the original one
if (!empty($XMLDB->dbdirs)) {
if (isset($XMLDB->dbdirs[$dirpath])) {
$XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
$dbdir = $XMLDB->dbdirs[$dirpath];
}
}
// Check for perms
if (!is_writeable($dirpath . '/install.xml')) {
$this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)';
return false;
}
// Save the original dir
$result = $dbdir->xml_file->saveXMLFile();
if ($result) {
// Delete the edited dir
unset($XMLDB->editeddirs[$dirpath]);
// Unload de originaldir
unset($XMLDB->dbdirs[$dirpath]->xml_file);
unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
unset($XMLDB->dbdirs[$dirpath]->xml_changed);
unset($XMLDB->dbdirs[$dirpath]->xml_exists);
unset($XMLDB->dbdirs[$dirpath]->xml_writeable);
} else {
$this->errormsg = 'Error saving XML file (' . $dirpath . ')';
return false;
}
// If unload has been disabled, simulate it by reloading the file now
if (!$unload) {
return $this->launch('load_xml_file');
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
示例8: invoke
/**
* 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, $DB;
$dbman = $DB->get_manager();
/// Do the job, setting result as needed
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
/// Get parameters
$tableparam = required_param('table', PARAM_PATH);
if (!($table = $structure->getTable($tableparam))) {
$this->errormsg = 'Wrong table specified: ' . $tableparam;
return false;
}
/// The back to edit table button
$b = ' <p class="centerpara buttons">';
$b .= '<a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
$b .= '</p>';
$o = $b;
$o .= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
$o .= ' <tr><td><textarea cols="80" rows="32">';
/// Get an array of statements
if ($starr = $DB->get_manager()->generator->getCreateTableSQL($table)) {
$starr = $dbman->generator->getEndedStatements($starr);
$sqltext = '';
foreach ($starr as $st) {
$sqltext .= s($st) . "\n\n";
}
$sqltext = trim($sqltext);
$o .= $sqltext;
}
$o .= '</textarea></td></tr>';
$o .= ' </table>';
$this->output = $o;
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例9: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
/// If not confirmed, show confirmation box
if (!$confirmed) {
$o = '<table width="60" class="generalbox boxaligncenter" border="0" cellpadding="5" cellspacing="0" id="notice">';
$o .= ' <tr><td class="generalboxcontent">';
$o .= ' <p class="centerpara">' . $this->str['confirmrevertchanges'] . '<br /><br />' . $dirpath . '</p>';
$o .= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=revert_changes&sesskey=' . sesskey() . '&confirmed=yes&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&postaction=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['yes'] . '" /></fieldset></form></div>';
$o .= ' </td><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=main_view#lastused" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['no'] . '" /></fieldset></form></div>';
$o .= ' </td></tr>';
$o .= ' </table>';
$o .= ' </td></tr>';
$o .= '</table>';
$this->output = $o;
} else {
/// Get the original dir and delete some elements
if (!empty($XMLDB->dbdirs)) {
if (isset($XMLDB->dbdirs[$dirpath])) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
if ($dbdir) {
unset($dbdir->xml_changed);
}
}
}
/// Get the edited dir and delete it completely
if (!empty($XMLDB->editeddirs)) {
if (isset($XMLDB->editeddirs[$dirpath])) {
unset($XMLDB->editeddirs[$dirpath]);
}
}
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例10: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
$statementparam = required_param('statement', PARAM_CLEAN);
$basesentenceparam = optional_param('basesentence', NULL, PARAM_CLEAN);
$statement =& $structure->getStatement($statementparam);
$sentences =& $statement->getSentences();
$sentence = NULL;
/// If some sentence has been specified, create the new one
/// based on it
if (!empty($basesentenceparam)) {
$sentence = $sentences[$basesentenceparam];
}
/// Else, try to create the new one based in the last
if (empty($sentence) && !empty($sentences)) {
$sentence = end($sentences);
}
/// Else, create one sentence by hand
if (empty($sentence)) {
$sentence = "(list, of, fields) VALUES ('list', 'of', 'values')";
}
/// Add the sentence to the statement
$statement->addSentence($sentence);
/// We have one new sentence, so the statement and the structure has changed
$statement->setChanged(true);
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例11: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
$statementparam = required_param('statement', PARAM_CLEAN);
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
/// If not confirmed, show confirmation box
if (!$confirmed) {
$o = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
$o .= ' <tr><td class="generalboxcontent">';
$o .= ' <p class="centerpara">' . $this->str['confirmdeletestatement'] . '<br /><br />' . $statementparam . '</p>';
$o .= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=delete_statement&confirmed=yes&postaction=edit_xml_file&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['yes'] . '" /></fieldset></form></div>';
$o .= ' </td><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['no'] . '" /></fieldset></form></div>';
$o .= ' </td></tr>';
$o .= ' </table>';
$o .= ' </td></tr>';
$o .= '</table>';
$this->output = $o;
} else {
/// Get the edited dir
if (!empty($XMLDB->editeddirs)) {
if (isset($XMLDB->editeddirs[$dirpath])) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
$editeddir =& $XMLDB->editeddirs[$dirpath];
if ($editeddir) {
$structure =& $editeddir->xml_file->getStructure();
/// Remove the table
$structure->deleteStatement($statementparam);
}
}
}
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例12: invoke
/**
* 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;
}
示例13: invoke
/**
* 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
/// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
/// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
$tableparam = required_param('table', PARAM_CLEAN);
$table =& $structure->getTable($tableparam);
/// If the changeme field exists, just get it and continue
$changeme_exists = false;
if ($fields =& $table->getFields()) {
if ($field =& $table->getField('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
/// Lets create the field
$field = new XMLDBField('changeme');
$field->setComment('Default comment for the field, please edit me');
$table->addField($field);
/// We have one new field, so the structure has changed
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
示例14: invoke
/**
* 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
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$plugintype = $this->get_plugin_type($dirpath);
$dirpath = $CFG->dirroot . $dirpath;
$file = $dirpath . '/install.xml';
// Some variables
$xmlpath = dirname(str_replace($CFG->dirroot . '/', '', $file));
$xmlversion = userdate(time(), '%Y%m%d', 99, false);
$xmlcomment = 'XMLDB file for Moodle ' . dirname($xmlpath);
$xmltable = strtolower(basename(dirname($xmlpath)));
if ($plugintype && $plugintype != 'mod') {
$xmltable = $plugintype . '_' . $xmltable;
}
// Initial contents
$c = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$c .= ' <XMLDB PATH="' . $xmlpath . '" VERSION="' . $xmlversion . '" COMMENT="' . $xmlcomment . '">' . "\n";
$c .= ' <TABLES>' . "\n";
$c .= ' <TABLE NAME="' . $xmltable . '" COMMENT="Default comment for ' . $xmltable . ', please edit me">' . "\n";
$c .= ' <FIELDS>' . "\n";
$c .= ' <FIELD NAME="id" TYPE="int" LENGTH="10" UNSIGNED="true" NOTNULL="true" SEQUENCE="true" />' . "\n";
$c .= ' </FIELDS>' . "\n";
$c .= ' <KEYS>' . "\n";
$c .= ' <KEY NAME="primary" TYPE="primary" FIELDS="id" />' . "\n";
$c .= ' </KEYS>' . "\n";
$c .= ' </TABLE>' . "\n";
$c .= ' </TABLES>' . "\n";
$c .= ' </XMLDB>';
if (!file_put_contents($file, $c)) {
$errormsg = 'Error creando fichero ' . $file;
$result = false;
}
// Launch postaction if exists
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
示例15: invoke
/**
* 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
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir = $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir = $XMLDB->editeddirs[$dirpath];
$structure = $editeddir->xml_file->getStructure();
}
$tableparam = required_param('table', PARAM_CLEAN);
$table = $structure->getTable($tableparam);
// If the changeme index exists, just get it and continue
$changeme_exists = false;
if ($indexes = $table->getIndexes()) {
if ($index = $table->getIndex('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
// Lets create the Index
$index = new xmldb_index('changeme');
$table->addIndex($index);
// We have one new key, so the structure has changed
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}