]> source.dussan.org Git - nextcloud-server.git/commitdiff
use preDelete instead of postDelete hook
authorGeorg Ehrke <developer@georgehrke.com>
Tue, 11 Mar 2014 13:21:27 +0000 (14:21 +0100)
committerGeorg Ehrke <developer@georgehrke.com>
Thu, 13 Mar 2014 02:14:42 +0000 (03:14 +0100)
lib/base.php
lib/private/preview.php

index 86ee534982859dcc67d6eb5d87ef42cda1e5c776..6ad3a84bcaca9fe440cea3c6198b88fadbfef184 100644 (file)
@@ -661,7 +661,10 @@ class OC {
         */
        public static function registerPreviewHooks() {
                OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write');
-               OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete');
+               OC_Hook::connect('OC_Filesystem', 'preDelete', 'OC\Preview', 'prepare_delete_files');
+               OC_Hook::connect('\OCP\Versions', 'preDelete', 'OC\Preview', 'prepare_delete');
+               OC_Hook::connect('\OCP\Trashbin', 'preDelete', 'OC\Preview', 'prepare_delete');
+               OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete_files');
                OC_Hook::connect('\OCP\Versions', 'delete', 'OC\Preview', 'post_delete');
                OC_Hook::connect('\OCP\Trashbin', 'delete', 'OC\Preview', 'post_delete');
        }
index 74051fbc2a3dab8d772e8ce81fcff879986aa960..8cef1ade01bfdc61ace168cddada95fbbb64f744 100755 (executable)
@@ -42,6 +42,10 @@ class Preview {
        private $scalingup;
        private $mimetype;
 
+       //filemapper used for deleting previews
+       // index is path, value is fileinfo
+       static public $deleteFileMapper = array();
+
        //preview images object
        /**
         * @var \OC_Image
@@ -166,7 +170,11 @@ class Preview {
        }
 
        protected function getFileInfo() {
-               if (!$this->info) {
+               $absPath = $this->fileView->getAbsolutePath($this->file);
+               $absPath = Files\Filesystem::normalizePath($absPath);
+               if(array_key_exists($absPath, self::$deleteFileMapper)) {
+                       $this->info = self::$deleteFileMapper[$absPath];
+               } else if (!$this->info) {
                        $this->info = $this->fileView->getFileInfo($this->file);
                }
                return $this->info;
@@ -623,12 +631,35 @@ class Preview {
                self::post_delete($args);
        }
 
-       public static function post_delete($args) {
+       public static function prepare_delete_files($args) {
+               self::prepare_delete($args, 'files/');
+       }
+
+       public static function prepare_delete($args, $prefix='') {
                $path = $args['path'];
                if (substr($path, 0, 1) === '/') {
                        $path = substr($path, 1);
                }
-               $preview = new Preview(\OC_User::getUser(), 'files/', $path);
+
+               $view = new \OC\Files\View('/' . \OC_User::getUser() . '/' . $prefix);
+               $info = $view->getFileInfo($path);
+
+               \OC\Preview::$deleteFileMapper = array_merge(
+                       \OC\Preview::$deleteFileMapper,
+                       array(
+                               Files\Filesystem::normalizePath($view->getAbsolutePath($path)) => $info,
+                       )
+               );
+       }
+
+       public static function post_delete_files($args) {
+               self::post_delete($args, 'files/');
+       }
+
+       public static function post_delete($args, $prefix='') {
+               $path = Files\Filesystem::normalizePath($args['path']);
+
+               $preview = new Preview(\OC_User::getUser(), $prefix, $path);
                $preview->deleteAllPreviews();
        }