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

function task_deployVersionNumberToTest() {

    global $local_source_dir,
           $remote_dest_dir_teambuddy;

    debug( "Update current version" );
    $version = '1.00';
    $versionFile = $local_source_dir . '/apps/teambuddy/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 ) );
        }
    }

    debug( "Version updated to " . $versionArr[ 'version' ] );

    debug( "Deploy new version file..." );
    sshConnect();
    sshFileCopy( $versionFile,  $remote_dest_dir_teambuddy . '/version.json' );
}

task_deployVersionNumberToTest();