adjust the name and/or location of the stored versions if the actual file gets moved or renamed

This commit is contained in:
Bjoern Schiessle 2012-06-28 14:06:20 +02:00
parent f22f49671b
commit e5792cc064
2 changed files with 27 additions and 3 deletions

View File

@ -9,5 +9,6 @@ OCP\Util::addscript('files_versions', 'versions');
// Listen to write signals // Listen to write signals
OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook");
// Listen to delete signals // Listen to delete and rename signals
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions"); OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions");
OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA_Versions\Storage", "renameVersions");

View File

@ -311,6 +311,10 @@ 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) { public static function removeVersions($params) {
$rel_path = $params[\OC_Filesystem::signal_param_path]; $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']);
}
}
}
} }