Blame view
sources/apps/files_versions/lib/hooks.php
2.82 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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.
*/
namespace OCA\Files_Versions;
class Hooks {
|
|
6d9380f96
|
16 17 18 19 20 21 22 23 24 |
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");
}
|
|
03e52840d
|
25 26 27 28 |
/**
* listen to write event.
*/
public static function write_hook( $params ) {
|
|
31b7f2792
|
29 |
if (\OCP\App::isEnabled('files_versions')) {
|
|
03e52840d
|
30 31 32 33 34 35 36 37 38 |
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
Storage::store($path);
}
}
}
/**
|
|
6d9380f96
|
39 40 |
* Erase versions of deleted file * @param array $params |
|
03e52840d
|
41 42 43 44 45 |
*
* 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) {
|
|
31b7f2792
|
46 47 |
if (\OCP\App::isEnabled('files_versions')) {
|
|
03e52840d
|
48 49 50 51 |
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
Storage::delete($path);
}
|
|
03e52840d
|
52 53 54 55 |
} } /** |
|
6d9380f96
|
56 |
* mark file as "deleted" so that we can clean up the versions if the file is gone |
|
31b7f2792
|
57 58 59 60 61 62 63 64 65 66 |
* @param array $params
*/
public static function pre_remove_hook($params) {
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
Storage::markDeletedFile($path);
}
}
/**
|
|
6d9380f96
|
67 68 |
* rename/move versions of renamed/moved files * @param array $params array with oldpath and newpath |
|
03e52840d
|
69 70 71 72 73 |
*
* 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) {
|
|
31b7f2792
|
74 75 |
if (\OCP\App::isEnabled('files_versions')) {
|
|
03e52840d
|
76 77 78 |
$oldpath = $params['oldpath'];
$newpath = $params['newpath'];
if($oldpath<>'' && $newpath<>'') {
|
|
6d9380f96
|
79 |
Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
|
03e52840d
|
80 |
} |
|
03e52840d
|
81 82 83 84 |
} } /** |
|
6d9380f96
|
85 86 |
* copy versions of copied files * @param array $params array with oldpath and newpath |
|
03e52840d
|
87 |
* |
|
6d9380f96
|
88 89 |
* This function is connected to the copy signal of OC_Filesystem and copies the * the stored versions to the new location |
|
03e52840d
|
90 |
*/ |
|
6d9380f96
|
91 |
public static function copy_hook($params) {
|
|
31b7f2792
|
92 93 |
if (\OCP\App::isEnabled('files_versions')) {
|
|
6d9380f96
|
94 95 96 97 98 |
$oldpath = $params['oldpath'];
$newpath = $params['newpath'];
if($oldpath<>'' && $newpath<>'') {
Storage::renameOrCopy($oldpath, $newpath, 'copy');
}
|
|
31b7f2792
|
99 |
} |
|
03e52840d
|
100 101 102 |
} } |