mirror of
https://github.com/nextcloud/documentation.git
synced 2026-01-04 10:46:21 +07:00
93 lines
3.4 KiB
ReStructuredText
93 lines
3.4 KiB
ReStructuredText
=====
|
|
Hooks
|
|
=====
|
|
|
|
.. sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>
|
|
|
|
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
|
|
===============
|
|
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)
|
|
|
|
Filesystem 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)
|
|
|
|
Filesystem Scanner
|
|
------------------
|
|
Filesystem scanner hooks available in scope **\\OC\\Utils\\Scanner**:
|
|
|
|
* **scanFile** (string $absolutePath)
|
|
* **scanFolder** (string $absolutePath) |