From: martinlanghoff <martinlanghoff>
Date: Thu, 20 Sep 2007 00:16:22 +0000 (+0000)
Subject: accesslib:build_Context_path() fix $emptyclause
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=92b34bdd6cf742deaafb20eb82fc8e8a147a87c8;p=moodle.git

accesslib:build_Context_path() fix $emptyclause

We need 2 different empty clauses, one for updates, anotherone for
selects.
---

diff --git a/lib/accesslib.php b/lib/accesslib.php
index 85b38342b6..1d61e2e31b 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -4443,7 +4443,13 @@ function build_context_path($force=false) {
                                     'instanceid', SITEID);
     }
 
-    $emptyclause = " AND (depth IS NULL OR depth=0) ";
+    $ctxemptyclause = " AND (ctx.depth IS NULL 
+                              OR ctx.depth=0) ";
+    $emptyclause    = " AND (context.depth IS NULL 
+                              OR context.depth=0) ";
+    if ($force) {
+        $ctxemptyclause = $emptyclause = '';
+    }
 
     // TODO: following could be improved with WHERE + $emptyclause, but there should be a better way
     $upathsql = "UPDATE {$CFG->prefix}context
@@ -4489,7 +4495,7 @@ function build_context_path($force=false) {
                  WHERE ctx.contextlevel=".CONTEXT_COURSECAT."
                        AND pctx.contextlevel=".CONTEXT_COURSECAT."
                        AND c.depth=$n
-                       $emptyclause";
+                       $ctxemptyclause";
         execute_sql($sql, $force);
     }
 
@@ -4506,7 +4512,7 @@ function build_context_path($force=false) {
              WHERE ctx.contextlevel=".CONTEXT_COURSE."
                    AND c.id!=".SITEID."
                    AND pctx.contextlevel=".CONTEXT_COURSECAT."
-                   $emptyclause";
+                   $ctxemptyclause";
     execute_sql($sql, $force);
 
     execute_sql($upathsql, $force);
@@ -4521,7 +4527,7 @@ function build_context_path($force=false) {
               JOIN {$CFG->prefix}context pctx ON cm.course=pctx.instanceid
              WHERE ctx.contextlevel=".CONTEXT_MODULE."
                    AND pctx.contextlevel=".CONTEXT_COURSE."
-                   $emptyclause";
+                   $ctxemptyclause";
     execute_sql($sql, $force);
 
     execute_sql($upathsql, $force);
@@ -4537,7 +4543,7 @@ function build_context_path($force=false) {
              WHERE ctx.contextlevel=".CONTEXT_BLOCK."
                    AND pctx.contextlevel=".CONTEXT_COURSE."
                    AND bi.pagetype='course-view'
-                   $emptyclause";
+                   $ctxemptyclause";
     execute_sql($sql, $force);
 
     execute_sql($upathsql, $force);