]> source.dussan.org Git - nextcloud-server.git/commitdiff
Emit a new hook, when a file is being updated only
authorJoas Schilling <nickvergessen@gmx.de>
Wed, 9 Apr 2014 14:42:10 +0000 (16:42 +0200)
committerJoas Schilling <nickvergessen@gmx.de>
Tue, 29 Apr 2014 08:34:26 +0000 (10:34 +0200)
The write-hook also is triggered for created files

Fix #8131

lib/private/files/filesystem.php
lib/private/files/view.php

index 434ee495870ca44c41b5b2f0083ce2475be8016c..52df1bec6117c5c823b1521cbb28fc9846dfc59d 100644 (file)
@@ -118,6 +118,22 @@ class Filesystem {
         */
        const signal_post_write = 'post_write';
 
+       /**
+        * signal emitted before file/dir update
+        *
+        * @param string $path
+        * @param bool $run changing this flag to false in hook handler will cancel event
+        */
+       const signal_update = 'update';
+
+       /**
+        * signal emitted after file/dir update
+        *
+        * @param string $path
+        * @param bool $run changing this flag to false in hook handler will cancel event
+        */
+       const signal_post_update = 'post_update';
+
        /**
         * signal emits when reading file/dir
         *
index 31ec8cfacff57d734977b69977e56135923544bb..1291ed170e8837bbaa63e7d8a16290ee9b19b539 100644 (file)
@@ -291,6 +291,15 @@ class View {
                                                                Filesystem::signal_param_run => &$run
                                                        )
                                                );
+                                       } else {
+                                               \OC_Hook::emit(
+                                                       Filesystem::CLASSNAME,
+                                                       Filesystem::signal_update,
+                                                       array(
+                                                               Filesystem::signal_param_path => $this->getHookPath($path),
+                                                               Filesystem::signal_param_run => &$run,
+                                                       )
+                                               );
                                        }
                                        \OC_Hook::emit(
                                                Filesystem::CLASSNAME,
@@ -319,6 +328,12 @@ class View {
                                                                Filesystem::signal_post_create,
                                                                array(Filesystem::signal_param_path => $this->getHookPath($path))
                                                        );
+                                               } else {
+                                                       \OC_Hook::emit(
+                                                               Filesystem::CLASSNAME,
+                                                               Filesystem::signal_post_update,
+                                                               array(Filesystem::signal_param_path => $this->getHookPath($path))
+                                                       );
                                                }
                                                \OC_Hook::emit(
                                                        Filesystem::CLASSNAME,
@@ -335,7 +350,7 @@ class View {
                                return false;
                        }
                } else {
-                       $hooks = ($this->file_exists($path)) ? array('write') : array('create', 'write');
+                       $hooks = ($this->file_exists($path)) ? array('update', 'write') : array('create', 'write');
                        return $this->basicOperation('file_put_contents', $path, $hooks, $data);
                }
        }
@@ -516,6 +531,15 @@ class View {
                                                        Filesystem::signal_param_run => &$run
                                                )
                                        );
+                               } elseif ($run) {
+                                       \OC_Hook::emit(
+                                               Filesystem::CLASSNAME,
+                                               Filesystem::signal_update,
+                                               array(
+                                                       Filesystem::signal_param_path => $this->getHookPath($path2),
+                                                       Filesystem::signal_param_run => &$run,
+                                               )
+                                       );
                                }
                                if ($run) {
                                        \OC_Hook::emit(
@@ -572,6 +596,12 @@ class View {
                                                        Filesystem::signal_post_create,
                                                        array(Filesystem::signal_param_path => $this->getHookPath($path2))
                                                );
+                                       } else {
+                                               \OC_Hook::emit(
+                                                       Filesystem::CLASSNAME,
+                                                       Filesystem::signal_post_update,
+                                                       array(Filesystem::signal_param_path => $this->getHookPath($path2))
+                                               );
                                        }
                                        \OC_Hook::emit(
                                                Filesystem::CLASSNAME,