[Pkg-owncloud-commits] [owncloud-doc] 77/270: add hooks documentation

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit b50d85563e98bebecceb7078cf13ff8c0544d4d9
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Mon May 12 02:42:53 2014 +0200

    add hooks documentation
---
 developer_manual/app/hooks.rst | 171 ++++++++++++++++++++---------------------
 developer_manual/app/users.rst |   2 +-
 2 files changed, 86 insertions(+), 87 deletions(-)

diff --git a/developer_manual/app/hooks.rst b/developer_manual/app/hooks.rst
index e4f2a35..5dc59dc 100644
--- a/developer_manual/app/hooks.rst
+++ b/developer_manual/app/hooks.rst
@@ -4,91 +4,90 @@ Hooks
 
 .. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
 
-In ownCloud apps, function or methods (event handlers) which are used by the app and called by ownCloud core hooks, are generally stored in :file:`apps/appname/lib/hooks.php`. Hooks are a way of implementing the `observer
-pattern`_, and are commonly used by web platform applications to provide clean
-interfaces to third party applications which need to modify core application
-functionality.
-
-In ownCloud, a hook is a function whose name can be used by developers of
-plug-ins to ensure that additional code is executed at a precise place during
-the execution of other parts of ownCloud code. For example, when an ownCloud
-user is deleted, the ownCloud core hook **post_deleteUser** is executed.
-In the calendar app's :file:`appinfo/app.php`, this hook is connected to the app's
-own event handler **deleteUser** (**user** here refers to an ownCloud user;
-**deleteUser** deletes all addressbooks for that a given ownCloud user).
-
-When **post_deleteUser** calls the calender app's **deleteUser** event handler,
-it supplies it with an argument, which is an array containing the user ID of the
-user that has just been deleted. This user ID is then used by the event handler
-to specify which address books to delete. There are three components to the use
-of hooks in this example:
-
-#. The ownCloud core hook **post_deleteUser**, (see what arguments / data it
-   will provide in :file:`lib/user.php`, where it is defined)
-#. The event handler **deleteUser**, defined in :file:`apps/contacts/lib/hooks.php`.
-#. The connection of the hook to the event handler, in
-   :file:`apps/contacts/appinfo/app.php`.
-
-Hook Terminology
-----------------
-
-* **Signal class  / emitter class:** the class that contains the method which
-  contains the creation of the hook (and a call to the **emit()** method)
-  e.g. OC_User
-* **Signal  / signal name:** the name of the hook, e.g. **post_deleteUser**
-* **Slot class**: class housing the event handling method, e.g.
-  **OC_Contacts_Hooks**
-* **Slot name**: event handler method, e.g. deleteUser (function that deletes
-  all contact address books for a user)
+Hooks are used to execute code before or after an event has occured. This is for instance useful to run cleanup code after users, groups or files have been deleted.
 
 Available hooks
