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