3232
3333namespace OCA \Files_Versions ;
3434
35+ use OC \Files \Filesystem ;
36+ use Symfony \Component \EventDispatcher \GenericEvent ;
37+
3538class Hooks {
3639
3740 public static function connectHooks () {
41+ $ hooks = new Hooks ();
3842 // Listen to write signals
3943 \OCP \Util::connectHook ('OC_Filesystem ' , 'write ' , 'OCA\Files_Versions\Hooks ' , 'write_hook ' );
4044 // Listen to delete and rename signals
4145 \OCP \Util::connectHook ('OC_Filesystem ' , 'post_delete ' , 'OCA\Files_Versions\Hooks ' , 'remove_hook ' );
4246 \OCP \Util::connectHook ('OC_Filesystem ' , 'delete ' , 'OCA\Files_Versions\Hooks ' , 'pre_remove_hook ' );
43- \OCP \Util:: connectHook ( ' OC_Filesystem ' , ' post_rename ' , 'OCA\Files_Versions\Hooks ' , ' rename_hook ' );
44- \OCP \Util:: connectHook ( ' OC_Filesystem ' , ' post_copy ' , 'OCA\Files_Versions\Hooks ' , ' copy_hook ' );
47+ \OC :: $ server -> getEventDispatcher ()-> addListener ( ' file.afterrename ' , [ $ hooks , 'rename_hook ' ] );
48+ \OC :: $ server -> getEventDispatcher ()-> addListener ( ' file.aftercopy ' , [ $ hooks , 'copy_hook ' ] );
4549 \OCP \Util::connectHook ('OC_Filesystem ' , 'rename ' , 'OCA\Files_Versions\Hooks ' , 'pre_renameOrCopy_hook ' );
4650 \OCP \Util::connectHook ('OC_Filesystem ' , 'copy ' , 'OCA\Files_Versions\Hooks ' , 'pre_renameOrCopy_hook ' );
4751
@@ -98,11 +102,13 @@ public static function pre_remove_hook($params) {
98102 * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
99103 * of the stored versions along the actual file
100104 */
101- public static function rename_hook ($ params ) {
105+ public static function rename_hook (GenericEvent $ params ) {
102106
103107 if (\OCP \App::isEnabled ('files_versions ' )) {
104- $ oldpath = $ params ['oldpath ' ];
105- $ newpath = $ params ['newpath ' ];
108+ $ oldpath = $ params ->getArgument ('oldpath ' );
109+ $ oldpath = Filesystem::getView ()->getRelativePath ($ oldpath );
110+ $ newpath = $ params ->getArgument ('newpath ' );
111+ $ newpath = Filesystem::getView ()->getRelativePath ($ newpath );
106112 if ($ oldpath <>'' && $ newpath <>'' ) {
107113 Storage::renameOrCopy ($ oldpath , $ newpath , 'rename ' );
108114 }
@@ -116,11 +122,13 @@ public static function rename_hook($params) {
116122 * This function is connected to the copy signal of OC_Filesystem and copies the
117123 * the stored versions to the new location
118124 */
119- public static function copy_hook ($ params ) {
125+ public static function copy_hook (GenericEvent $ params ) {
120126
121127 if (\OCP \App::isEnabled ('files_versions ' )) {
122- $ oldpath = $ params ['oldpath ' ];
123- $ newpath = $ params ['newpath ' ];
128+ $ oldpath = $ params ->getArgument ('oldpath ' );
129+ $ oldpath = Filesystem::getView ()->getRelativePath ($ oldpath );
130+ $ newpath = $ params ->getArgument ('newpath ' );
131+ $ newpath = Filesystem::getView ()->getRelativePath ($ newpath );
124132 if ($ oldpath <>'' && $ newpath <>'' ) {
125133 Storage::renameOrCopy ($ oldpath , $ newpath , 'copy ' );
126134 }
0 commit comments