[dokuwiki] Re: New event proposition

On Fri, 2008-09-26 at 16:03 +0200, Andreas Gohr wrote:
> I think that might come in handy. So please send a patch.

Patch included in an attachment.

> However for quota checking, I'd say you only need to check on upload.

It would be enough, but I assume that DokuWiki will have to deal with
large number of files and subdirectories. Consequently, a method
scanning all media files on upload may be quite slow. I think it's a
better idea to store in some file and update (add and substract) used
disk space each time user uploads/deletes a media file.

Michal Kolodziejski
diff -aur dw-original/inc/media.php dw-changed/inc/media.php
--- dw-original/inc/media.php   2008-05-05 19:10:08.000000000 +0200
+++ dw-changed/inc/media.php    2008-09-29 18:06:52.000000000 +0200
@@ -163,17 +163,28 @@
 
     if(!count($mediareferences)){
         $file = mediaFN($id);
-        if(@unlink($file)){
-            msg(str_replace('%s',noNS($id),$lang['deletesucc']),1);
-            $del = io_sweepNS($id,'mediadir');
-            if($del){
-                // current namespace was removed. redirecting to root ns 
passing msg along
-                header('Location: '.DOKU_URL.'lib/exe/mediamanager.php?msg1='.
-                        
rawurlencode(str_replace('%s',noNS($id),$lang['deletesucc'])));
-                exit;
-            }
-            return true;
+        
+        // trigger an event - MEDIA_FILE_DELETE
+        $data['name'] = substr($file,strrpos($file,'/'));
+        $data['path'] = $file;
+        $data['size'] = (file_exists($file)) ? filesize($file) : 0;
+        $evt = new Doku_Event('MEDIA_DELETE_FILE',$data);
+        if ($evt->advise_before()) {
+               if(@unlink($file)){
+                   msg(str_replace('%s',noNS($id),$lang['deletesucc']),1);
+                   $del = io_sweepNS($id,'mediadir');
+                   if($del){
+                       // current namespace was removed. redirecting to root 
ns passing msg along
+                       header('Location: 
'.DOKU_URL.'lib/exe/mediamanager.php?msg1='.
+                               
rawurlencode(str_replace('%s',noNS($id),$lang['deletesucc'])));
+                       exit;
+                   }
+                   return true;
+               }
         }
+        $evt->advise_after();
+        unset($evt);
+        
         //something went wrong
         msg(str_replace('%s',$file,$lang['deletefail']),-1);
         return false;

Other related posts: