# yatra/3.0.14.2/app/Services/TripLifecycleCronService.php

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.14.2. 65 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.14.2/code/app/Services/TripLifecycleCronService.php
- Raw: https://pluginprobe.com/plugins/yatra/3.0.14.2/raw/app/Services/TripLifecycleCronService.php
- Modified: 2026-04-14T03:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.14.2/code/app/Services/TripLifecycleCronService.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Yatra\Services;

use Yatra\Repositories\TripRepository;

/**
 * Trip Lifecycle Cron Service
 * Handles scheduled publish/unpublish and seasonal auto enable/disable.
 */
class TripLifecycleCronService
{
    public const CRON_HOOK = 'yatra_daily_trip_lifecycle';

    /**
     * Register WordPress cron hook (daily)
     */
    public static function registerCronHook(): void
    {
        if (!wp_next_scheduled(self::CRON_HOOK)) {
            wp_schedule_event(time(), 'daily', self::CRON_HOOK);
        }
    }

    /**
     * Unregister cron hook
     */
    public static function unregisterCronHook(): void
    {
        $timestamp = wp_next_scheduled(self::CRON_HOOK);
        if ($timestamp) {
            wp_unschedule_event($timestamp, self::CRON_HOOK);
        }
    }

    /**
     * Run lifecycle tasks:
     * - Scheduled publish/unpublish
     * - Seasonal auto enable/disable
     */
    public function runDaily(): void
    {
        // Use WP local time
        $now = current_time('mysql');
        $today = current_time('Y-m-d');

        $repo = new TripRepository();

        // Publish trips whose scheduled_publish_date has passed
        $repo->publishScheduledTrips($now);

        // Unpublish/archive trips whose scheduled_unpublish_date has passed
        $repo->archiveScheduledTrips($now);

        // Seasonal auto-enable: activate trips when enable date reached
        $repo->enableSeasonalTrips($today, $now);

        // Seasonal auto-disable: archive trips when disable date reached
        $repo->disableSeasonalTrips($today, $now);
    }
}


```
