2012-07-03 16:42:51 +00: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 12:10:43 +00:00
|
|
|
|
2012-09-19 18:59:57 +00:00
|
|
|
namespace OCA\Files_Versions;
|
2012-07-03 16:42:51 +00:00
|
|
|
|
|
|
|
class Hooks {
|
|
|
|
|
2014-07-24 14:49:38 +00:00
|
|
|
public static function connectHooks() {
|
|
|
|
// Listen to write signals
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'write', "OCA\Files_Versions\Hooks", "write_hook");
|
|
|
|
// Listen to delete and rename signals
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_delete', "OCA\Files_Versions\Hooks", "remove_hook");
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Versions\Hooks", "pre_remove_hook");
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA\Files_Versions\Hooks", "rename_hook");
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'copy', "OCA\Files_Versions\Hooks", "copy_hook");
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:42:51 +00:00
|
|
|
/**
|
|
|
|
* listen to write event.
|
|
|
|
*/
|
|
|
|
public static function write_hook( $params ) {
|
2012-09-07 12:10:43 +00:00
|
|
|
|
2013-07-30 10:19:01 +00:00
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2012-10-10 11:18:36 +00:00
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
2013-02-10 13:17:18 +00:00
|
|
|
if($path<>'') {
|
|
|
|
Storage::store($path);
|
|
|
|
}
|
2012-07-03 16:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 14:07:26 +00:00
|
|
|
|
2012-09-07 12:10:43 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Erase versions of deleted file
|
2014-05-15 12:19:32 +00:00
|
|
|
* @param array $params
|
2012-09-07 12:10:43 +00:00
|
|
|
*
|
|
|
|
* This function is connected to the delete signal of OC_Filesystem
|
|
|
|
* cleanup the versions directory if the actual file gets deleted
|
|
|
|
*/
|
2012-07-09 14:51:16 +00:00
|
|
|
public static function remove_hook($params) {
|
2013-07-30 10:19:01 +00:00
|
|
|
|
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2013-01-28 19:04:10 +00:00
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
2013-02-10 13:17:18 +00:00
|
|
|
if($path<>'') {
|
|
|
|
Storage::delete($path);
|
|
|
|
}
|
2013-01-28 19:04:10 +00:00
|
|
|
}
|
2012-09-07 12:10:43 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 12:17:19 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* mark file as "deleted" so that we can clean up the versions if the file is gone
|
2013-11-28 12:17:19 +00:00
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public static function pre_remove_hook($params) {
|
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
|
|
|
if($path<>'') {
|
|
|
|
Storage::markDeletedFile($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 12:10:43 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* rename/move versions of renamed/moved files
|
2014-05-15 12:19:32 +00:00
|
|
|
* @param array $params array with oldpath and newpath
|
2012-09-07 12:10:43 +00:00
|
|
|
*
|
|
|
|
* 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 14:51:16 +00:00
|
|
|
public static function rename_hook($params) {
|
2013-11-28 12:17:19 +00:00
|
|
|
|
2013-07-30 10:19:01 +00:00
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2013-01-11 13:23:28 +00:00
|
|
|
$oldpath = $params['oldpath'];
|
2013-01-28 19:04:10 +00:00
|
|
|
$newpath = $params['newpath'];
|
2013-02-10 13:17:18 +00:00
|
|
|
if($oldpath<>'' && $newpath<>'') {
|
2014-07-24 13:30:00 +00:00
|
|
|
Storage::renameOrCopy($oldpath, $newpath, 'rename');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy versions of copied files
|
|
|
|
* @param array $params array with oldpath and newpath
|
|
|
|
*
|
|
|
|
* This function is connected to the copy signal of OC_Filesystem and copies the
|
|
|
|
* the stored versions to the new location
|
|
|
|
*/
|
|
|
|
public static function copy_hook($params) {
|
|
|
|
|
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
|
|
|
$oldpath = $params['oldpath'];
|
|
|
|
$newpath = $params['newpath'];
|
|
|
|
if($oldpath<>'' && $newpath<>'') {
|
|
|
|
Storage::renameOrCopy($oldpath, $newpath, 'copy');
|
2013-02-10 13:17:18 +00:00
|
|
|
}
|
2012-09-07 12:10:43 +00:00
|
|
|
}
|
2012-07-05 09:35:08 +00:00
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2012-07-03 16:42:51 +00:00
|
|
|
}
|