2012-07-03 20:42:51 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains all hooks.
|
|
|
|
*/
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
namespace OCA_Versions;
|
|
|
|
|
|
|
|
class Hooks {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* listen to write event.
|
|
|
|
*/
|
|
|
|
public static function write_hook( $params ) {
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
$versions = new Storage( new \OC_FilesystemView('') );
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
$path = $params[\OC_Filesystem::signal_param_path];
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
if($path<>'') $versions->store( $path );
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 18:07:26 +04:00
|
|
|
|
2012-09-07 16:10:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2012-07-09 18:51:16 +04:00
|
|
|
public static function remove_hook($params) {
|
2012-09-07 16:10:43 +04:00
|
|
|
$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);
|
2012-09-07 17:22:01 +04:00
|
|
|
foreach ($versions as $v) {
|
2012-09-07 16:10:43 +04:00
|
|
|
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
|
|
|
|
*/
|
2012-07-09 18:51:16 +04:00
|
|
|
public static function rename_hook($params) {
|
2012-09-07 16:10:43 +04:00
|
|
|
$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';
|
2012-07-09 18:51:16 +04:00
|
|
|
if(Storage::isversioned($rel_oldpath)) {
|
2012-09-07 16:10:43 +04:00
|
|
|
$info=pathinfo($abs_newpath);
|
|
|
|
if(!file_exists($info['dirname'])) mkdir($info['dirname'],0700,true);
|
|
|
|
$versions = Storage::getVersions($rel_oldpath);
|
2012-09-07 17:22:01 +04:00
|
|
|
foreach ($versions as $v) {
|
2012-09-07 16:10:43 +04:00
|
|
|
rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']);
|
|
|
|
}
|
|
|
|
}
|
2012-07-05 13:35:08 +04:00
|
|
|
}
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
}
|