summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2014-03-11 14:21:27 +0100
committerGeorg Ehrke <developer@georgehrke.com>2014-03-13 03:14:42 +0100
commit8048868bd7cc55716127d1c9fa40a0c32db8b901 (patch)
treeed97a7f357d0bb4a20d014e5a9bdeceea740c8ca /lib
parentb506de6f08d17bf6e5584dfce253b7e3bead928b (diff)
downloadnextcloud-server-8048868bd7cc55716127d1c9fa40a0c32db8b901.tar.gz
nextcloud-server-8048868bd7cc55716127d1c9fa40a0c32db8b901.zip
use preDelete instead of postDelete hook
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php5
-rwxr-xr-xlib/private/preview.php37
2 files changed, 38 insertions, 4 deletions
diff --git a/lib/base.php b/lib/base.php
index 86ee5349828..6ad3a84bcac 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -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');
}
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 74051fbc2a3..8cef1ade01b 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -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();
}