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
|
|
|
* @param int|User $changeBy |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
8 |
|
public function queueUpdate(Issue $issue, $changeBy) |
34
|
|
|
{ |
35
|
|
|
// Number of changed attributes |
36
|
8 |
|
$countChanges = count($issue->getDirty()); |
37
|
|
|
|
38
|
|
|
// Whether or not the assignee has changed |
39
|
8 |
|
$noMessageForMe = false; |
40
|
|
|
|
41
|
|
|
// is Closed? |
42
|
8 |
|
if (!$issue->isOpen()) { |
43
|
7 |
|
return (new Queue())->queue(Queue::CLOSE_ISSUE, $issue, $changeBy); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// is Reopened? |
47
|
4 |
|
if ((int) $issue->getOriginal('status') === Issue::STATUS_CLOSED) { |
48
|
2 |
|
return (new Queue())->queue(Queue::REOPEN_ISSUE, $issue, $changeBy); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// If the assignee has changed and it is not the logged in user who made the action |
52
|
3 |
|
if ($issue->assigned_to !== $issue->getOriginal('assigned_to', $issue->assigned_to) |
53
|
3 |
|
&& $changeBy->id !== $issue->assigned_to |
54
|
|
|
) { |
55
|
|
|
(new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, $changeBy); |
56
|
|
|
$noMessageForMe = $issue->assigned_to; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// If the update was just for assigning user, then skip update issue |
60
|
3 |
|
if (!($countChanges === 1 && $noMessageForMe !== false)) { |
61
|
3 |
|
return (new Queue())->queue(Queue::UPDATE_ISSUE, $issue, $changeBy); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Insert add issue to message queue. |
67
|
|
|
* |
68
|
|
|
* @param Issue $issue |
69
|
|
|
* @param int|User $changeBy |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
31 |
|
public function queueAdd(Issue $issue, $changeBy) |
74
|
|
|
{ |
75
|
31 |
|
return (new Queue())->queue(Queue::ADD_ISSUE, $issue, $changeBy); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Insert assign issue to message queue. |
80
|
|
|
* |
81
|
|
|
* @param Issue $issue |
82
|
|
|
* @param int|User $changeBy |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
3 |
|
public function queueAssign(Issue $issue, $changeBy) |
87
|
|
|
{ |
88
|
|
|
// If the assignee has changed and it is not the logged in user who made the action |
89
|
3 |
|
$changeBy = $changeBy instanceof User? $changeBy->id : $changeBy; |
90
|
3 |
|
if ($issue->assigned_to > 0 && $changeBy !== $issue->assigned_to) { |
91
|
3 |
|
return (new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, $changeBy); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Insert issue tag changes to message queue. |
97
|
|
|
* |
98
|
|
|
* @param Issue $issue |
99
|
|
|
* @param array $addedTags |
100
|
|
|
* @param array $removedTags |
101
|
|
|
* @param int|User $changeBy |
102
|
|
|
* |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
4 |
|
public function queueChangeTags(Issue $issue, array $addedTags, array $removedTags, $changeBy) |
106
|
|
|
{ |
107
|
4 |
|
$queue = new Queue(); |
108
|
|
|
|
109
|
4 |
|
return $queue->queueIssueTagChanges($issue, $addedTags, $removedTags, $changeBy); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.