1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Action; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Create automatically a comment from a webhook. |
16
|
|
|
*/ |
17
|
|
|
class CommentCreation extends Base |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Get automatic action description. |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function getDescription() |
25
|
|
|
{ |
26
|
|
|
return t('Create a comment from an external provider'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the list of compatible events. |
31
|
|
|
* |
32
|
|
|
* @return string[] |
33
|
|
|
*/ |
34
|
|
|
public function getCompatibleEvents() |
35
|
|
|
{ |
36
|
|
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the required parameter for the action (defined by the user). |
41
|
|
|
* |
42
|
|
|
* @return string[] |
43
|
|
|
*/ |
44
|
|
|
public function getActionRequiredParameters() |
45
|
|
|
{ |
46
|
|
|
return []; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the required parameter for the event. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function getEventRequiredParameters() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
'task_id', |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Execute the action (create a new comment). |
63
|
|
|
* |
64
|
|
|
* @param array $data Event data dictionary |
65
|
|
|
* |
66
|
|
|
* @return bool True if the action was executed or false when not executed |
67
|
|
|
*/ |
68
|
|
|
public function doAction(array $data) |
69
|
|
|
{ |
70
|
|
|
return (bool) $this->commentModel->create([ |
|
|
|
|
71
|
|
|
'reference' => isset($data['reference']) ? $data['reference'] : '', |
72
|
|
|
'comment' => $data['comment'], |
73
|
|
|
'task_id' => $data['task_id'], |
74
|
|
|
'user_id' => isset($data['user_id']) && $this->projectPermissionModel->isAssignable($this->getProjectId(), $data['user_id']) ? $data['user_id'] : 0, |
|
|
|
|
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Check if the event data meet the action condition. |
80
|
|
|
* |
81
|
|
|
* @param array $data Event data dictionary |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function hasRequiredCondition(array $data) |
86
|
|
|
{ |
87
|
|
|
return !empty($data['comment']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.