diff options
Diffstat (limited to 'apps/files_versions/lib/hooks.php')
-rw-r--r-- | apps/files_versions/lib/hooks.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 990f1403e8d..1a584232ba7 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -14,6 +14,16 @@ namespace OCA\Files_Versions; class Hooks { + public static function connectHooks() { + // Listen to write signals + \OCP\Util::connectHook('OC_Filesystem', 'write', "OCA\Files_Versions\Hooks", "write_hook"); + // Listen to delete and rename signals + \OCP\Util::connectHook('OC_Filesystem', 'post_delete', "OCA\Files_Versions\Hooks", "remove_hook"); + \OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Versions\Hooks", "pre_remove_hook"); + \OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA\Files_Versions\Hooks", "rename_hook"); + \OCP\Util::connectHook('OC_Filesystem', 'copy', "OCA\Files_Versions\Hooks", "copy_hook"); + } + /** * listen to write event. */ @@ -69,7 +79,25 @@ class Hooks { $oldpath = $params['oldpath']; $newpath = $params['newpath']; if($oldpath<>'' && $newpath<>'') { - Storage::rename( $oldpath, $newpath ); + Storage::renameOrCopy($oldpath, $newpath, 'rename'); + } + } + } + + /** + * copy versions of copied files + * @param array $params array with oldpath and newpath + * + * This function is connected to the copy signal of OC_Filesystem and copies the + * the stored versions to the new location + */ + public static function copy_hook($params) { + + if (\OCP\App::isEnabled('files_versions')) { + $oldpath = $params['oldpath']; + $newpath = $params['newpath']; + if($oldpath<>'' && $newpath<>'') { + Storage::renameOrCopy($oldpath, $newpath, 'copy'); } } } |