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

function patch_PatchExistingValidUntildDateTimes()
{
    /*
    // Set DB configuration for live teamdata access
    Francis_Utils_Config::set( 'db.tbteamdata.host', 'XXXXXXXXX' );
    Francis_Utils_Config::set( 'db.tbteamdata.name', 'd01c3281' );
    Francis_Utils_Config::set( 'db.tbteamdata.user', 'd01c3281' );
    Francis_Utils_Config::set( 'db.tbteamdata.pass', 'XXXXXXXXX' );
*/


    $db = TB_Shared_Db_TeamData::get();
    $sql = 'SELECT id FROM premium_log WHERE package_id = "PREMIUM_100_FREE"';
    $stmt = $db->query( $sql );
    $res = $stmt->fetchAll();

    foreach( $res as $row )
    {
        if ( is_array( $row ) && isset( $row[ 'id' ] ) )
        {
            /** @var TB_Shared_Ent_TeamData_PremiumLog $entPremiumLog */
            $entPremiumLog = TB_Shared_Ent_TeamData_PremiumLog::get( $row[ 'id' ] );
            $clonedDt = clone $entPremiumLog->valid_until_dt;
            $clonedDt->setTime( 23, 59, 59 );
            $entPremiumLog->valid_until_dt = $clonedDt;
            $entPremiumLog->save();
        }
    }

    echo "DONE...";
}

patch_PatchExistingValidUntildDateTimes();
