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 +82 -16 1.0.97 → 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,12 +11,13 @@
13 11 {
14 12 public function register()
15 13 {
16 14 add_action('fluent_community/feed/before_deleted', [$this, 'handleFeedDeleted'], 10, 1);
15 + add_action('fluent_community/lesson/before_deleted', [$this, 'handleLessonDeleted'], 10, 1);
17 16 add_action('fluent_community/remove_old_notifications', [$this, 'maybeDeleteOldNotifications']);
18 17
19 18 add_action('fluent_community/comment/media_deleted', [$this, 'queueMediaDelete'], 10, 1);
20 - add_action('fluent_community/feed/media_deleted', [$this, 'queueMediaDelete'], 10, 1);
19 + add_action('fluent_community/feed/media_deleted', [$this, 'handleMediaDelete'], 10, 1);
21 20 add_action('fluent_community/maybe_delete_draft_medias', [$this, 'deleteOldDraftMedias'], 10);
22 21 add_action('fluent_community/remove_medias_by_url', function ($mediaUrls, $wheres = []) {
23 22 if (!$mediaUrls) {
24 23 return;
@@ -38,24 +37,34 @@
38 37 $this->queueMediaDelete($media);
39 38 }, 10, 2);
40 39
41 40 add_action('deleted_user', [$this, 'handleUserDeleted'], 10, 2);
41 + }
42 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);
43 55 }
44 56
45 57 public function handleFeedDeleted($feed)
46 58 {
47 - $feed->comments()->delete();
59 + foreach ($feed->comments as $comment) {
60 + $comment->delete();
61 + }
62 +
48 63 $feed->reactions()->delete();
49 64 $feed->activities()->delete();
50 65 $this->queueMediaDelete($feed->media);
51 66
52 - if ($feed->comtent_type == 'survey') {
53 - Reaction::where('type', 'survey_vote')
54 - ->where('object_id', $feed->id)
55 - ->delete();
56 - }
57 -
58 67 // Loop is used to delete notification with notified user data from fcom_notification_users table
59 68 foreach ($feed->notifications as $notification) {
60 69 $notification->delete();
61 70 }
@@ -62,8 +71,55 @@
62 71
63 72 Utility::getApp('db')->table('fcom_term_feed')->where('post_id', $feed->id)->delete();
64 73 }
65 74
75 + public function handleLessonMediaDelete($lessonId, $media, $mediaKeys = [], $isCollection = false)
76 + {
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();
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);
109 + }
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 +
66 122 public function queueMediaDelete($media)
67 123 {
68 124 if (is_null($media)) {
69 125 return false;
@@ -134,14 +190,15 @@
134 190 $ids[] = $notification->id;
135 191 }
136 192
137 193 if (!$ids) {
138 -
139 194 // Let's delete meta data
140 - Utility::getApp('db')->table('fcom_meta')->whereIn('meta_key', [
141 - '_last_mention_email_user_id',
142 - '_last_email_user_id'
143 - ])
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 + ])
144 201 ->limit(9000)
145 202 ->where('created_at', '<', gmdate('Y-m-d H:i:s', strtotime('-1 week')))
146 203 ->delete();
147 204
@@ -192,8 +249,9 @@
192 249 *
193 250 * fcom_meta where object_type = user and object_id = user_id
194 251 *
195 252 * fcom_notification_users where user_id = user_id
253 + * fcom_notification_prefs where user_id = user_id
196 254 * fcom_post_comments where user_id = user_id
197 255 * fcom_post_reactions where user_id = user_id
198 256 * fcom_posts where user_id = user_id & type = text
199 257 * fcom_space_user where user_id = user_id
@@ -207,11 +265,16 @@
207 265 *
208 266 *
209 267 */
210 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 +
211 275 Utility::getApp('db')->table('fcom_chat_messages')->where('user_id', $userId)->delete();
212 276 Utility::getApp('db')->table('fcom_chat_thread_users')->where('user_id', $userId)->delete();
213 - Utility::getApp('db')->table('fcom_chat_thread_users')->where('user_id', $userId)->delete();
214 277 }
215 278
216 279 // meta
217 280 Utility::getApp('db')->table('fcom_meta')->where('object_type', 'user')->where('object_id', $userId)->delete();
@@ -217,8 +280,11 @@
217 280 Utility::getApp('db')->table('fcom_meta')->where('object_type', 'user')->where('object_id', $userId)->delete();
218 281
219 282 // notifications
220 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();
221 287
222 288 // comments
223 289 Utility::getApp('db')->table('fcom_post_comments')->where('user_id', $userId)->delete();
224 290