@@ -37,118 +37,118 @@ |
||
37 | 37 | |
38 | 38 | class Hooks { |
39 | 39 | |
40 | - public static function connectHooks() { |
|
41 | - // Listen to write signals |
|
42 | - \OCP\Util::connectHook('OC_Filesystem', 'write', Hooks::class, 'write_hook'); |
|
43 | - // Listen to delete and rename signals |
|
44 | - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', Hooks::class, 'remove_hook'); |
|
45 | - \OCP\Util::connectHook('OC_Filesystem', 'delete', Hooks::class, 'pre_remove_hook'); |
|
46 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', Hooks::class, 'rename_hook'); |
|
47 | - \OCP\Util::connectHook('OC_Filesystem', 'post_copy', Hooks::class, 'copy_hook'); |
|
48 | - \OCP\Util::connectHook('OC_Filesystem', 'rename', Hooks::class, 'pre_renameOrCopy_hook'); |
|
49 | - \OCP\Util::connectHook('OC_Filesystem', 'copy', Hooks::class, 'pre_renameOrCopy_hook'); |
|
40 | + public static function connectHooks() { |
|
41 | + // Listen to write signals |
|
42 | + \OCP\Util::connectHook('OC_Filesystem', 'write', Hooks::class, 'write_hook'); |
|
43 | + // Listen to delete and rename signals |
|
44 | + \OCP\Util::connectHook('OC_Filesystem', 'post_delete', Hooks::class, 'remove_hook'); |
|
45 | + \OCP\Util::connectHook('OC_Filesystem', 'delete', Hooks::class, 'pre_remove_hook'); |
|
46 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', Hooks::class, 'rename_hook'); |
|
47 | + \OCP\Util::connectHook('OC_Filesystem', 'post_copy', Hooks::class, 'copy_hook'); |
|
48 | + \OCP\Util::connectHook('OC_Filesystem', 'rename', Hooks::class, 'pre_renameOrCopy_hook'); |
|
49 | + \OCP\Util::connectHook('OC_Filesystem', 'copy', Hooks::class, 'pre_renameOrCopy_hook'); |
|
50 | 50 | |
51 | - $eventDispatcher = \OC::$server->getEventDispatcher(); |
|
52 | - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [Hooks::class, 'onLoadFilesAppScripts']); |
|
53 | - } |
|
51 | + $eventDispatcher = \OC::$server->getEventDispatcher(); |
|
52 | + $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [Hooks::class, 'onLoadFilesAppScripts']); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * listen to write event. |
|
57 | - */ |
|
58 | - public static function write_hook( $params ) { |
|
59 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
60 | - if($path !== '') { |
|
61 | - Storage::store($path); |
|
62 | - } |
|
63 | - } |
|
55 | + /** |
|
56 | + * listen to write event. |
|
57 | + */ |
|
58 | + public static function write_hook( $params ) { |
|
59 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
60 | + if($path !== '') { |
|
61 | + Storage::store($path); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Erase versions of deleted file |
|
68 | - * @param array $params |
|
69 | - * |
|
70 | - * This function is connected to the delete signal of OC_Filesystem |
|
71 | - * cleanup the versions directory if the actual file gets deleted |
|
72 | - */ |
|
73 | - public static function remove_hook($params) { |
|
74 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
75 | - if($path !== '') { |
|
76 | - Storage::delete($path); |
|
77 | - } |
|
78 | - } |
|
66 | + /** |
|
67 | + * Erase versions of deleted file |
|
68 | + * @param array $params |
|
69 | + * |
|
70 | + * This function is connected to the delete signal of OC_Filesystem |
|
71 | + * cleanup the versions directory if the actual file gets deleted |
|
72 | + */ |
|
73 | + public static function remove_hook($params) { |
|
74 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
75 | + if($path !== '') { |
|
76 | + Storage::delete($path); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * mark file as "deleted" so that we can clean up the versions if the file is gone |
|
82 | - * @param array $params |
|
83 | - */ |
|
84 | - public static function pre_remove_hook($params) { |
|
85 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
86 | - if($path !== '') { |
|
87 | - Storage::markDeletedFile($path); |
|
88 | - } |
|
89 | - } |
|
80 | + /** |
|
81 | + * mark file as "deleted" so that we can clean up the versions if the file is gone |
|
82 | + * @param array $params |
|
83 | + */ |
|
84 | + public static function pre_remove_hook($params) { |
|
85 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
86 | + if($path !== '') { |
|
87 | + Storage::markDeletedFile($path); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * rename/move versions of renamed/moved files |
|
93 | - * @param array $params array with oldpath and newpath |
|
94 | - * |
|
95 | - * This function is connected to the rename signal of OC_Filesystem and adjust the name and location |
|
96 | - * of the stored versions along the actual file |
|
97 | - */ |
|
98 | - public static function rename_hook($params) { |
|
99 | - $oldpath = $params['oldpath']; |
|
100 | - $newpath = $params['newpath']; |
|
101 | - if($oldpath !== '' && $newpath !== '') { |
|
102 | - Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
|
103 | - } |
|
104 | - } |
|
91 | + /** |
|
92 | + * rename/move versions of renamed/moved files |
|
93 | + * @param array $params array with oldpath and newpath |
|
94 | + * |
|
95 | + * This function is connected to the rename signal of OC_Filesystem and adjust the name and location |
|
96 | + * of the stored versions along the actual file |
|
97 | + */ |
|
98 | + public static function rename_hook($params) { |
|
99 | + $oldpath = $params['oldpath']; |
|
100 | + $newpath = $params['newpath']; |
|
101 | + if($oldpath !== '' && $newpath !== '') { |
|
102 | + Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * copy versions of copied files |
|
108 | - * @param array $params array with oldpath and newpath |
|
109 | - * |
|
110 | - * This function is connected to the copy signal of OC_Filesystem and copies the |
|
111 | - * the stored versions to the new location |
|
112 | - */ |
|
113 | - public static function copy_hook($params) { |
|
114 | - $oldpath = $params['oldpath']; |
|
115 | - $newpath = $params['newpath']; |
|
116 | - if($oldpath !== '' && $newpath !== '') { |
|
117 | - Storage::renameOrCopy($oldpath, $newpath, 'copy'); |
|
118 | - } |
|
119 | - } |
|
106 | + /** |
|
107 | + * copy versions of copied files |
|
108 | + * @param array $params array with oldpath and newpath |
|
109 | + * |
|
110 | + * This function is connected to the copy signal of OC_Filesystem and copies the |
|
111 | + * the stored versions to the new location |
|
112 | + */ |
|
113 | + public static function copy_hook($params) { |
|
114 | + $oldpath = $params['oldpath']; |
|
115 | + $newpath = $params['newpath']; |
|
116 | + if($oldpath !== '' && $newpath !== '') { |
|
117 | + Storage::renameOrCopy($oldpath, $newpath, 'copy'); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Remember owner and the owner path of the source file. |
|
123 | - * If the file already exists, then it was a upload of a existing file |
|
124 | - * over the web interface and we call Storage::store() directly |
|
125 | - * |
|
126 | - * @param array $params array with oldpath and newpath |
|
127 | - * |
|
128 | - */ |
|
129 | - public static function pre_renameOrCopy_hook($params) { |
|
130 | - // if we rename a movable mount point, then the versions don't have |
|
131 | - // to be renamed |
|
132 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); |
|
133 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
134 | - $mount = $manager->find($absOldPath); |
|
135 | - $internalPath = $mount->getInternalPath($absOldPath); |
|
136 | - if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) { |
|
137 | - return; |
|
138 | - } |
|
121 | + /** |
|
122 | + * Remember owner and the owner path of the source file. |
|
123 | + * If the file already exists, then it was a upload of a existing file |
|
124 | + * over the web interface and we call Storage::store() directly |
|
125 | + * |
|
126 | + * @param array $params array with oldpath and newpath |
|
127 | + * |
|
128 | + */ |
|
129 | + public static function pre_renameOrCopy_hook($params) { |
|
130 | + // if we rename a movable mount point, then the versions don't have |
|
131 | + // to be renamed |
|
132 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); |
|
133 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
134 | + $mount = $manager->find($absOldPath); |
|
135 | + $internalPath = $mount->getInternalPath($absOldPath); |
|
136 | + if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) { |
|
137 | + return; |
|
138 | + } |
|
139 | 139 | |
140 | - $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); |
|
141 | - if ($view->file_exists($params['newpath'])) { |
|
142 | - Storage::store($params['newpath']); |
|
143 | - } else { |
|
144 | - Storage::setSourcePathAndUser($params['oldpath']); |
|
145 | - } |
|
146 | - } |
|
140 | + $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); |
|
141 | + if ($view->file_exists($params['newpath'])) { |
|
142 | + Storage::store($params['newpath']); |
|
143 | + } else { |
|
144 | + Storage::setSourcePathAndUser($params['oldpath']); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Load additional scripts when the files app is visible |
|
150 | - */ |
|
151 | - public static function onLoadFilesAppScripts() { |
|
152 | - \OCP\Util::addScript('files_versions', 'files_versions'); |
|
153 | - } |
|
148 | + /** |
|
149 | + * Load additional scripts when the files app is visible |
|
150 | + */ |
|
151 | + public static function onLoadFilesAppScripts() { |
|
152 | + \OCP\Util::addScript('files_versions', 'files_versions'); |
|
153 | + } |
|
154 | 154 | } |