PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
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 / DailyScheduler.php

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

51 lines 1.1 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\Hooks\Scheduler\JobRunner;
6 use FluentCart\App\Models\Cart;
7
8 class DailyScheduler
9 {
10
11 private $startTimeStamp = null;
12
13 public function register(): void
14 {
15 add_action('fluent_cart/scheduler/daily_tasks', [$this, 'handle']);
16 }
17
18 public function handle()
19 {
20 $this->startTimeStamp = time();
21 $this->deleteOldCarts();
22 }
23
24
25 private function deleteOldCarts()
26 {
27
28 if ((time() - $this->startTimeStamp) > 40) {
29 return; // Prevent long execution
30 }
31
32 $days = apply_filters('fluent_cart/cleanup/old_carts_days', 30);
33
34 $carts = Cart::query()
35 ->where('updated_at', '<=', date('Y-m-d H:i:s', strtotime('-' . $days . ' days')))
36 ->limt(1000)
37 ->get();
38
39 if ($carts->isEmpty()) {
40 return;
41 }
42
43 foreach ($carts as $cart) {
44 $cart->delete();
45 }
46
47 // Recursively call to delete more carts
48 $this->deleteOldCarts();
49 }
50 }
51