<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/

include_once 'build_inc.php';

function task_setupDBOnTest() {
    global $local_path_mysqldump;
    global $local_temp_dir;
    global $remote_temp_dir;
    global $remote_db_core_name;
    global $remote_db_core_user;
    global $remote_db_core_pass;
    global $remote_db_teamdata_name;
    global $remote_db_teamdata_user;
    global $remote_db_teamdata_pass;

    debug( "Dumping local db structure..." );
    windowsCmd( $local_path_mysqldump . " -u root -d tb_core > " . $local_temp_dir . "/tb_core.sql" );
    windowsCmd( $local_path_mysqldump . " -u root -d tb_teamdata > " . $local_temp_dir . "/tb_teamdata.sql" );
    debug( "Uploading db scripts..." );
    sshConnect();
    sshFileCopy( $local_temp_dir . "/tb_core.sql",  $remote_temp_dir . '/tb_core.sql' );
    sshFileCopy( $local_temp_dir . "/tb_teamdata.sql",  $remote_temp_dir . '/tb_teamdata.sql' );
    debug( "Updating remote DB structure..." );
    sshExec( "cd $remote_temp_dir;mysql -u$remote_db_core_user -p$remote_db_core_pass $remote_db_core_name < tb_core.sql" );
    sshExec( "cd $remote_temp_dir;mysql -u$remote_db_teamdata_user -p$remote_db_teamdata_pass $remote_db_teamdata_name < tb_teamdata.sql" );
    debug( "Remove uploaded db scripts..." );
    sshExec( "cd $remote_temp_dir;rm tb_core.sql;" );
    sshExec( "cd $remote_temp_dir;rm tb_teamdata.sql;" );
    debug( "Task done." );
}

// task_setupDBOnTest();
debug( "*** LIVE DB Reset is DEACTIVATED ***" );