accesslib: Introducing context_moved() - call after moving courses/coursecats

With the new accesslib, moving courses and categories has a major
impact on enrolments and unenrolments.

At _least_ we need to signal accesslib that it has happened. So here
is context_moved() for exactly that.

Open to refactoring later into something along the lines of

 - move_course()
 - move_category()

However, at this stage the most important of those two: move_course()
does not fit very well with the code in course/edit. So keep it simple
for now.
This commit is contained in:
martinlanghoff
2007-09-19 07:13:33 +00:00
parent c633af7a5a
commit e4fec27340
+43
View File
@@ -4731,6 +4731,49 @@ function build_context_path() {
}
/**
* Update the path field of the context and
* all the dependent subcontexts that follow
* the move.
*
* The most important thing here is to be as
* DB efficient as possible. This op can have a
* massive impact in the DB.
*
* @param obj current context obj
* @param obj newparent new parent obj
*
*/
function context_moved($context, $newparent) {
global $CFG;
$frompath = $context->path;
$newpath = $newparent->path . '/' . $context->id;
$setdepth = '';
if ($newparent->depth +1 != $context->depth) {
$setdepth = ", depth= depth + " . ($context->depth - $newparent->depth +1);
}
$sql = "UPDATE {$CFG->prefix}context
SET path='$newpath'
$setdepth
WHERE path='$frompath'";
error_log($sql);
execute_sql($sql,false);
$len = strlen($frompath);
$sql = "UPDATE {$CFG->prefix}context
SET path = '$newpath' || SUBSTR(path, {$len} +1)
$setdepth
WHERE path LIKE '{$frompath}/%'";
error_log($sql);
execute_sql($sql,false);
mark_context_dirty($frompath);
mark_context_dirty($newpath);
}
/**
* Turn the ctx* fields in an objectlike record
* into a context subobject. This allows