[dokuwiki] Re: New event proposition

On Tue, 2008-09-30 at 10:10 +0200, Michal Kolodziejski wrote:
> 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.

Oh, I've just found a little mistake in a comment that may be a bit
misleading. There should be MEDIA_DELETE_FILE instead of
MEDIA_FILE_DELETE, of course. Once again, I include a correct patch in
an attachment.

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_DELETE_FILE
+        $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: