From: skodak Date: Tue, 2 Oct 2007 22:34:12 +0000 (+0000) Subject: MDL-11523 fixed - moving categories and courses around breaks paths and depths in... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1f41940f20362235cd0ec0754133322b03c90eff;p=moodle.git MDL-11523 fixed - moving categories and courses around breaks paths and depths in context table + some notice fixes --- diff --git a/course/lib.php b/course/lib.php index 1f503ce1ad..123c7e85da 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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, diff --git a/lib/accesslib.php b/lib/accesslib.php index 3ffbc57b65..a5e566e34a 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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);