connect preview lib to filesystem hooks

This commit is contained in:
Georg Ehrke 2013-05-29 12:01:43 +02:00
parent a03787bc42
commit eebc15dce0
2 changed files with 71 additions and 44 deletions

View file

@ -474,6 +474,7 @@ class OC {
self::registerCacheHooks();
self::registerFilesystemHooks();
self::registerPreviewHooks();
self::registerShareHooks();
//make sure temporary files are cleaned up
@ -539,6 +540,14 @@ class OC {
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
}
/**
* register hooks for previews
*/
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');
}
/**
* register hooks for sharing
*/

View file

@ -55,7 +55,7 @@ class OC_Preview {
* false if thumbnail does not exist
* path to thumbnail if thumbnail exists
*/
public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true){
public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){
//set config
$this->max_x = OC_Config::getValue('preview_max_x', null);
$this->max_y = OC_Config::getValue('preview_max_y', null);
@ -71,6 +71,7 @@ class OC_Preview {
$this->fileview = new \OC\Files\View('/' . $user . '/' . $root);
$this->userview = new \OC\Files\View('/' . $user);
if($force !== true){
if(!is_null($this->max_x)){
if($this->maxX > $this->max_x){
OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG);
@ -114,6 +115,7 @@ class OC_Preview {
throw new Exception('Height and/or width set to 0');
}
}
}
/**
* @brief returns the path of the file you want a thumbnail from
@ -187,18 +189,21 @@ class OC_Preview {
$fileinfo = $this->fileview->getFileInfo($this->file);
$fileid = $fileinfo['fileid'];
return $this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png');
$this->userview->unlink(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $this->maxX . '-' . $this->maxY . '.png');
return;
}
/**
* @brief deletes all previews of a file
* @return bool
*/
public function deleteAllPrevies(){
public function deleteAllPreviews(){
$fileinfo = $this->fileview->getFileInfo($this->file);
$fileid = $fileinfo['fileid'];
return $this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid);
$this->userview->deleteAll(self::THUMBNAILS_FOLDER . '/' . $fileid . '/');
$this->userview->rmdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/');
return;
}
/**
@ -577,4 +582,17 @@ class OC_Preview {
exit;
}
}
public static function post_write($args){
self::post_delete($args);
}
public static function post_delete($args){
$path = $args['path'];
if(substr($path, 0, 1) == '/'){
$path = substr($path, 1);
}
$preview = new OC_Preview(OC_User::getUser(), 'files/', $path, 0, 0, false, true);
$preview->deleteAllPreviews();
}
}