<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/
require_once __DIR__ . '/../../src/server/server/config/boot_global.php';
require_once __DIR__ . '/../../src/server/server/config/boot_local.php';

function patch_addDateTimeRejectToExistingAppointments()
{
    /*
    // Set DB configuration for live teamdata access
    Francis_Utils_Config::set( 'db.tbteamdata.host', 'v034011.kasserver.com' );
    Francis_Utils_Config::set( 'db.tbteamdata.name', 'd02e620f' );
    Francis_Utils_Config::set( 'db.tbteamdata.user', 'd02e620f' );
    Francis_Utils_Config::set( 'db.tbteamdata.pass', 'NT7uSbtaebV9Gedq' );
    */

    $db = TB_Shared_Db_TeamData::get();
    $sql = 'SELECT * FROM appointment';
    $stmt = $db->query( $sql );
    $res = $stmt->fetchAll();

    foreach( $res as $row )
    {
        if ( is_array( $row ) && isset( $row[ 'id' ] ) )
        {
            $db->beginTransaction();
            $entAppointment = TB_Shared_Ent_TeamData_Appointment::get( $row[ 'id' ] );
            $entAppointment->deadline_reject_dt = $entAppointment->start_dt;
            $entAppointment->save();
            $db->commit();
            unset( $entAppointment );
        }
    }

    echo "DONE...";
}

patch_addDateTimeRejectToExistingAppointments();
