1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
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 Tinyissue\Model\Traits\Project\Issue; |
13
|
|
|
|
14
|
|
|
use Tinyissue\Model\Project\Issue; |
15
|
|
|
use Tinyissue\Model\Message\Queue; |
16
|
|
|
use Tinyissue\Model\User; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* QueueTrait is trait class for adding method to insert records into a queue. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
trait QueueTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Insert update issue to message queue. |
27
|
|
|
* |
28
|
|
|
* @param Issue $issue |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
5 |
|
public function queueUpdate(Issue $issue) |
33
|
|
|
{ |
34
|
|
|
// Number of changed attributes |
35
|
5 |
|
$countChanges = count($issue->getDirty()); |
36
|
|
|
|
37
|
|
|
// Whether or not the assignee has changed |
38
|
5 |
|
$noMessageForMe = false; |
39
|
|
|
|
40
|
|
|
// is Closed? |
41
|
5 |
|
if (!$issue->isOpen()) { |
42
|
4 |
|
return (new Queue())->queue(Queue::CLOSE_ISSUE, $issue, auth()->user()); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// is Reopened? |
46
|
2 |
|
if ((int) $issue->getOriginal('status') === Issue::STATUS_CLOSED) { |
47
|
1 |
|
return (new Queue())->queue(Queue::REOPEN_ISSUE, $issue, auth()->user()); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// If the assignee has changed and it is not the logged in user who made the action |
51
|
1 |
|
if ($issue->assigned_to !== $issue->getOriginal('assigned_to', $issue->assigned_to) |
52
|
1 |
|
&& auth()->user()->id !== $issue->assigned_to |
|
|
|
|
53
|
|
|
) { |
54
|
|
|
(new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, auth()->user()); |
|
|
|
|
55
|
|
|
$noMessageForMe = $issue->assigned_to; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// If the update was just for assigning user, then skip update issue |
59
|
1 |
|
if (!($countChanges === 1 && $noMessageForMe !== false)) { |
60
|
1 |
|
return (new Queue())->queue(Queue::UPDATE_ISSUE, $issue, auth()->user()); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Insert add issue to message queue. |
66
|
|
|
* |
67
|
|
|
* @param Issue $issue |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
28 |
|
public function queueAdd(Issue $issue) |
72
|
|
|
{ |
73
|
28 |
|
return (new Queue())->queue(Queue::ADD_ISSUE, $issue, auth()->user()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Insert assign issue to message queue. |
78
|
|
|
* |
79
|
|
|
* @param Issue $issue |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
2 |
|
public function queueAssign(Issue $issue) |
84
|
|
|
{ |
85
|
|
|
// If the assignee has changed and it is not the logged in user who made the action |
86
|
2 |
|
if ($issue->assigned_to > 0 && auth()->user()->id !== $issue->assigned_to) { |
|
|
|
|
87
|
2 |
|
return (new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, auth()->user()); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Insert issue tag changes to message queue. |
93
|
|
|
* |
94
|
|
|
* @param Issue $issue |
95
|
|
|
* @param array $addedTags |
96
|
|
|
* @param array $removedTags |
97
|
|
|
* |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
2 |
|
public function queueChangeTags(Issue $issue, array $addedTags, array $removedTags) |
101
|
|
|
{ |
102
|
2 |
|
$user = auth()->user(); |
103
|
2 |
|
$queue = new Queue(); |
104
|
|
|
|
105
|
2 |
|
return $queue->queueIssueTagChanges($issue, $addedTags, $removedTags, $user); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: