From: stronk7 Date: Thu, 5 Jul 2007 16:24:24 +0000 (+0000) Subject: New $CFG->xmldbreconstructprevnext setting to allow edition of XMLDB X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4d248a2e8013ff11ac76668d0041adf6359ed4fd;p=moodle.git 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! --- diff --git a/config-dist.php b/config-dist.php index a1ca325d15..ee63e0856f 100644 --- a/config-dist.php +++ b/config-dist.php @@ -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 diff --git a/lib/xmldb/classes/XMLDBObject.class.php b/lib/xmldb/classes/XMLDBObject.class.php index 4aec0d87a7..50881001f7 100644 --- a/lib/xmldb/classes/XMLDBObject.class.php +++ b/lib/xmldb/classes/XMLDBObject.class.php @@ -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 diff --git a/lib/xmldb/classes/XMLDBStructure.class.php b/lib/xmldb/classes/XMLDBStructure.class.php index e37aacadc9..38aab23a28 100644 --- a/lib/xmldb/classes/XMLDBStructure.class.php +++ b/lib/xmldb/classes/XMLDBStructure.class.php @@ -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); diff --git a/lib/xmldb/classes/XMLDBTable.class.php b/lib/xmldb/classes/XMLDBTable.class.php index 55a2c2d99c..a65f7641cc 100644 --- a/lib/xmldb/classes/XMLDBTable.class.php +++ b/lib/xmldb/classes/XMLDBTable.class.php @@ -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);