-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
100 lines (92 loc) · 4.17 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<project name="blog-example" default="build" basedir=".">
<target name="composer" description="Installing dependencies">
<exec logoutput="true" command="composer install --no-interaction --prefer-dist -o"/>
</target>
<target name="doctrine" description="Update database schema">
<exec logoutput="true" command="vendor/bin/doctrine-module orm:schema-tool:update --force"/>
</target>
<target name="create_mysql" description="Create database">
<trycatch property="error">
<try>
<pdosqlexec url="mysql:host=${db.host};port=${db.port}" userid="${db.user}" password="${db.pass}">
CREATE DATABASE ${db.name};
</pdosqlexec>
</try>
<catch>
<echo message="${error}"/>
<input propertyName="db.root_user" message="Database root user:"/>
<input propertyName="db.root_pass" message="Database root pass:"/>
<if>
<and>
<isset property="db.root_user"/>
<isset property="db.root_pass"/>
</and>
<then>
<phingcall target="create_mysql">
<property name="db.user" value="db.root_user"/>
<property name="db.pass" value="db.root_pass"/>
</phingcall>
</then>
</if>
</catch>
</trycatch>
</target>
<target name="check_database" description="Check if database exists and accessible">
<trycatch property="error">
<try>
<pdosqlexec url="mysql:host=${db.host};port=${db.port}" userid="${db.user}" password="${db.pass}">
USE ${db.name};
</pdosqlexec>
</try>
<catch>
<phingcall target="create_mysql"/>
</catch>
</trycatch>
</target>
<target name="doctrine_import_fixtures" description="Import doctrine fixtures">
<exec logoutput="true" command="php public/index.php data-fixture:import" />
</target>
<target name="config" description="Setup basic configuration">
<copy file="config/autoload/doctrine.orm.local.php.dist" tofile="config/autoload/doctrine.orm.local.php" overwrite="true">
<filterchain>
<replacetokens begintoken="__" endtoken="__">
<token key="NAME" value="${db.name}"/>
<token key="HOST" value="${db.host}"/>
<token key="PORT" value="${db.port}"/>
<token key="USER" value="${db.user}"/>
<token key="PASS" value="${db.pass}"/>
</replacetokens>
</filterchain>
</copy>
</target>
<target name="install" description="Installation task">
<input propertyName="db.name" message="Database name:"/>
<input propertyName="db.host" message="Database host:" defaultValue="localhost"/>
<input propertyName="db.port" message="Database port:" defaultValue="3306"/>
<input propertyName="db.user" message="Database user:"/>
<input propertyName="db.pass" message="Database pass:"/>
<if>
<and>
<isset property="db.name"/>
<isset property="db.host"/>
<isset property="db.port"/>
<isset property="db.user"/>
<isset property="db.pass"/>
</and>
<then>
<phingcall target="composer"/>
<phingcall target="check_database"/>
<phingcall target="config"/>
<phingcall target="doctrine"/>
<phingcall target="doctrine_import_fixtures"/>
</then>
<else>
<fail>
Can't create database.
Usage: phing -Ddb.host=localhost -Ddb.port=3306 -Ddb.user=root -Ddb.pass=password -Ddb.name=example install
</fail>
</else>
</if>
</target>
<target name="build" description="Update code and database, regular task" depends="composer, doctrine"/>
</project>