PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Hooks/Scheduler/FiveMinuteScheduler.php +75 -10 1.10.02 → 2.5.0 View file →
@@ -27,16 +27,25 @@
27 27 private function maybeAutoCompleteBookings()
28 28 {
29 29 $autoCompleteTimeOut = (int)Helper::getGlobalAdminSetting('auto_complete_timing', 60) * 60; // 10 minutes
30 30
31 - $bookings = Booking::where('status', 'scheduled')
31 + $bookings = Booking::with('calendar_event')
32 + ->where('status', 'scheduled')
32 33 ->where('end_time', '<', gmdate('Y-m-d H:i:s', time() - $autoCompleteTimeOut)) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
33 34 ->limit(500)
34 35 ->get();
35 36
37 + if ($bookings->isEmpty()) {
38 + return true;
39 + }
40 +
36 41 foreach ($bookings as $booking) {
42 + // Flag each row just before its hook, so a run that dies mid-loop leaves the rest for the next run.
43 + if (!Booking::where('id', $booking->id)->where('status', 'scheduled')->update(['status' => 'completed'])) {
44 + continue;
45 + }
46 +
37 47 $booking->status = 'completed';
38 - $booking->save();
39 48 do_action('fluent_booking/booking_schedule_completed', $booking, $booking->calendar_event);
40 49 }
41 50
42 51 return true;
@@ -45,16 +54,33 @@
45 54 private function maybeAutoCancelPastBookings()
46 55 {
47 56 $autoCompleteTimeOut = (int)Helper::getGlobalAdminSetting('auto_complete_timing', 60) * 60; // 10 minutes
48 57
49 - Booking::query()
58 + $bookings = Booking::with('calendar_event')
50 59 ->where('status', 'pending')
51 60 ->where('end_time', '<', gmdate('Y-m-d H:i:s', time() - $autoCompleteTimeOut)) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
52 - ->update([
61 + ->limit(500)
62 + ->get();
63 +
64 + if ($bookings->isEmpty()) {
65 + return true;
66 + }
67 +
68 + foreach ($bookings as $booking) {
69 + // Flag each row just before its hook, so a run that dies mid-loop leaves the rest for the next run.
70 + $flagged = Booking::where('id', $booking->id)->where('status', 'pending')->update([
53 71 'status' => 'cancelled',
54 - 'updated_at' => gmdate('Y-m-d H:i:s') // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
72 + 'updated_at' => gmdate('Y-m-d H:i:s'), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
55 73 ]);
56 74
75 + if (!$flagged) {
76 + continue;
77 + }
78 +
79 + $booking->status = 'cancelled';
80 + do_action('fluent_booking/booking_schedule_auto_cancelled', $booking, $booking->calendar_event);
81 + }
82 +
57 83 return true;
58 84 }
59 85
60 86 private function maybeAutoCancelBooking()
@@ -61,19 +87,33 @@
61 87 {
62 88 $autoCancelTimeOut = (int)Helper::getGlobalAdminSetting('auto_cancel_timing', 10) * 60; // 10 minutes
63 89
64 90 $bookings = Booking::query()
91 + ->with('calendar_event')
65 92 ->where('created_at', '<=', gmdate('Y-m-d H:i:s', time() - $autoCancelTimeOut)) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
66 93 ->where('status', 'pending')
67 94 ->where('payment_status', 'pending')
68 95 ->where('payment_method', '!=', 'offline')
96 + ->limit(500)
69 97 ->get();
70 98
99 + if ($bookings->isEmpty()) {
100 + return true;
101 + }
102 +
71 103 foreach ($bookings as $booking) {
104 + // Flag each row just before its hook, so a run that dies mid-loop leaves the rest for the next run.
105 + $flagged = Booking::where('id', $booking->id)->where('status', 'pending')->update([
106 + 'status' => 'cancelled',
107 + 'updated_at' => gmdate('Y-m-d H:i:s'), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
108 + ]);
109 +
110 + if (!$flagged) {
111 + continue;
112 + }
113 +
72 114 $booking->status = 'cancelled';
73 - $booking->updated_at = gmdate('Y-m-d H:i:s');
74 - $booking->save();
75 - do_action('fluent_booking/booking_schedule_auto_cancelled', $booking);
115 + do_action('fluent_booking/booking_schedule_auto_cancelled', $booking, $booking->calendar_event);
76 116 }
77 117
78 118 return true;
79 119 }
@@ -79,14 +119,27 @@
79 119 }
80 120
81 121 private function maybeAutoExpireCalendars()
82 122 {
83 - Calendar::query()
123 + $calendarIds = Calendar::query()
84 124 ->where('type', 'event')
85 125 ->where('status', 'active')
86 126 ->whereDoesntHave('events', function ($query) {
87 127 $query->whereIn('status', ['active', 'draft']);
88 128 })
129 + ->limit(500)
130 + ->pluck('id');
131 +
132 + if ($calendarIds->isEmpty()) {
133 + return true;
134 + }
135 +
136 + Calendar::whereIn('id', $calendarIds)
137 + ->where('type', 'event')
138 + ->where('status', 'active')
139 + ->whereDoesntHave('events', function ($query) {
140 + $query->whereIn('status', ['active', 'draft']);
141 + })
89 142 ->update(['status' => 'expired']);
90 143
91 144 return true;
92 145 }
@@ -102,8 +155,9 @@
102 155 })
103 156 ->with(['calendar_event' => function ($query) {
104 157 $query->where('status', 'active');
105 158 }])
159 + ->limit(500)
106 160 ->get()
107 161 ->each(function ($meta) {
108 162 $meta->calendar_event->update(['status' => 'expired']);
109 163 });
@@ -112,9 +166,20 @@
112 166 }
113 167
114 168 private function maybeAutoDeleteReservations()
115 169 {
116 - Booking::query()
170 + $reservationIds = Booking::query()
171 + ->whereIn('event_type', ['single_event', 'group_event'])
172 + ->where('status', 'reserved')
173 + ->where('start_time', '<=', gmdate('Y-m-d H:i:s', time())) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
174 + ->limit(500)
175 + ->pluck('id');
176 +
177 + if ($reservationIds->isEmpty()) {
178 + return true;
179 + }
180 +
181 + Booking::whereIn('id', $reservationIds)
117 182 ->whereIn('event_type', ['single_event', 'group_event'])
118 183 ->where('status', 'reserved')
119 184 ->where('start_time', '<=', gmdate('Y-m-d H:i:s', time())) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
120 185 ->delete();