1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Data Analytics |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the LICENSE.md file. |
8
|
|
|
* |
9
|
|
|
* @author Marcel Scherello <[email protected]> |
10
|
|
|
* @copyright 2019 Marcel Scherello |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Analytics\Notification; |
14
|
|
|
|
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use OCP\IURLGenerator; |
17
|
|
|
use OCP\IUserManager; |
18
|
|
|
use OCP\L10N\IFactory; |
19
|
|
|
use OCP\Notification\AlreadyProcessedException; |
|
|
|
|
20
|
|
|
use OCP\Notification\IManager as INotificationManager; |
21
|
|
|
use OCP\Notification\INotification; |
22
|
|
|
use OCP\Notification\INotifier; |
23
|
|
|
|
24
|
|
|
class Notifier implements INotifier |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** @var IFactory */ |
28
|
|
|
protected $l10nFactory; |
29
|
|
|
|
30
|
|
|
/** @var INotificationManager */ |
31
|
|
|
protected $notificationManager; |
32
|
|
|
|
33
|
|
|
/** @var IUserManager */ |
34
|
|
|
protected $userManager; |
35
|
|
|
|
36
|
|
|
/** @var IURLGenerator */ |
37
|
|
|
protected $urlGenerator; |
38
|
|
|
|
39
|
|
|
public function __construct(IFactory $l10nFactory, |
40
|
|
|
INotificationManager $notificationManager, |
41
|
|
|
IUserManager $userManager, |
42
|
|
|
IURLGenerator $urlGenerator) |
43
|
|
|
{ |
44
|
|
|
$this->l10nFactory = $l10nFactory; |
45
|
|
|
$this->notificationManager = $notificationManager; |
46
|
|
|
$this->userManager = $userManager; |
47
|
|
|
$this->urlGenerator = $urlGenerator; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
* @since 17.0.0 |
55
|
|
|
*/ |
56
|
|
|
public function getID(): string |
57
|
|
|
{ |
58
|
|
|
return 'analytics'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Human readable name describing the notifier |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
* @since 17.0.0 |
66
|
|
|
*/ |
67
|
|
|
public function getName(): string |
68
|
|
|
{ |
69
|
|
|
return $this->l10nFactory->get('analytics')->t('Announcements'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param INotification $notification |
74
|
|
|
* @param string $languageCode The code of the language that should be used to prepare the notification |
75
|
|
|
* @return INotification |
76
|
|
|
* @throws InvalidArgumentException When the notification was not prepared by a notifier |
77
|
|
|
*/ |
78
|
|
|
public function prepare(INotification $notification, $languageCode) |
79
|
|
|
{ |
80
|
|
|
if ($notification->getApp() !== 'analytics') { |
81
|
|
|
// Not my app => throw |
82
|
|
|
throw new InvalidArgumentException('Unknown app'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Read the language from the notification |
86
|
|
|
$l = $this->l10nFactory->get('analytics', $languageCode); |
87
|
|
|
|
88
|
|
|
$i = $notification->getSubject(); |
89
|
|
|
if ($i !== 'alert') { |
90
|
|
|
// Unknown subject => Unknown notification => throw |
91
|
|
|
throw new InvalidArgumentException('Unknown subject'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$link = $this->urlGenerator->linkToRouteAbsolute('analytics.page.main', [ |
95
|
|
|
'analytics' => $notification->getObjectId(), |
96
|
|
|
]); |
97
|
|
|
|
98
|
|
|
$notification->setParsedMessage('test message') |
99
|
|
|
->setRichSubject( |
100
|
|
|
$l->t('{user} announced '), |
101
|
|
|
[ |
102
|
|
|
'user' => [ |
103
|
|
|
'type' => 'user', |
104
|
|
|
'id' => 1, |
105
|
|
|
'name' => 'testuser', |
106
|
|
|
] |
107
|
|
|
] |
108
|
|
|
) |
109
|
|
|
->setLink($link) |
110
|
|
|
->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('analytics', 'app-dark.svg'))); |
111
|
|
|
|
112
|
|
|
$notification->setParsedSubject($notification); |
|
|
|
|
113
|
|
|
return $notification; |
114
|
|
|
} |
115
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths