PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.91
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.91
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.91, at app/Hooks/Handlers/Scheduler.php

105 lines 3.8 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
28 $this->maybeRemoveOldScheuledActionLogs();
29 });
30
31 add_action('init', function () {
32 $this->maybeRemoveOldScheuledActionLogs();
33 });
34
35 }
36
37 public function checkDailyDigestSchedule($willReset = false)
38 {
39 $notificationSettings = Utility::getEmailNotificationSettings();
40 $globalStatus = Arr::get($notificationSettings, 'digest_email_status', 'no');
41
42 if ($globalStatus != 'yes') {
43 // Global Status is false
44 // Check if any user enabled that or not
45 $isEnabled = NotificationSubscription::where('notification_type', 'digest_mail')
46 ->where('is_read', 1)
47 ->exist();
48
49 if (!$isEnabled) {
50 // unset the scheduled action
51 if (as_next_scheduled_action('fluent_community_send_daily_digest_init', null, 'fluent-community')) {
52 as_unschedule_all_actions('fluent_community_send_daily_digest_init', null, 'fluent-community');
53 }
54 return;
55 }
56 }
57
58 $notificationDay = Arr::get($notificationSettings, 'digest_mail_day');
59 $digestTime = Arr::get($notificationSettings, 'daily_digest_time', '09:00');
60 // Let's check if we have the daily digest action scheduled or not
61 if (!as_next_scheduled_action('fluent_community_send_daily_digest_init', null, 'fluent-community')) {
62 $notificationDay = 'next ' . $notificationDay . 'day ' . $digestTime;
63 $diff = time() - current_time('timestamp');
64 $timeStamp = strtotime($notificationDay) + $diff;
65 as_schedule_single_action($timeStamp, 'fluent_community_send_daily_digest_init', null, 'fluent-community', true);
66 }
67 }
68
69 private function maybeRemoveOldScheuledActionLogs($group_slug = 'fluent-community', $days_old = 7)
70 {
71 global $wpdb;
72
73 // Get the timestamp for 7 days ago
74 $cutoff_date = date('Y-m-d H:i:s', strtotime("-{$days_old} days"));
75
76 // Get the group ID
77 $group_id = $wpdb->get_var($wpdb->prepare(
78 "SELECT group_id FROM {$wpdb->prefix}actionscheduler_groups WHERE slug = %s",
79 $group_slug
80 ));
81
82 if (!$group_id) {
83 return false; // Group not found
84 }
85
86 // Delete old actions and their associated logs
87 $deleted = $wpdb->query($wpdb->prepare("
88 DELETE a, l
89 FROM {$wpdb->prefix}actionscheduler_actions a
90 LEFT JOIN {$wpdb->prefix}actionscheduler_logs l ON a.action_id = l.action_id
91 WHERE a.group_id = %d
92 AND a.status IN ('complete', 'failed')
93 AND a.scheduled_date_gmt < %s", $group_id, $cutoff_date));
94
95 // Clean up orphaned claims
96 $wpdb->query("
97 DELETE c
98 FROM {$wpdb->prefix}actionscheduler_claims c
99 LEFT JOIN {$wpdb->prefix}actionscheduler_actions a ON c.claim_id = a.claim_id
100 WHERE a.action_id IS NULL");
101
102 return $deleted;
103 }
104 }
105