<?php

require_once __DIR__ . '/../../src/server/server/config/boot_global.php';
require_once __DIR__ . '/../../src/server/server/config/boot_local.php';

function patch_addActiveStateToProfile()
{

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

    $db->beginTransaction();
    foreach( $res as $row )
    {
        if ( is_array( $row ) && isset( $row[ 'id' ] ) )
        {

            $entProfile = TB_Shared_Ent_TeamData_Profile::get( $row[ 'id' ] );
            $resTeam = [];
            foreach ($entProfile->teams_js as $team) {
                $tmpTeam = $team;
                $tmpTeam['status'] = 'active';
                $resTeam[] = $tmpTeam;
            }
            $entProfile->teams_js = $resTeam;
            $entProfile->save();
            unset($team);
            unset( $entProfile );
        }
    }
    $db->commit();

    echo "DONE...";
}

patch_addActiveStateToProfile();