<?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_addCategoryIdsJsToAppointments()
{
    return NULL;
    /*
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();
            $entApp = TB_Shared_Ent_TeamData_Appointment::get( $row[ 'id' ] );
            if ( $entApp instanceof  TB_Shared_Ent_TeamData_Appointment )
            {
                if ( !is_null( $entApp->category_id ) )
                {
                    $entApp->category_ids_js = array( $entApp->category_id );
                    $entApp->save();
                }
            }
            $db->commit();
        }
    }

    echo "DONE...";
}

patch_addCategoryIdsJsToAppointments();
