From: Sam Hemelryk <sam@moodle.com>
Date: Wed, 4 Nov 2009 06:11:32 +0000 (+0000)
Subject: files MDL-20635 Added support for cleaning up files associated with a context when... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8432f5e6c5045f618fca0b72491d21bcd229e469;p=moodle.git

files MDL-20635 Added support for cleaning up files associated with a context when it is deleted
Note: This is a temporary solution until we have a patch to clean them up in a cron run
---

diff --git a/lib/accesslib.php b/lib/accesslib.php
index 5e6a45a6e5..27cef15ecc 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -2297,7 +2297,7 @@ function get_system_context($cache=true) {
  * @return bool properly deleted
  */
 function delete_context($contextlevel, $instanceid) {
-    global $DB, $ACCESSLIB_PRIVATE;
+    global $DB, $ACCESSLIB_PRIVATE, $CFG;
 
     // do not use get_context_instance(), because the related object might not exist,
     // or the context does not exist yet and it would be created now
@@ -2319,6 +2319,11 @@ function delete_context($contextlevel, $instanceid) {
         blocks_delete_all_for_context($context->id);
         filter_delete_all_for_context($context->id);
 
+        // TODO: MDL-20635 Replace with a means to delete during a cron run
+        require_once($CFG->libdir.'/filelib.php');
+        $fs = get_file_storage();
+        $fs->delete_area_files($context->id);
+
         return $result;
     } else {