]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11523 fixed - moving categories and courses around breaks paths and depths in...
authorskodak <skodak>
Tue, 2 Oct 2007 22:34:12 +0000 (22:34 +0000)
committerskodak <skodak>
Tue, 2 Oct 2007 22:34:12 +0000 (22:34 +0000)
course/lib.php
lib/accesslib.php

index 1f503ce1ad0cf10aa9261dccc4c897c80c6b0d43..123c7e85dad67fdc7d08f1df008b44b799f50afc 100644 (file)
@@ -2709,12 +2709,20 @@ function move_category ($category, $newparentcat) {
 
     global $CFG;
 
-    if (!set_field('course_categories', 'parent', $newparentcat->id, 'id', $category->id)) {
-        return false;
+    $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+
+    if (empty($newparentcat->id)) {
+        if (!set_field('course_categories', 'parent', 0, 'id', $category->id)) {
+            return false;
+        }
+        $newparent = get_context_instance(CONTEXT_SYSTEM);
+    } else {
+        if (!set_field('course_categories', 'parent', $newparentcat->id, 'id', $category->id)) {
+            return false;
+        }
+        $newparent = get_context_instance(CONTEXT_COURSECAT, $newparentcat->id);
     }
 
-    $context   = get_context_instance(CONTEXT_COURSECAT, $category->id);
-    $newparent = get_context_instance(CONTEXT_COURSECAT, $newparentcat->id);
     context_moved($context, $newparent);
 
     // The most effective thing would be to find the common parent, 
index 3ffbc57b651f39c1d966e8d98b49da1276466def..a5e566e34a8dd4e0524c77963649d345a2bab2c8 100755 (executable)
@@ -4685,7 +4685,7 @@ function context_moved($context, $newparent) {
 
     $len = strlen($frompath);
     $sql = "UPDATE {$CFG->prefix}context
-            SET path = ".sql_concat("'$newpath'", 'SUBSTR(path, {$len} +1)')."
+            SET path = ".sql_concat("'$newpath'", 'SUBSTR(path, '.$len.' +1)')."
                 $setdepth
             WHERE path LIKE '{$frompath}/%'";
     execute_sql($sql,false);