@@ -18,6 +18,20 @@ class Executor
18
18
*/
19
19
protected $ db ;
20
20
21
+ /**
22
+ * Disables all checks and fires all commands again and again.
23
+ *
24
+ * @var bool
25
+ */
26
+ protected $ debug = false ;
27
+
28
+ /**
29
+ * Defines whether prepareRuntimeConfig should call config:convert or not
30
+ *
31
+ * @var bool
32
+ */
33
+ protected $ needConfigConvertCall = false ;
34
+
21
35
/**
22
36
* @param $redis
23
37
*/
@@ -44,13 +58,19 @@ public function execute(Fiddle $fiddle)
44
58
}
45
59
46
60
$ this ->prepareChroot ($ fiddle );
61
+ $ directory = $ this ->getDirectory ($ fiddle );
62
+ $ logFile = $ directory . '/home/sandbox/propel_log.txt ' ;
63
+ file_put_contents ($ logFile , '' );
47
64
65
+ $ this ->prepareDatabase ($ fiddle );
48
66
$ this ->buildDatabaseSchema ($ fiddle );
49
67
$ this ->prepareRuntimeConfig ($ fiddle );
50
68
51
69
$ scriptOutput = $ this ->executeInJail ($ fiddle );
52
70
$ fiddle ->setScriptOutput ($ scriptOutput );
53
71
$ this ->extractDbInformation ($ fiddle );
72
+
73
+ $ fiddle ->setLogOutput (file_get_contents ($ logFile ));
54
74
}
55
75
56
76
protected function prepareChroot (Fiddle $ fiddle )
@@ -69,13 +89,11 @@ protected function prepareChroot(Fiddle $fiddle)
69
89
\$autoloader->add('', __DIR__ . '/generated-classes/');
70
90
require './generated-conf/config.php';
71
91
72
-
73
92
$ php
74
93
EOF
75
94
);
76
95
file_put_contents ($ directory . '/home/sandbox/schema.xml ' , $ fiddle ->getSchema ());
77
96
78
- $ this ->prepareDatabase ($ fiddle );
79
97
}
80
98
81
99
/**
@@ -90,7 +108,7 @@ protected function prepareDatabase(Fiddle $fiddle)
90
108
$ fiddleEscaped = $ this ->db ->quote ($ fiddle ->getId (), \PDO ::PARAM_STR );
91
109
$ fiddleId = $ this ->db ->quoteIdentifier ($ fiddle ->getId ());
92
110
93
- if (file_exists ($ directory . '/home/sandbox/propel.yml ' )) {
111
+ if (! $ this -> debug && file_exists ($ directory . '/home/sandbox/propel.yml ' )) {
94
112
return false ;
95
113
}
96
114
@@ -120,6 +138,8 @@ protected function prepareDatabase(Fiddle $fiddle)
120
138
)
121
139
);
122
140
141
+ $ this ->needConfigConvertCall = true ;
142
+
123
143
$ this ->db ->executeQuery (
124
144
sprintf (
125
145
"GRANT USAGE, ALTER, CREATE, DELETE, DROP, INDEX, INSERT, SELECT, UPDATE ON %s.* TO %s@'localhost' " ,
@@ -128,7 +148,6 @@ protected function prepareDatabase(Fiddle $fiddle)
128
148
)
129
149
);
130
150
131
-
132
151
$ propelConfig = <<<EOF
133
152
propel:
134
153
database:
@@ -141,6 +160,11 @@ classname: Propel\Runtime\Connection\DebugPDO
141
160
password: $ password
142
161
attributes:
143
162
runtime:
163
+ log:
164
+ defaultLogger:
165
+ type: stream
166
+ path: ./propel_log.txt
167
+ level: 100
144
168
defaultConnection: default
145
169
connections:
146
170
- default
@@ -159,12 +183,12 @@ protected function prepareRuntimeConfig(Fiddle $fiddle)
159
183
{
160
184
$ directory = $ this ->getDirectory ($ fiddle );
161
185
162
- if (file_exists ($ directory . '/home/sandbox/generated-conf/ ' )) {
186
+ if (! $ this -> needConfigConvertCall && ! $ this -> debug && file_exists ($ directory . '/home/sandbox/generated-conf/config.php ' )) {
163
187
return ;
164
188
}
165
189
166
- $ this ->executeInJail ($ fiddle , '/usr/ bin/php /vendor/propel/propel/bin/propel config:convert ' );
167
-
190
+ $ output = $ this ->executeInJail ($ fiddle , '/bin/build- config.sh ' );
191
+ $ fiddle -> setConfigBuildOutput ( $ output );
168
192
}
169
193
170
194
/**
@@ -176,18 +200,18 @@ protected function buildDatabaseSchema(Fiddle $fiddle)
176
200
$ currentHash = $ this ->getSchemaHash ($ fiddle );
177
201
$ directory = $ this ->getDirectory ($ fiddle );
178
202
179
- if ($ lastBuiltHash !== $ currentHash ) {
203
+ if ($ this -> debug || $ lastBuiltHash !== $ currentHash ) {
180
204
$ buildOutput = $ this ->executeInJail ($ fiddle , '/bin/sql-build.sh ' );
181
205
$ fiddle ->setSqlBuildOutput ($ buildOutput );
182
206
183
207
$ buildOutput = $ this ->executeInJail ($ fiddle , '/bin/model-build.sh ' );
184
208
$ fiddle ->setModelBuildOutput ($ buildOutput );
185
209
}
186
210
187
- if (file_exists ($ directory . '/home/sandbox/generated-sql/ ' )) {
211
+ if ($ this -> debug || file_exists ($ directory . '/home/sandbox/generated-sql/ ' )) {
188
212
$ insertOutput = $ this ->executeInJail (
189
213
$ fiddle ,
190
- '/usr/ bin/php /vendor/propel/propel/bin/propel sql:insert -vv '
214
+ '/bin/sql-insert.sh '
191
215
);
192
216
$ fiddle ->setSqlInsertOutput ($ insertOutput );
193
217
} else {
@@ -206,11 +230,12 @@ protected function extractDbInformation(Fiddle $fiddle)
206
230
foreach ($ tables as $ table ) {
207
231
$ table = current ($ table );
208
232
$ tableIdentifier = $ identifier . '. ' . $ this ->db ->quoteIdentifier ($ table );
233
+ $ columns = $ this ->db ->fetchAll (sprintf ('SHOW COLUMNS FROM %s ' , $ tableIdentifier ));
209
234
$ items = $ this ->db ->fetchAll (sprintf ('SELECT * FROM %s LIMIT 1000 ' , $ tableIdentifier ));
210
235
$ result [] = [
211
236
'name ' => $ table ,
212
237
'count ' => count ($ items ),
213
- 'columns ' => $ items ? array_keys ( $ items [ 0 ]) : [] ,
238
+ 'columns ' => $ columns ,
214
239
'items ' => $ items ?: false
215
240
];
216
241
}
@@ -237,11 +262,25 @@ protected function getSchemaHash(Fiddle $fiddle)
237
262
* @param Fiddle $fiddle
238
263
* @return string
239
264
*/
240
- protected function getDirectory (Fiddle $ fiddle )
265
+ public function getDirectory (Fiddle $ fiddle )
241
266
{
242
267
return '/tmp/propelsandbox/chroots/ ' . $ fiddle ->getId ();
243
268
}
244
269
270
+ /**
271
+ * @param Fiddle $fiddle
272
+ * @return boolean
273
+ */
274
+ public function isUpdate2Date (Fiddle $ fiddle )
275
+ {
276
+ $ directory = $ this ->getDirectory ($ fiddle );
277
+ if (!file_exists ($ directory . '/home/sandbox/propel.yml ' )) {
278
+ return false ;
279
+ }
280
+
281
+ return true ;
282
+ }
283
+
245
284
/**
246
285
* @param Fiddle $fiddle
247
286
* @param string $command needs absolute path to the binary
0 commit comments