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 User $changeBy |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
8 |
|
public function queueUpdate(Issue $issue, User $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 User $changeBy |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
31 |
|
public function queueAdd(Issue $issue, User $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 User $changeBy |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
3 |
|
public function queueAssign(Issue $issue, User $changeBy) |
87
|
|
|
{ |
88
|
|
|
// If the assignee has changed and it is not the logged in user who made the action |
89
|
3 |
|
if ($issue->assigned_to > 0 && $changeBy->id !== $issue->assigned_to) { |
90
|
3 |
|
return (new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, $changeBy); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Insert issue tag changes to message queue. |
96
|
|
|
* |
97
|
|
|
* @param Issue $issue |
98
|
|
|
* @param array $addedTags |
99
|
|
|
* @param array $removedTags |
100
|
|
|
* @param User $changeBy |
101
|
|
|
* |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
4 |
|
public function queueChangeTags(Issue $issue, array $addedTags, array $removedTags, User $changeBy) |
105
|
|
|
{ |
106
|
4 |
|
$queue = new Queue(); |
107
|
|
|
|
108
|
4 |
|
return $queue->queueIssueTagChanges($issue, $addedTags, $removedTags, $changeBy); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|