]> git.mjollnir.org Git - moodle.git/commitdiff
New $CFG->xmldbreconstructprevnext setting to allow edition of XMLDB
authorstronk7 <stronk7>
Thu, 5 Jul 2007 16:24:24 +0000 (16:24 +0000)
committerstronk7 <stronk7>
Thu, 5 Jul 2007 16:24:24 +0000 (16:24 +0000)
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!

config-dist.php
lib/xmldb/classes/XMLDBObject.class.php
lib/xmldb/classes/XMLDBStructure.class.php
lib/xmldb/classes/XMLDBTable.class.php

index a1ca325d154fd70ac19d09e902d14e93998c2ddf..ee63e0856f2620866673e26c6e04c09548345f40 100644 (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
index 4aec0d87a7daf34ae0236022411f9d2ab68c20f1..50881001f777f029b5223dcf474160753478194e 100644 (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
index e37aacadc994b334938d065eae0c1312faff5ede..38aab23a283151a6d7f8b0429c7438ee1899c719 100644 (file)
@@ -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);
index 55a2c2d99c746016ff3e12ed93c5dcecc8c34430..a65f7641ccbe3b522765b57c31667795df8ed194 100644 (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);