PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.14.2
Yatra – Travel Booking & Tour Operator Software v3.0.14.2
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Services / TripLifecycleCronService.php

TripLifecycleCronService.php in Yatra – Travel Booking & Tour Operator Software 3.0.14.2, at app/Services/TripLifecycleCronService.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Services;
6
7 use Yatra\Repositories\TripRepository;
8
9 /**
10 * Trip Lifecycle Cron Service
11 * Handles scheduled publish/unpublish and seasonal auto enable/disable.
12 */
13 class TripLifecycleCronService
14 {
15 public const CRON_HOOK = 'yatra_daily_trip_lifecycle';
16
17 /**
18 * Register WordPress cron hook (daily)
19 */
20 public static function registerCronHook(): void
21 {
22 if (!wp_next_scheduled(self::CRON_HOOK)) {
23 wp_schedule_event(time(), 'daily', self::CRON_HOOK);
24 }
25 }
26
27 /**
28 * Unregister cron hook
29 */
30 public static function unregisterCronHook(): void
31 {
32 $timestamp = wp_next_scheduled(self::CRON_HOOK);
33 if ($timestamp) {
34 wp_unschedule_event($timestamp, self::CRON_HOOK);
35 }
36 }
37
38 /**
39 * Run lifecycle tasks:
40 * - Scheduled publish/unpublish
41 * - Seasonal auto enable/disable
42 */
43 public function runDaily(): void
44 {
45 // Use WP local time
46 $now = current_time('mysql');
47 $today = current_time('Y-m-d');
48
49 $repo = new TripRepository();
50
51 // Publish trips whose scheduled_publish_date has passed
52 $repo->publishScheduledTrips($now);
53
54 // Unpublish/archive trips whose scheduled_unpublish_date has passed
55 $repo->archiveScheduledTrips($now);
56
57 // Seasonal auto-enable: activate trips when enable date reached
58 $repo->enableSeasonalTrips($today, $now);
59
60 // Seasonal auto-disable: archive trips when disable date reached
61 $repo->disableSeasonalTrips($today, $now);
62 }
63 }
64
65