<?xml version="1.0" encoding="UTF-8"?>

<project name="Orchard" default="dist" basedir=".">

    <target name="setup">
        <property file="./application/configs/phing.properties" override="true"/>
    </target>

    <target name="mkdirs" depends="setup">
        <echo msg="Making directory ./application/modules/alw/data/logs" />
        <mkdir dir="./application/modules/alw/data" />
        <mkdir dir="./application/modules/alw/data/logs" />
        <chmod file="./application/modules/alw/data" mode="0775" verbose="true" />
        <chmod file="./application/modules/alw/data/logs" mode="0775" verbose="true" />

        <echo msg="Making directory ./public/images/lg_coverart_correction" />
        <mkdir dir="./public/images/lg_coverart_correction" />
        <chmod file="./public/images/lg_coverart_correction" mode="0775" verbose="true" />

        <echo msg="Making directory ./public/images/lg_coverart_10" />
        <mkdir dir="./public/images/lg_coverart_10" />
        <chmod file="./public/images/lg_coverart_10" mode="0775" verbose="true" />

        <echo msg="Making directory ./public/images/coverart_correction" />
        <mkdir dir="./public/images/coverart_correction" />
        <chmod file="./public/images/coverart_correction" mode="0775" verbose="true" />

        <echo msg="Making directory ./public/tmp" />
        <mkdir dir="./public/tmp" />
        <chmod file="./public/tmp" mode="0775" verbose="true" />
    </target>

  <target name="copy" depends="mkdirs">
        <echo msg="Copying config config files and .htaccess files..." />

        <echo msg="Copying ./public/.htaccess ..." />
        <copy file="./public/.dev.shadow.htaccess" tofile="./public/.htaccess" overwrite="yes">
            <filterchain>
                <replacetokens>
                    <token key="workstation.host" value="${workstation.host}"/>
                    <token key="oa.host" value="${oa.host}"/>
                </replacetokens>
            </filterchain>
        </copy>

        <echo msg="Copying application.ini..." />
        <copy file="./application/configs/application.shadow.ini" tofile="./application/configs/application.ini" overwrite="yes">
            <filterchain>
                <replacetokens>
                    <token key="workstation.host" value="${workstation.host}"/>
                    <token key="oa.host" value="${oa.host}"/>
                    <token key="db.username" value="${db.username}"/>
                    <token key="db.password" value="${db.password}"/>
                </replacetokens>
            </filterchain>
        </copy>

        <echo msg="Copying accounting.ini..." />
        <copy file="./application/configs/accounting.shadow.ini" tofile="./application/configs/accounting.ini" overwrite="yes" />

        <echo msg="Copying server_locations.ini..." />
        <copy file="./application/configs/server_locations.shadow.ini" tofile="./application/configs/server_locations.ini" overwrite="yes"/>

        <echo msg="Copying config.ini..." />
        <copy file="./application/configs/config.shadow.ini" tofile="./application/configs/config.ini" overwrite="yes">
            <filterchain>
                <replacetokens>
                    <token key="memcache.host" value="${memcache.host}"/>
                    <token key="workstation.host" value="${workstation.host}"/>
                    <token key="oa.host" value="${oa.host}"/>
                </replacetokens>
            </filterchain>
        </copy>

        <echo msg="Copying art_db.yml..." />
        <copy file="./application/configs/art_db.shadow.yml" tofile="./application/configs/art_db.yml" overwrite="yes" />

        <echo msg="Copying aws.ini..." />
        <copy file="./application/configs/aws.shadow.ini" tofile="./application/configs/aws.ini" overwrite="yes" />

        <echo msg="Copying aws.yml..." />
        <copy file="./application/configs/aws.shadow.yml" tofile="./application/configs/aws.yml" overwrite="yes" />

        <echo msg="Copying doctrine.ini..." />
        <copy file="./application/configs/doctrine.shadow.ini" tofile="./application/configs/doctrine.ini" overwrite="yes" />

        <echo msg="Copying grass.yml..." />
        <copy file="./application/configs/grass.shadow.yml" tofile="./application/configs/grass.yml" overwrite="yes" />

        <echo msg="Copying webservice.yml..." />
        <copy file="./application/configs/webservice.shadow.yml" tofile="./application/configs/webservice.yml" overwrite="yes" >
            <filterchain>
                <replacetokens begintoken="%%" endtoken="%%">
                    <token key="WebServiceUrl" value="${webservice.url}"/>
                </replacetokens>
            </filterchain>
        </copy>

    </target>

    <target name="dist" depends="copy">
        <echo msg="Setting up Orchard codebase..." />
        <echo msg="Build complete" />
    </target>
</project>
