PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.11.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.11.0
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
← All changes | app/Hooks/Handlers/CleanupHandler.php +89 -18 1.0.92 → 2.11.0 View file →
@@ -5,10 +5,8 @@
5 5 use FluentCommunity\App\Functions\Utility;
6 6 use FluentCommunity\App\Models\Media;
7 7 use FluentCommunity\App\Models\Notification;
8 8 use FluentCommunity\App\Models\NotificationSubscriber;
9 -use FluentCommunity\App\Models\Reaction;
10 -use FluentCommunity\App\Services\Helper;
11 9
12 10 class CleanupHandler
13 11 {
14 12 public function register()
@@ -13,13 +11,13 @@
13 11 {
14 12 public function register()
15 13 {
16 14 add_action('fluent_community/feed/before_deleted', [$this, 'handleFeedDeleted'], 10, 1);
17 - add_action('fluent_community/feed/hashtags_deleted', [$this, 'handleHashTagDeleted'], 10, 1);
15 + add_action('fluent_community/lesson/before_deleted', [$this, 'handleLessonDeleted'], 10, 1);
18 16 add_action('fluent_community/remove_old_notifications', [$this, 'maybeDeleteOldNotifications']);
19 17
20 18 add_action('fluent_community/comment/media_deleted', [$this, 'queueMediaDelete'], 10, 1);
21 - add_action('fluent_community/feed/media_deleted', [$this, 'queueMediaDelete'], 10, 1);
19 + add_action('fluent_community/feed/media_deleted', [$this, 'handleMediaDelete'], 10, 1);
22 20 add_action('fluent_community/maybe_delete_draft_medias', [$this, 'deleteOldDraftMedias'], 10);
23 21 add_action('fluent_community/remove_medias_by_url', function ($mediaUrls, $wheres = []) {
24 22 if (!$mediaUrls) {
25 23 return;
@@ -39,39 +37,89 @@
39 37 $this->queueMediaDelete($media);
40 38 }, 10, 2);
41 39
42 40 add_action('deleted_user', [$this, 'handleUserDeleted'], 10, 2);
41 + }
43 42
43 + public function handleMediaDelete($media)
44 + {
45 + if(!$media) {
46 + return;
47 + }
48 +
49 + if ($media && $media instanceof Media && $media->object_source == 'lesson_document') {
50 + $this->handleLessonMediaDelete($media->feed_id, $media);
51 + return;
52 + }
53 +
54 + $this->queueMediaDelete($media);
44 55 }
45 56
46 57 public function handleFeedDeleted($feed)
47 58 {
48 - $feed->comments()->delete();
59 + foreach ($feed->comments as $comment) {
60 + $comment->delete();
61 + }
62 +
49 63 $feed->reactions()->delete();
50 64 $feed->activities()->delete();
51 - $this->handleHashTagDeleted($feed->terms);
52 65 $this->queueMediaDelete($feed->media);
53 66
54 - if ($feed->comtent_type == 'survey') {
55 - Reaction::where('type', 'survey_vote')
56 - ->where('object_id', $feed->id)
57 - ->delete();
58 - }
59 -
60 67 // Loop is used to delete notification with notified user data from fcom_notification_users table
61 68 foreach ($feed->notifications as $notification) {
62 69 $notification->delete();
63 70 }
71 +
72 + Utility::getApp('db')->table('fcom_term_feed')->where('post_id', $feed->id)->delete();
64 73 }
65 74
66 - public function handleHashTagDeleted($terms)
75 + public function handleLessonMediaDelete($lessonId, $media, $mediaKeys = [], $isCollection = false)
67 76 {
68 - // Loop is used to delete terms with related data from fcom_term_feed table
69 - foreach ($terms as $term) {
70 - $term->delete();
77 + $mediaKeys = $isCollection ? $mediaKeys : [$media->media_key];
78 +
79 + $duplicateMediaKeys = Media::whereIn('media_key', $mediaKeys)
80 + ->where('feed_id', '!=', $lessonId)
81 + ->groupBy('media_key')
82 + ->pluck('media_key')
83 + ->all();
84 +
85 + $deletedIds = [];
86 + if (!empty($duplicateMediaKeys)) {
87 + $deletedIds = Media::where('feed_id', $lessonId)
88 + ->whereIn('media_key', $duplicateMediaKeys)
89 + ->pluck('id')
90 + ->all();
91 +
92 + Media::where('feed_id', $lessonId)
93 + ->whereIn('media_key', $duplicateMediaKeys)
94 + ->delete();
71 95 }
96 +
97 + if (!$isCollection) {
98 + if (empty($deletedIds)) {
99 + $this->queueMediaDelete($media);
100 + }
101 + return;
102 + }
103 +
104 + $lessonMedia = $media ? $media->filter(function ($medium) use ($deletedIds) {
105 + return !in_array($medium->id, $deletedIds);
106 + }) : null;
107 +
108 + $this->queueMediaDelete($lessonMedia);
72 109 }
73 110
111 + public function handleLessonDeleted($lesson)
112 + {
113 + $lesson->comments()->delete();
114 + $lesson->reactions()->delete();
115 + $lesson->lessonCompleted()->delete();
116 +
117 + $mediaKeys = $lesson->media ? $lesson->media->pluck('media_key')->all() : [];
118 +
119 + $this->handleLessonMediaDelete($lesson->id, $lesson->media, $mediaKeys, true);
120 + }
121 +
74 122 public function queueMediaDelete($media)
75 123 {
76 124 if (is_null($media)) {
77 125 return false;
@@ -142,17 +190,31 @@
142 190 $ids[] = $notification->id;
143 191 }
144 192
145 193 if (!$ids) {
194 + // Let's delete meta data
195 + Utility::getApp('db')->table('fcom_meta')
196 + ->where('object_type', 'feed')
197 + ->whereIn('meta_key', [
198 + '_last_mention_email_user_id',
199 + '_last_email_user_id'
200 + ])
201 + ->limit(9000)
202 + ->where('created_at', '<', gmdate('Y-m-d H:i:s', strtotime('-1 week')))
203 + ->delete();
204 +
146 205 return false;
147 206 }
148 207
149 208 NotificationSubscriber::whereIn('object_id', $ids)->delete();
150 - $notifications->delete();
151 209
210 + Notification::whereIn('id', $ids)->delete();
211 +
152 212 if (microtime(true) - FLUENT_COMMUNITY_START_TIME < 30) {
153 213 $this->maybeDeleteOldNotifications();
154 214 }
215 +
216 +
155 217 }
156 218
157 219 public function deleteOldDraftMedias()
158 220 {
@@ -187,8 +249,9 @@
187 249 *
188 250 * fcom_meta where object_type = user and object_id = user_id
189 251 *
190 252 * fcom_notification_users where user_id = user_id
253 + * fcom_notification_prefs where user_id = user_id
191 254 * fcom_post_comments where user_id = user_id
192 255 * fcom_post_reactions where user_id = user_id
193 256 * fcom_posts where user_id = user_id & type = text
194 257 * fcom_space_user where user_id = user_id
@@ -202,11 +265,16 @@
202 265 *
203 266 *
204 267 */
205 268 if (defined('FLUENT_MESSAGING_CHAT_VERSION')) {
269 + \FluentMessaging\App\Models\Thread::whereHas('thread_users', function ($q) use ($userId) {
270 + $q->where('user_id', $userId);
271 + })
272 + ->whereNull('space_id')
273 + ->delete();
274 +
206 275 Utility::getApp('db')->table('fcom_chat_messages')->where('user_id', $userId)->delete();
207 276 Utility::getApp('db')->table('fcom_chat_thread_users')->where('user_id', $userId)->delete();
208 - Utility::getApp('db')->table('fcom_chat_thread_users')->where('user_id', $userId)->delete();
209 277 }
210 278
211 279 // meta
212 280 Utility::getApp('db')->table('fcom_meta')->where('object_type', 'user')->where('object_id', $userId)->delete();
@@ -212,8 +280,11 @@
212 280 Utility::getApp('db')->table('fcom_meta')->where('object_type', 'user')->where('object_id', $userId)->delete();
213 281
214 282 // notifications
215 283 Utility::getApp('db')->table('fcom_notification_users')->where('user_id', $userId)->delete();
284 +
285 + // notification preferences
286 + Utility::getApp('db')->table('fcom_notification_prefs')->where('user_id', $userId)->delete();
216 287
217 288 // comments
218 289 Utility::getApp('db')->table('fcom_post_comments')->where('user_id', $userId)->delete();
219 290