From 55cde0e5aa7118ed916fc76e21c72c5081cc81ae Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 5 Jul 2012 11:35:08 +0200 Subject: moved remove and rename hook to libs/hooks.php --- apps/files_versions/lib/hooks.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'apps/files_versions/lib/hooks.php') diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 8a746705329..b43fdb9fd33 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -30,6 +30,43 @@ class Hooks { } } + /** + * @brief Erase versions of deleted file + * @param array + * + * This function is connected to the delete signal of OC_Filesystem + * cleanup the versions directory if the actual file gets deleted + */ + public static function remove_hook($params) { + $rel_path = $params['path']; + $abs_path = \OCP\Config::getSystemValue('datadirectory').'/'.\OCP\User::getUser()."/versions".$rel_path.'.v'; + if(Storage::isversioned($rel_path)) { + $versions = Storage::getVersions($rel_path); + foreach ($versions as $v){ + unlink($abs_path . $v['version']); + } + } + } + + /** + * @brief rename/move versions of renamed/moved files + * @param array with oldpath and newpath + * + * This function is connected to the rename signal of OC_Filesystem and adjust the name and location + * of the stored versions along the actual file + */ + public static function rename_hook($params) { + $rel_oldpath = $params['oldpath']; + $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OCP\User::getUser()."/versions".$rel_oldpath.'.v'; + $abs_newpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OCP\User::getUser()."/versions".$params['newpath'].'.v'; + if(Storage::isversioned($rel_oldpath)) { + $versions = Storage::getVersions($rel_oldpath); + foreach ($versions as $v){ + rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']); + } + } + } + } ?> -- cgit v1.2.3