@@ -15,13 +15,17 @@ public function convertToMongoDBQueryAction() {
1515 return new JsonResponse (400 , ErrorNormalizer::normalize ($ th , __METHOD__ ));
1616 }
1717
18+ // Converter takes only inline SQL as input.
19+ $ decodedRequestBody ['sql ' ] = str_replace ("\n" , ' ' , $ decodedRequestBody ['sql ' ]);
20+
21+ $ decodedRequestBody ['sql ' ] = str_replace ('" ' , '\" ' , $ decodedRequestBody ['sql ' ]);
22+
1823 $ jarPath = '" ' . MPG_ABS_PATH
1924 . '/static/jar/sql-to-mongo-db-query-converter-1.13-standalone.jar" ' ;
20- $ jarArgs = '--sql " ' . str_replace ( ' " ' , ' \" ' , $ decodedRequestBody ['sql ' ]) . '" ' ;
25+ $ jarArgs = '--sql " ' . $ decodedRequestBody ['sql ' ] . '" ' ;
2126
2227 $ command = 'java -jar ' . $ jarPath . ' ' . $ jarArgs ;
2328
24- // If OS is Windows:
2529 if ( strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
2630 // Force output.
2731 $ command .= ' 2>&1 ' ;
@@ -32,7 +36,7 @@ public function convertToMongoDBQueryAction() {
3236 $ mongoDBQuery = [];
3337
3438 try {
35- if ( !preg_match_all ('|^.*\.find\((.*)\)$|s ' , $ commandResult , $ mongoDBQuery ) ) {
39+ if ( !preg_match_all ('|^.*\.find\({ (.*)} \)$|s ' , $ commandResult , $ mongoDBQuery ) ) {
3640 throw new \Exception (
3741 'Impossible to convert (SELECT) SQL query to MongoDB query... ' .
3842 'Try to install Java JDK on the computer hosting " ' . MPG_APP_NAME . '". '
@@ -42,7 +46,7 @@ public function convertToMongoDBQueryAction() {
4246 return new JsonResponse (500 , ErrorNormalizer::normalize ($ th , __METHOD__ ));
4347 }
4448
45- return new JsonResponse (200 , $ mongoDBQuery [1 ][0 ]);
49+ return new JsonResponse (200 , ' { ' . $ mongoDBQuery [1 ][0 ] . ' } ' );
4650
4751 }
4852
0 commit comments