diff --git a/lib/accesslib.php b/lib/accesslib.php
index <HASH>..<HASH> 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -4759,8 +4759,8 @@ function context_moved($context, $newparent) {
     $newpath  = $newparent->path . '/' . $context->id;
 
     $setdepth = '';
-    if ($newparent->depth +1 != $context->depth) {
-        $setdepth = ", depth= depth + " . ($context->depth - $newparent->depth +1);
+    if (($newparent->depth +1) != $context->depth) {
+        $setdepth = ", depth= depth + ({$newparent->depth} - {$context->depth}) + 1";
     }
     $sql = "UPDATE {$CFG->prefix}context 
             SET path='$newpath'
accesslib:content_moved() fix bug in depth handling

the depth was getting a bit out-of-control when moving
up the tree. Fix it...