]> source.dussan.org Git - nextcloud-server.git/commitdiff
adjust the name and/or location of the stored versions if the actual file gets moved...
authorBjoern Schiessle <schiessle@owncloud.com>
Thu, 28 Jun 2012 12:06:20 +0000 (14:06 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Thu, 28 Jun 2012 12:06:20 +0000 (14:06 +0200)
apps/files_versions/appinfo/app.php
apps/files_versions/versions.php

index 5a559c0c9629c09dfd75f911f83868d27122ba0d..105c5a102cbdd8ef041f522b52489706e67ac1f8 100644 (file)
@@ -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
index 787de0f78ad1ef966aad98fb187251b39efec89f..b733c57923e2036f5b9d8d900b380089decf5434 100644 (file)
@@ -310,7 +310,11 @@ class Storage {
         }
 
         /**\r
-         * @brief Erase versions of deleted file\r
+         * @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\r
          */
         public static function removeVersions($params) {\r
                $rel_path =  $params[\OC_Filesystem::signal_param_path];\r
@@ -322,4 +326,23 @@ class Storage {
                        }\r
                }\r
         }
+        
+        /**\r
+         * @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\r
+         */\r
+        public static function renameVersions($params) {\r
+               $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';\r
+               if(Storage::isversioned($rel_oldpath)) {
+                       $versions = Storage::getVersions($rel_oldpath);\r
+                       foreach ($versions as $v){
+                               rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']);
+                       }
+               }\r
+        }
 }