/**
* This class contains all hooks.
*/
-
+
namespace OCA_Versions;
class Hooks {
* listen to write event.
*/
public static function write_hook( $params ) {
-
+
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
-
+
$versions = new Storage( new \OC_FilesystemView('') );
-
+
$path = $params[\OC_Filesystem::signal_param_path];
-
+
if($path<>'') $versions->store( $path );
-
+
}
}
-
- /**\r
- * @brief Erase versions of deleted file\r
- * @param array\r
- *\r
- * This function is connected to the delete signal of OC_Filesystem\r
- * cleanup the versions directory if the actual file gets deleted\r
- */\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
+ */
public static function remove_hook($params) {
- $versions_fileview = \OCP\Files::getStorage('files_versions');\r
- $rel_path = $params['path'];\r
- $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_path.'.v';\r
- if(Storage::isversioned($rel_path)) {\r
- $versions = Storage::getVersions($rel_path);\r
- foreach ($versions as $v){\r
- unlink($abs_path . $v['version']);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * @brief rename/move versions of renamed/moved files\r
- * @param array with oldpath and newpath\r
- *\r
- * This function is connected to the rename signal of OC_Filesystem and adjust the name and location\r
- * of the stored versions along the actual file\r
- */\r
+ $versions_fileview = \OCP\Files::getStorage('files_versions');
+ $rel_path = $params['path'];
+ $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$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) {
- $versions_fileview = \OCP\Files::getStorage('files_versions');\r
- $rel_oldpath = $params['oldpath'];\r
- $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_oldpath.'.v';\r
- $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$params['newpath'].'.v';\r
+ $versions_fileview = \OCP\Files::getStorage('files_versions');
+ $rel_oldpath = $params['oldpath'];
+ $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_oldpath.'.v';
+ $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$params['newpath'].'.v';
if(Storage::isversioned($rel_oldpath)) {
- $info=pathinfo($abs_newpath);\r
- if(!file_exists($info['dirname'])) mkdir($info['dirname'],0700,true);\r
- $versions = Storage::getVersions($rel_oldpath);\r
- foreach ($versions as $v){\r
- rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']);\r
- }\r
- }\r
+ $info=pathinfo($abs_newpath);
+ if(!file_exists($info['dirname'])) mkdir($info['dirname'],0700,true);
+ $versions = Storage::getVersions($rel_oldpath);
+ foreach ($versions as $v){
+ rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']);
+ }
+ }
}
-
+
}