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\Comment; |
13
|
|
|
|
14
|
|
|
use Tinyissue\Model\Project\Issue\Comment; |
15
|
|
|
use Tinyissue\Model\Message; |
16
|
|
|
use Tinyissue\Model\Message\Queue; |
17
|
|
|
use Tinyissue\Model\User; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* QueueTrait is trait class for adding method to insert records into a queue. |
21
|
|
|
* |
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
trait QueueTrait |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Insert add comment to message queue. |
28
|
|
|
* |
29
|
|
|
* @param Comment $comment |
30
|
|
|
* @param int|User $changeBy |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
8 |
|
public function queueAdd(Comment $comment, $changeBy) |
35
|
|
|
{ |
36
|
|
|
// Skip message if issue closed |
37
|
8 |
|
if (!$comment->issue->isOpen()) { |
38
|
4 |
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
4 |
|
return (new Message\Queue())->queue(Queue::ADD_COMMENT, $comment, $changeBy); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Insert update comment to message queue. |
46
|
|
|
* |
47
|
|
|
* @param Comment $comment |
48
|
|
|
* @param int|User $changeBy |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
1 |
|
public function queueUpdate(Comment $comment, $changeBy) |
53
|
|
|
{ |
54
|
|
|
// Skip message if issue closed or nothing changed in comment |
55
|
1 |
|
if (!$comment->issue->isOpen() || !$comment->isDirty()) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
return (new Message\Queue())->queue(Queue::UPDATE_COMMENT, $comment, $changeBy); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Insert delete comment to message queue. |
64
|
|
|
* |
65
|
|
|
* @param Comment $comment |
66
|
|
|
* @param int|User $changeBy |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function queueDelete(Comment $comment, $changeBy) |
71
|
|
|
{ |
72
|
|
|
// Skip message if issue closed |
73
|
|
|
if (!$comment->issue->isOpen()) { |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return (new Message\Queue())->queueDelete(Queue::DELETE_COMMENT, $comment, $changeBy); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|