<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/
include_once 'build_inc-new.php';

function task_homeDeployVersionNumberToTest() {

    $server = new Server();

    $lSrcDir = Local::PROJECT_ROOT . '/apps/teambuddy';
    $remoteRootDir = Server::ROOT_DIR . '/projects/teambuddy/apps/teambuddy';

    print( "Update current version...\n" );
    $version = '2.00';
    $versionFile = $lSrcDir . '/version.json';
    $versionArr = json_decode( file_get_contents( $versionFile ), true );
    if ( is_array( $versionArr ) && isset( $versionArr[ 'version' ] ) ) {
        $version = $versionArr[ 'version' ];
        // Never update major version automatically - just increase rest
        $versionParts = explode( '.', $version );
        if ( 2 === count( $versionParts ) ){
            $versionParts[1] = sprintf( '%02d', ((int)$versionParts[1] + 1) );
            $versionArr[ 'version' ] = $versionParts[0] . '.' . $versionParts[1];
            file_put_contents( $versionFile, json_encode( $versionArr ) );
        }
    }

    print( "Version updated to " . $versionArr[ 'version' ] . "\n" );

    print( "Deploy new version file...\n" );
    $server->upload( $versionFile,  $remoteRootDir . '/version.json' );
}

task_homeDeployVersionNumberToTest();