<?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_AddFremiumToExistingTeams()
{
    /*
    // 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 * FROM team WHERE active_premium_package = "STANDARD"';
    $stmt = $db->query( $sql );
    $res = $stmt->fetchAll();

    foreach( $res as $row )
    {
        if ( is_array( $row ) && isset( $row[ 'id' ] ) )
        {
            $db->beginTransaction();
            $entTeam = TB_Shared_Ent_TeamData_Team::get( $row[ 'id'  ] );
            if ( $entTeam instanceof  TB_Shared_Ent_TeamData_Team )
            {

                $entTeam->active_premium_package = TB_Server_Core_Premium::PREMIUM_PACKAGE_PREMIUM100_FREE;
                $entTeam->save();

                TB_Server_Core_Premium::createFreemiumPremiumLogEntryForTeam( $entTeam );
            }
            $db->commit();
        }
    }

    echo "DONE...";
}

patch_AddFremiumToExistingTeams();
