]> git.mjollnir.org Git - moodle.git/commitdiff
merged fix for MDL-8942, can't delete blog images
authortoyomoyo <toyomoyo>
Mon, 19 Mar 2007 07:52:29 +0000 (07:52 +0000)
committertoyomoyo <toyomoyo>
Mon, 19 Mar 2007 07:52:29 +0000 (07:52 +0000)
blog/edit.php
blog/lib.php

index b14f3f38462c868668ccabee328a31e116e1df61..5743b66bc531bba89263dc6a516b48114050da44 100755 (executable)
@@ -244,7 +244,9 @@ function do_delete($post) {
 
     $status = delete_records('post', 'id', $post->id);
     $status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status;
-
+    
+    blog_delete_old_attachments($post);
+    
     add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $post->userid, 'deleted blog entry with entry id# '. $post->id);
 
     if (!$status) {
index a986cb06c10df6d3a10272cc83d9455b3b5f7e83..431d0b5689b5d6ed269ee0eed9201e5c59c9fcab 100755 (executable)
         return make_upload_directory( blog_file_area_name($blogentry) );
     }
 
+    function blog_delete_old_attachments($post, $exception="") {
+    // Deletes all the user files in the attachments area for a post
+    // EXCEPT for any file named $exception
+
+        if ($basedir = blog_file_area($post)) {
+            if ($files = get_directory_list($basedir)) {
+                foreach ($files as $file) {
+                    if ($file != $exception) {
+                        unlink("$basedir/$file");
+                        notify("Existing file '$file' has been deleted!");
+                    }
+                }
+            }
+            if (!$exception) {  // Delete directory as well, if empty
+                rmdir("$basedir");
+            }
+        }
+    }
 
     function blog_print_attachments($blogentry, $return=NULL) {
     // if return=html, then return a html string.