HEX
Server: LiteSpeed
System: Linux d8 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: wbwebdes (3015)
PHP: 8.1.31
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/wbwebdes/domains/files.wb-cloud.nl/private_html/apps/activity/docs/create.md
<!--
  - SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: CC0-1.0
-->
# Creating a new event

To create and publish an event to the activity app, a new `IEvent` should be fetched from the activity manager and afterwards be passed to the `publish()` method:

```php
// The activity manager should be automatically injected
// by the type hint OCP\Activity\IManager, when inside a class.
// When you have a plain file without a class, you can use
// \OC::$server->getActivityManager() instead.

$event = $this->activityManager->generateEvent();
...
$this->activityManager->publish($event);
```

The following values **must** be set before publishing an event:

* `setApp()`
* `setType()` - this must match an `\OCP\Activity\ISetting::getIdentifier()`
* `setAffectedUser()`
* `setSubject()`
* `setObject()`

Additionally these values **can** be set:
* `setAuthor()` - if no author is set, the current user will be used
* `setTimestamp()` - if no time is set, the current time will be used
* `setMessage()`
* `setLink()` - should be done in `IProvider::parse()`
* `setIcon()` - should be done in `IProvider::parse()`

The following values **should not** be set on publishing (are not saved), instead they should be set in `IProvider::parse()`:

* `setParsedSubject()`
* `setRichSubject()`
* `setParsedMessage()`
* `setRichMessage()`
* `setChildEvent()`