use preDelete instead of postDelete hook

This commit is contained in:
Georg Ehrke 2014-03-11 14:21:27 +01:00
parent b506de6f08
commit 8048868bd7
2 changed files with 38 additions and 4 deletions

View File

@ -661,7 +661,10 @@ class OC {
*/ */
public static function registerPreviewHooks() { public static function registerPreviewHooks() {
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write'); 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\Versions', 'delete', 'OC\Preview', 'post_delete');
OC_Hook::connect('\OCP\Trashbin', 'delete', 'OC\Preview', 'post_delete'); OC_Hook::connect('\OCP\Trashbin', 'delete', 'OC\Preview', 'post_delete');
} }

View File

@ -42,6 +42,10 @@ class Preview {
private $scalingup; private $scalingup;
private $mimetype; private $mimetype;
//filemapper used for deleting previews
// index is path, value is fileinfo
static public $deleteFileMapper = array();
//preview images object //preview images object
/** /**
* @var \OC_Image * @var \OC_Image
@ -166,7 +170,11 @@ class Preview {
} }
protected function getFileInfo() { 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); $this->info = $this->fileView->getFileInfo($this->file);
} }
return $this->info; return $this->info;
@ -623,12 +631,35 @@ class Preview {
self::post_delete($args); 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']; $path = $args['path'];
if (substr($path, 0, 1) === '/') { if (substr($path, 0, 1) === '/') {
$path = substr($path, 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(); $preview->deleteAllPreviews();
} }