New $CFG->xmldbreconstructprevnext setting to allow edition of XMLDB

out from the XMLDBEditor, ignoring the prev/next stuff, that will be
automatically regenerated by the Editor by simply loading and saving
the edited file. Credit goes to skodak!
This commit is contained in:
stronk7
2007-07-05 16:24:24 +00:00
parent c3e193ece3
commit 4d248a2e80
4 changed files with 45 additions and 1 deletions
+8 -1
View File
@@ -283,10 +283,17 @@ $CFG->admin = 'admin';
// NOTE: if you are using custompix in your theme, see /fixpix.php.
//
// special magic evil developer only wanting to edit the xmldb files manually
// uncomment these if you're lazy like Penny
// AND don't use the XMLDBEditor nor the prev/next stuff at all (Mahara and others)
// Uncomment these if you're lazy like Penny
// $CFG->xmldbdisablecommentchecking = true;
// $CFG->xmldbdisablenextprevchecking = true;
//
// special magig evil developer only wanting to edit xmldb files manually
// AND allowing the XMLDBEditor to recostruct the prev/next elements every
// time one file is loaded and saved (Moodle).
// Uncomment this if you're lazy like Petr
// $CFG->xmldbreconstructprevnext = true;
//
// Set the priority of themes from highest to lowest. This is useful (for
// example) in sites where the user theme should override all other theme
// settings for accessibility reasons. You can also disable types of themes
+32
View File
@@ -189,6 +189,38 @@ class XMLDBObject {
return $result;
}
/**
* Reconstruct previous/next attributes.
*/
function fixPrevNext(&$arr) {
global $CFG;
if (empty($CFG->xmldbreconstructprevnext)) {
return false;
}
$tweaked = false;
$prev = null;
foreach ($arr as $key=>$el) {
$prev_value = $arr[$key]->previous;
$next_value = $arr[$key]->next;
$arr[$key]->next = null;
$arr[$key]->previous = null;
if ($prev !== null) {
$arr[$prev]->next = $arr[$key]->name;
$arr[$key]->previous = $arr[$prev]->name;
}
$prev = $key;
if ($prev_value != $arr[$key]->previous or $next_value != $arr[$key]->next) {
$tweaked = true;
}
}
return $tweaked;
}
/**
* This function will check that all the elements in one array
* have a consistent info in their previous/next fields
@@ -395,6 +395,7 @@ class XMLDBStructure extends XMLDBObject {
$result = false;
}
/// Check previous & next are ok (duplicates and existing tables)
$this->fixPrevNext($this->tables);
if ($result && !$this->checkPreviousNextValues($this->tables)) {
$this->errormsg = 'Some TABLES previous/next values are incorrect';
$this->debug($this->errormsg);
@@ -435,6 +436,7 @@ class XMLDBStructure extends XMLDBObject {
$result = false;
}
/// Check previous & next are ok (duplicates and existing statements)
$this->fixPrevNext($this->statements);
if ($result && !$this->checkPreviousNextValues($this->statements)) {
$this->errormsg = 'Some STATEMENTS previous/next values are incorrect';
$this->debug($this->errormsg);
+3
View File
@@ -498,6 +498,7 @@ class XMLDBTable extends XMLDBObject {
$result = false;
}
/// Check previous & next are ok (duplicates and existing fields)
$this->fixPrevNext($this->fields);
if ($result && !$this->checkPreviousNextValues($this->fields)) {
$this->errormsg = 'Some FIELDS previous/next values are incorrect';
$this->debug($this->errormsg);
@@ -542,6 +543,7 @@ class XMLDBTable extends XMLDBObject {
$result = false;
}
/// Check previous & next are ok (duplicates and existing keys)
$this->fixPrevNext($this->keys);
if ($result && !$this->checkPreviousNextValues($this->keys)) {
$this->errormsg = 'Some KEYS previous/next values are incorrect';
$this->debug($this->errormsg);
@@ -585,6 +587,7 @@ class XMLDBTable extends XMLDBObject {
$result = false;
}
/// Check previous & next are ok (duplicates and existing INDEXES)
$this->fixPrevNext($this->indexes);
if ($result && !$this->checkPreviousNextValues($this->indexes)) {
$this->errormsg = 'Some INDEXES previous/next values are incorrect';
$this->debug($this->errormsg);