PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.96
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.96
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
fluent-community / app / Hooks / Handlers / Scheduler.php

Scheduler.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.96, at app/Hooks/Handlers/Scheduler.php

100 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Hooks\Handlers;
4
5 use FluentCommunity\App\Functions\Utility;
6 use FluentCommunity\App\Models\NotificationSubscription;
7 use FluentCommunity\App\Services\Helper;
8 use FluentCommunity\Framework\Support\Arr;
9
10 class Scheduler
11 {
12
13 public function register()
14 {
15 add_action('fluent_community_scheduled_hour_jobs', function () {
16 $this->checkDailyDigestSchedule();
17 do_action('fluent_community/maybe_delete_draft_medias');
18 });
19
20 add_action('fluent_community_send_daily_digest_init', function () {
21 do_action('fluent_community_send_daily_digest');
22 });
23
24 add_action('fluent_community_daily_jobs', function () {
25 // let's fire the old email notifications hook
26 do_action('fluent_community/remove_old_notifications');
27 $this->maybeRemoveOldScheuledActionLogs();
28 });
29
30 }
31
32 public function checkDailyDigestSchedule($willReset = false)
33 {
34 $notificationSettings = Utility::getEmailNotificationSettings();
35 $globalStatus = Arr::get($notificationSettings, 'digest_email_status', 'no');
36
37 if ($globalStatus != 'yes') {
38 // Global Status is false
39 // Check if any user enabled that or not
40 $isEnabled = NotificationSubscription::query()->where('notification_type', 'digest_mail')
41 ->where('is_read', 1)
42 ->exists();
43
44 if (!$isEnabled) {
45 // unset the scheduled action
46 if (\as_next_scheduled_action('fluent_community_send_daily_digest_init')) {
47 \as_unschedule_all_actions('fluent_community_send_daily_digest_init', [], 'fluent-community');
48 }
49 return;
50 }
51 }
52
53 $notificationDay = Arr::get($notificationSettings, 'digest_mail_day');
54 $digestTime = Arr::get($notificationSettings, 'daily_digest_time', '09:00');
55 // Let's check if we have the daily digest action scheduled or not
56 if (!\as_next_scheduled_action('fluent_community_send_daily_digest_init')) {
57 $notificationDay = 'next ' . $notificationDay . 'day ' . $digestTime;
58 $diff = time() - current_time('timestamp');
59 $timeStamp = strtotime($notificationDay) + $diff;
60 \as_schedule_single_action($timeStamp, 'fluent_community_send_daily_digest_init', [], 'fluent-community', true);
61 }
62 }
63
64 private function maybeRemoveOldScheuledActionLogs($group_slug = 'fluent-community', $days_old = 7)
65 {
66 global $wpdb;
67
68 // Get the timestamp for 7 days ago
69 $cutoff_date = date('Y-m-d H:i:s', strtotime("-{$days_old} days"));
70
71 // Get the group ID
72 $group_id = $wpdb->get_var($wpdb->prepare(
73 "SELECT group_id FROM {$wpdb->prefix}actionscheduler_groups WHERE slug = %s",
74 $group_slug
75 ));
76
77 if (!$group_id) {
78 return false; // Group not found
79 }
80
81 // Delete old actions and their associated logs
82 $deleted = $wpdb->query($wpdb->prepare("
83 DELETE a, l
84 FROM {$wpdb->prefix}actionscheduler_actions a
85 LEFT JOIN {$wpdb->prefix}actionscheduler_logs l ON a.action_id = l.action_id
86 WHERE a.group_id = %d
87 AND a.status IN ('complete', 'failed')
88 AND a.scheduled_date_gmt < %s", $group_id, $cutoff_date));
89
90 // Clean up orphaned claims
91 $wpdb->query("
92 DELETE c
93 FROM {$wpdb->prefix}actionscheduler_claims c
94 LEFT JOIN {$wpdb->prefix}actionscheduler_actions a ON c.claim_id = a.claim_id
95 WHERE a.action_id IS NULL");
96
97 return $deleted;
98 }
99 }
100