----------------
-
-File: **apps/calendar/ajax/events.php**, Class: OC_Calendar
-
-* Hook: getEvents
-
-File: **apps/calendar/index.php**, Class: OC_Calendar
-
-* Hook: getSources
-
-File: **dav.php**, Class: OC_DAV
-
-* Hook: initialize
-
-File: **lib/migrate.php**, Class: OC_User
-
-* Hook: pre_createUser
-* Hook: post_createUser
-
-File: **lib/filecache.php**, Class: OC_Filesystem
-
-* Hook: post_write
-* Hook: post_write
-* Hook: post_delete
-* Hook: post_write
-
-File: **lib/user.php**, Class: OC_User
-
-* Hook: pre_createUser
-* Hook: post_createUser
-* Hook: pre_deleteUser
-* Hook: post_deleteUser
-* Hook: pre_login
-* Hook: post_login
-* Hook: logout
-* Hook: pre_setPassword
-* Hook: post_setPassword
-
-File: **lib/group.php**, Class: OC_Group
-
-* Hook: pre_createGroup
-* Hook: post_createGroup
-* Hook: pre_deleteGroup
-* Hook: post_deleteGroup
-* Hook: pre_addToGroup
-* Hook: post_addToGroup
-* Hook: pre_removeFromGroup
-* Hook: post_removeFromGroup
-
-.. _observer pattern: https://en.wikipedia.org/wiki/Observer_pattern
+===============
+The scope is the first parameter that is passed to the **listen** method, the second parameter is the method and the third one the callback that should be executed once the hook is being called, e.g.:
+
+.. code-block:: php
+
+    <?php
+    
+    // listen on user predelete
+    $userManager->listen('\OC\User', 'preDelete', function($user) {
+        // your code that executes before $user is deleted
+    });
+
+
+Hooks can also be removed by using the **removeListener** method on the object.
+
+The following hooks are available:
+
+Session
+-------
+Injectable from the ServerContainer by calling the method **getUserSession**. 
+
+Hooks available in scope **\\OC\\User**:
+ 
+* **preSetPassword** (\\OC\\User\\User $user, string $password, string $recoverPassword)
+* **postSetPassword** (\\OC\\User\\User $user, string $password, string $recoverPassword)
+* **preDelete** (\\OC\\User\\User $user)
+* **postDelete** (\\OC\\User\\User $user)
+* **preCreateUser** (string $uid, string $password)
+* **postCreateUser** (\\OC\\User\\User $user)
+* **preLogin** (string $user, string $password)
+* **postLogin** (\\OC\\User\\User $user)
+* **logout** ()
+
+UserManager
+-----------
+Injectable from the ServerContainer by calling the method **getUserManager**. 
+
+Hooks available in scope **\\OC\\User**:
+
+* **preSetPassword** (\\OC\\User\\User $user, string $password, string $recoverPassword)
+* **postSetPassword** (\\OC\\User\\User $user, string $password, string $recoverPassword)
+* **preDelete** (\\OC\\User\\User $user)
+* **postDelete** (\\OC\\User\\User $user)
+* **preCreateUser** (string $uid, string $password)
+* **postCreateUser** (\\OC\\User\\User $user, string $password)
+
+GroupManager
+------------
+Hooks available in scope **\\OC\\Group**:
+
+* **preAddUser** (\\OC\\Group\\Group $group, \\OC\\User\\User $user)
+* **postAddUser** (\\OC\\Group\\Group $group, \\OC\\User\\User $user)
+* **preRemoveUser** (\\OC\\Group\\Group $group, \\OC\\User\\User $user)
+* **postRemoveUser** (\\OC\\Group\\Group $group, \\OC\\User\\User $user)
+* **preDelete** (\\OC\\Group\\Group $group)
+* **postDelete** (\\OC\\Group\\Group $group)
+* **preCreate** (string $groupId)
+* **postCreate** (\\OC\\Group\\Group $group)
+
+Root
+----
+Injectable from the ServerContainer by calling the method **getRootFolder**, **getUserFolder** or **getAppFolder**.
+
+Filesystem hooks available in scope **\\OC\\Files**:
+
+* **preWrite** (\\OCP\\Files\\Node $node)
+* **postWrite** (\\OCP\\Files\\Node $node)
+* **preCreate** (\\OCP\\Files\\Node $node)
+* **postCreate** (\\OCP\\Files\\Node $node)
+* **preDelete** (\\OCP\\Files\\Node $node)
+* **postDelete** (\\OCP\\Files\\Node $node)
+* **preTouch** (\\OC\\FilesP\\Node $node, int $mtime)
+* **postTouch** (\\OCP\\Files\\Node $node)
+* **preCopy** (\\OCP\\Files\\Node $source, \\OCP\\Files\\Node $target)
+* **postCopy** (\\OCP\\Files\\Node $source, \\OCP\\Files\\Node $target)
+* **preRename** (\\OCP\\Files\\Node $source, \\OCP\\Files\\Node $target)
+* **postRename** (\\OCP\\Files\\Node $source, \\OCP\\Files\\Node $target)
+
+Scanner
+-------
+Filesystem scanner hooks available in scope **\\OC\\Utils\\Scanner**:
+
+* **scanFile** (string $absolutePath)
+* **scanFolder** (string $absolutePath)
\ No newline at end of file
diff --git a/developer_manual/app/users.rst b/developer_manual/app/users.rst
index 77c6b29..944ff9d 100644
--- a/developer_manual/app/users.rst
+++ b/developer_manual/app/users.rst
@@ -134,7 +134,7 @@ To login, logout or getting the currently logged in user, the Session has to be
             });
 
             $container->registerService('Session', function($c) {
-                return $c->query('ServerContainer')->getSession();
+                return $c->query('ServerContainer')->getUserSession();
             });
 
             // currently logged in user, userId can be gotten by calling the

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list