PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.4
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Scheduler / AutoSchedules / HourlyScheduler.php

HourlyScheduler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.4, at app/Hooks/Scheduler/AutoSchedules/HourlyScheduler.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Scheduler\AutoSchedules;
4
5 use FluentCart\App\Helpers\Status;
6 use FluentCart\App\Models\ScheduledAction;
7 use FluentCart\App\Models\Subscription;
8 use FluentCart\App\Services\Email\StoreDigestService;
9
10 class HourlyScheduler
11 {
12 private $startTimeStamp = null;
13
14 public function register(): void
15 {
16 add_action('fluent_cart/scheduler/hourly_tasks', [$this, 'handle'], 10);
17
18 // On-demand digest trigger (WP-CLI / debugging): do_action('fluent_cart/store_digest/send', 'daily')
19 add_action('fluent_cart/store_digest/send', function ($frequency) {
20 StoreDigestService::sendDigest((string) $frequency);
21 }, 10, 1);
22 }
23
24 public function handle()
25 {
26 $this->startTimeStamp = time();
27
28 // hourly tasks, remove all completed tasks
29 $this->removeCompleteTasks();
30
31 $this->checkAndExpireSubscriptions();
32
33 // Store digest (daily/weekly/monthly): evaluated each hour against the configured send time.
34 StoreDigestService::runDueDigests();
35 }
36
37
38 private function removeCompleteTasks()
39 {
40 ScheduledAction::query()->where('status', Status::SCHEDULE_COMPLETED)
41 ->limit(5000)
42 ->delete();
43 }
44
45 private function checkAndExpireSubscriptions()
46 {
47 if ((time() - $this->startTimeStamp) > 60) {
48 return;
49 }
50
51 Subscription::checkAndExpireSubscriptions();
52 }
53 }
54