1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coyote\Listeners; |
4
|
|
|
|
5
|
|
|
use Coyote\Events\CommentDeleted; |
6
|
|
|
use Coyote\Events\CommentSaved; |
7
|
|
|
use Coyote\Events\PostWasDeleted; |
8
|
|
|
use Coyote\Events\PostSaved; |
9
|
|
|
use Coyote\Events\TopicWasDeleted; |
10
|
|
|
use Coyote\Events\TopicWasMoved; |
11
|
|
|
use Coyote\Post; |
12
|
|
|
use Coyote\Repositories\Contracts\ActivityRepositoryInterface as ActivityRepository; |
13
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
14
|
|
|
|
15
|
|
|
class ActivitySubscriber implements ShouldQueue |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var ActivityRepository |
19
|
|
|
*/ |
20
|
|
|
private $activity; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ActivitySubscriber constructor. |
24
|
|
|
* @param ActivityRepository $activity |
25
|
|
|
*/ |
26
|
|
|
public function __construct(ActivityRepository $activity) |
27
|
|
|
{ |
28
|
|
|
$this->activity = $activity; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param PostSaved $event |
33
|
|
|
*/ |
34
|
|
|
public function onPostSaved(PostSaved $event) |
35
|
|
|
{ |
36
|
|
|
$this->activity->updateOrCreate([ |
|
|
|
|
37
|
|
|
'content_type' => Post::class, |
38
|
|
|
'content_id' => $event->post->id, |
39
|
|
|
], [ |
40
|
|
|
'created_at' => $event->post->created_at, |
41
|
|
|
'user_id' => $event->post->user_id, |
42
|
|
|
'forum_id' => $event->post->forum_id, |
43
|
|
|
'topic_id' => $event->post->topic_id, |
44
|
|
|
'excerpt' => excerpt($event->post->html), |
45
|
|
|
'user_name' => $event->post->user_name |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param PostWasDeleted $event |
51
|
|
|
*/ |
52
|
|
|
public function onPostDeleted(PostWasDeleted $event) |
53
|
|
|
{ |
54
|
|
|
$this->activity->where('content_id', $event->post['id'])->where('content_type', Post::class)->delete(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function onTopicDeleted(TopicWasDeleted $event) |
58
|
|
|
{ |
59
|
|
|
$this->activity->where('topic_id', $event->topic['id'])->delete(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function onTopicMoved(TopicWasMoved $event) |
63
|
|
|
{ |
64
|
|
|
$this->activity->where('topic_id', $event->topic['id'])->update(['forum_id' => $event->topic['forum_id']]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param CommentSaved $event |
69
|
|
|
*/ |
70
|
|
|
public function onCommentSaved(CommentSaved $event) |
71
|
|
|
{ |
72
|
|
|
$this->activity->updateOrCreate([ |
73
|
|
|
'content_id' => $event->comment->id, |
74
|
|
|
'content_type' => Post\Comment::class, |
75
|
|
|
], [ |
76
|
|
|
'created_at' => $event->comment->created_at, |
77
|
|
|
'user_id' => $event->comment->user_id, |
78
|
|
|
'forum_id' => $event->comment->post->forum_id, |
79
|
|
|
'topic_id' => $event->comment->post->topic_id, |
80
|
|
|
'excerpt' => excerpt($event->comment->html) |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param CommentDeleted $event |
86
|
|
|
*/ |
87
|
|
|
public function onCommentDeleted(CommentDeleted $event) |
88
|
|
|
{ |
89
|
|
|
$this->activity->where('content_id', $event->comment['id'])->where('content_type', Post\Comment::class)->delete(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Register the listeners for the subscriber. |
94
|
|
|
* |
95
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
96
|
|
|
*/ |
97
|
|
|
public function subscribe($events) |
98
|
|
|
{ |
99
|
|
|
$events->listen( |
100
|
|
|
PostSaved::class, |
101
|
|
|
'Coyote\Listeners\ActivitySubscriber@onPostSaved' |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$events->listen( |
105
|
|
|
PostWasDeleted::class, |
106
|
|
|
'Coyote\Listeners\ActivitySubscriber@onPostDeleted' |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$events->listen( |
110
|
|
|
TopicWasDeleted::class, |
111
|
|
|
'Coyote\Listeners\ActivitySubscriber@onTopicDeleted' |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$events->listen( |
115
|
|
|
TopicWasMoved::class, |
116
|
|
|
'Coyote\Listeners\ActivitySubscriber@onTopicMoved' |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$events->listen( |
120
|
|
|
CommentSaved::class, |
121
|
|
|
'Coyote\Listeners\ActivitySubscriber@onCommentSaved' |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$events->listen( |
125
|
|
|
CommentDeleted::class, |
126
|
|
|
'Coyote\Listeners\ActivitySubscriber@onCommentDeleted' |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.