<?xml version="1.0" encoding="UTF-8"?>
<project name="inc_deploy" default="build">
	<target name="deploy-ci" description="Deployment tasks, that are required after SVN checkout" depends="create-aliases">
		<property name="tools.dir" value="${base.dir}/tools"/>

		<echo msg="Fixing shell scripts permissions under '/tools' folder"/>
		<chmod mode="0755" verbose="true" failonerror="true">
			<fileset dir="${tools.dir}">
				<include name="*.sh"/>
			</fileset>
		</chmod>

		<echo msg="Fixing '/system' folder permissions"/>
		<exec dir="${tools.dir}" command="./fix_perms.sh" logoutput="true"/>

		<echo msg="Removing compiled templates under '/system/cache' folder"/>
		<exec dir="${tools.dir}" command="./clear_cache.sh" logoutput="true"/>

		<composer command="install" composer="/usr/local/bin/composer">
			<arg value="--working-dir"/>
			<arg path="${base.dir}"/>
			<arg value="--ansi"/>
		</composer>

		<if>
			<available file="${base.dir}/system/build-schema.sql" type="file"/>
			<then>
				<phingcall target="db-fill-ci"/>
				<phingcall target="inportal-deploy"/>
			</then>
		</if>
	</target>

	<target name="inportal-deploy" description="Runs In-Portal deployment script">
		<echo msg="Running In-Portal Deployment Script (part of 'do_update') ..."/>

		<exec executable="php" logoutput="true" checkreturn="true">
			<arg path="${base.dir}/tools/run_event.php"/>
			<arg value="adm:OnDeploy"/>
			<arg value="${cli.key}"/>
			<arg value="${client.ip.address}"/>
		</exec>
	</target>
</project>
