Conditions | 9 |
Paths | 9 |
Total Lines | 33 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 9.111 |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
20 | 783 | public function __invoke(\Elgg\Event $event): void { |
|
21 | 783 | $entity = $event->getObject(); |
|
22 | 783 | if (!$entity instanceof \ElggObject && !$entity instanceof \ElggGroup) { |
|
23 | return; |
||
24 | } |
||
25 | |||
26 | 783 | $owner = $entity->getOwnerEntity(); |
|
27 | 783 | if (!$owner instanceof \ElggUser) { |
|
28 | 45 | return; |
|
29 | } |
||
30 | |||
31 | 743 | if ($entity instanceof \ElggObject) { |
|
32 | 572 | $notification_events = _elgg_services()->notifications->getEvents(); |
|
33 | 572 | if (!isset($notification_events[$entity->getType()]) || !isset($notification_events[$entity->getType()][$entity->getSubtype()])) { |
|
34 | // no notification events registered for this entity type/subtype |
||
35 | // so there is no need to subscribe |
||
36 | // this also prevents the database from flooding with relationships that are never used (e.g. subscriptions to site notifications) |
||
37 | 531 | return; |
|
38 | } |
||
39 | } |
||
40 | |||
41 | 289 | $content_preferences = $owner->getNotificationSettings('content_create'); |
|
42 | 289 | $enabled_methods = array_keys(array_filter($content_preferences)); |
|
43 | |||
44 | // loop through all notification types |
||
45 | 289 | $methods = elgg_get_notification_methods(); |
|
46 | 289 | foreach ($enabled_methods as $method) { |
|
47 | // only enable supported methods |
||
48 | 289 | if (!in_array($method, $methods)) { |
|
49 | continue; |
||
50 | } |
||
51 | |||
52 | 289 | $entity->addSubscription($owner->guid, $method); |
|
53 | } |
||
56 |