From dac539b61936e61c804c3d8fbf91003803e2cc81 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Jun 2012 11:46:17 +0200 Subject: [PATCH 1/5] handover the correct timestamp --- apps/files_versions/ajax/getVersions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php index fe48434d2cb..f29d1760b6f 100644 --- a/apps/files_versions/ajax/getVersions.php +++ b/apps/files_versions/ajax/getVersions.php @@ -13,7 +13,7 @@ if( OCA_Versions\Storage::isversioned( $source ) ) { $versionsFormatted = array(); foreach ( $versions AS $version ) { - $versionsFormatted[] = OCP\Util::formatDate( doubleval($version) ); + $versionsFormatted[] = OCP\Util::formatDate( $version['version'] ); } $versionsSorted = array_reverse( $versions ); From 52f99a7570921f994035c96002b7ae46acdfea9b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Jun 2012 11:48:57 +0200 Subject: [PATCH 2/5] delete file versions if the user deletes a file --- apps/files_archive/appinfo/app.php | 2 ++ apps/files_versions/lib/hooks_handler.php | 38 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 apps/files_versions/lib/hooks_handler.php diff --git a/apps/files_archive/appinfo/app.php b/apps/files_archive/appinfo/app.php index 67376c4a03a..e6026670264 100644 --- a/apps/files_archive/appinfo/app.php +++ b/apps/files_archive/appinfo/app.php @@ -7,7 +7,9 @@ */ OC::$CLASSPATH['OC_Filestorage_Archive']='apps/files_archive/lib/storage.php'; +OC::$CLASSPATH['OC_Files_Versions_Hooks_Handler'] = 'files_versions/lib/hooks_handler.php'; OCP\Util::connectHook('OC_Filesystem','get_mountpoint','OC_Filestorage_Archive','autoMount'); +OCP\Util::connectHook('OC_Filesystem', 'delete', "OC_Files_Versions_Hooks_Handler", "removeVersions"); OCP\Util::addscript( 'files_archive', 'archive' ); diff --git a/apps/files_versions/lib/hooks_handler.php b/apps/files_versions/lib/hooks_handler.php new file mode 100644 index 00000000000..4be2d1c284b --- /dev/null +++ b/apps/files_versions/lib/hooks_handler.php @@ -0,0 +1,38 @@ +. +* +*/ + +class OC_Files_Versions_Hooks_Handler { + + public static function removeVersions($params) { + $rel_path = $params[OC_Filesystem::signal_param_path]; + $abs_path = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$rel_path; + if(OCA_Versions\Storage::isversioned($rel_path)) { + $versions = OCA_Versions\Storage::getVersions($rel_path); + foreach ($versions as $v){ + unlink($abs_path.'.v' . $v['version']); + } + } + } +} + +?> \ No newline at end of file From f22f49671bcdc87058c6060db4ca4e4e1d9704f1 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Jun 2012 12:42:47 +0200 Subject: [PATCH 3/5] move hook to erase versions from deleted files to the right place --- apps/files_archive/appinfo/app.php | 2 -- apps/files_versions/appinfo/app.php | 2 ++ apps/files_versions/lib/hooks_handler.php | 38 ----------------------- apps/files_versions/versions.php | 14 ++++++++- 4 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 apps/files_versions/lib/hooks_handler.php diff --git a/apps/files_archive/appinfo/app.php b/apps/files_archive/appinfo/app.php index e6026670264..67376c4a03a 100644 --- a/apps/files_archive/appinfo/app.php +++ b/apps/files_archive/appinfo/app.php @@ -7,9 +7,7 @@ */ OC::$CLASSPATH['OC_Filestorage_Archive']='apps/files_archive/lib/storage.php'; -OC::$CLASSPATH['OC_Files_Versions_Hooks_Handler'] = 'files_versions/lib/hooks_handler.php'; OCP\Util::connectHook('OC_Filesystem','get_mountpoint','OC_Filestorage_Archive','autoMount'); -OCP\Util::connectHook('OC_Filesystem', 'delete', "OC_Files_Versions_Hooks_Handler", "removeVersions"); OCP\Util::addscript( 'files_archive', 'archive' ); diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index bd06dc0ced3..5a559c0c962 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -9,3 +9,5 @@ OCP\Util::addscript('files_versions', 'versions'); // Listen to write signals OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); +// Listen to delete signals +OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions"); \ No newline at end of file diff --git a/apps/files_versions/lib/hooks_handler.php b/apps/files_versions/lib/hooks_handler.php deleted file mode 100644 index 4be2d1c284b..00000000000 --- a/apps/files_versions/lib/hooks_handler.php +++ /dev/null @@ -1,38 +0,0 @@ -. -* -*/ - -class OC_Files_Versions_Hooks_Handler { - - public static function removeVersions($params) { - $rel_path = $params[OC_Filesystem::signal_param_path]; - $abs_path = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$rel_path; - if(OCA_Versions\Storage::isversioned($rel_path)) { - $versions = OCA_Versions\Storage::getVersions($rel_path); - foreach ($versions as $v){ - unlink($abs_path.'.v' . $v['version']); - } - } - } -} - -?> \ No newline at end of file diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 9c0829ff1de..787de0f78ad 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -309,5 +309,17 @@ class Storage { } - + /** + * @brief Erase versions of deleted file + */ + public static function removeVersions($params) { + $rel_path = $params[\OC_Filesystem::signal_param_path]; + $abs_path = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_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']); + } + } + } } From e5792cc064c41c2a5bca32b886a8bc08cce2fb3f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Jun 2012 14:06:20 +0200 Subject: [PATCH 4/5] adjust the name and/or location of the stored versions if the actual file gets moved or renamed --- apps/files_versions/appinfo/app.php | 5 +++-- apps/files_versions/versions.php | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 5a559c0c962..105c5a102cb 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -9,5 +9,6 @@ OCP\Util::addscript('files_versions', 'versions'); // Listen to write signals OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); -// Listen to delete signals -OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions"); \ No newline at end of file +// Listen to delete and rename signals +OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions"); +OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA_Versions\Storage", "renameVersions"); \ No newline at end of file diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 787de0f78ad..b733c57923e 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -310,7 +310,11 @@ class Storage { } /** - * @brief Erase versions of deleted file + * @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 removeVersions($params) { $rel_path = $params[\OC_Filesystem::signal_param_path]; @@ -322,4 +326,23 @@ class Storage { } } } + + /** + * @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 renameVersions($params) { + $rel_oldpath = $params['oldpath']; + $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$rel_oldpath.'.v'; + $abs_newpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_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']); + } + } + } } From bdd1baeb858b4968a6b69b48960abe3b9f63bc92 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 28 Jun 2012 14:18:57 +0200 Subject: [PATCH 5/5] use public API --- apps/files_versions/versions.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index b733c57923e..7ed5f257505 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -316,9 +316,9 @@ class Storage { * This function is connected to the delete signal of OC_Filesystem * cleanup the versions directory if the actual file gets deleted */ - public static function removeVersions($params) { - $rel_path = $params[\OC_Filesystem::signal_param_path]; - $abs_path = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$rel_path.'.v'; + public static function removeVersions($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){ @@ -336,8 +336,8 @@ class Storage { */ public static function renameVersions($params) { $rel_oldpath = $params['oldpath']; - $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$rel_oldpath.'.v'; - $abs_newpath = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/versions".$params['newpath'].'.v'; + $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){