8
8
use GearboxSolutions \EloquentFileMaker \Database \Schema \FMBuilder ;
9
9
use GearboxSolutions \EloquentFileMaker \Exceptions \FileMakerDataApiException ;
10
10
use Illuminate \Database \Connection ;
11
+ use Illuminate \Database \Events \QueryExecuted ;
11
12
use Illuminate \Http \Client \PendingRequest ;
12
13
use Illuminate \Http \UploadedFile ;
13
14
use Illuminate \Support \Arr ;
14
15
use Illuminate \Support \Collection ;
15
16
use Illuminate \Support \Facades \Cache ;
16
17
use Illuminate \Support \Facades \Http ;
18
+ use Illuminate \Support \Str ;
17
19
use Symfony \Component \HttpFoundation \File \File ;
18
20
19
21
class FileMakerConnection extends Connection
@@ -690,6 +692,8 @@ protected function prepareRequestForSending($request)
690
692
*/
691
693
protected function makeRequest ($ method , $ url , $ params = [], ?PendingRequest $ request = null )
692
694
{
695
+ $ start = microtime (true );
696
+
693
697
$ this ->login ();
694
698
695
699
$ request = $ this ->prepareRequestForSending ($ request );
@@ -713,12 +717,65 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req
713
717
}
714
718
}
715
719
720
+ $ this ->logFMQuery ($ method , $ url , $ params , $ start );
721
+
716
722
// Return the JSON response
717
723
$ json = $ response ->json ();
718
724
719
725
return $ json ;
720
726
}
721
727
728
+ protected function logFMQuery ($ method , $ url , $ params , $ start )
729
+ {
730
+ $ commandType = $ this ->getSqlCommandType ($ method , $ url );
731
+
732
+ // Clockwork specifically looks for the commandType as the first word in the "sql" string
733
+ $ sql = <<<DOC
734
+ {$ commandType }
735
+ Method: {$ method }
736
+ URL: {$ url }
737
+ DOC ;
738
+
739
+ if (count ($ params ) > 0 ) {
740
+ $ sql .= "\nData: " . json_encode ($ params , JSON_PRETTY_PRINT );
741
+ }
742
+
743
+ $ this ->event (new QueryExecuted ($ sql , Arr::get ($ params , 'query ' , []), $ this ->getElapsedTime ($ start ), $ this ));
744
+ }
745
+
746
+ protected function getSqlCommandType ($ method , $ url )
747
+ {
748
+ if ($ method === 'delete ' ) {
749
+ return 'delete ' ;
750
+ }
751
+
752
+ if ($ method === 'patch ' ) {
753
+ return 'update ' ;
754
+ }
755
+
756
+ if ($ method === 'get ' ) {
757
+ if (Str::contains ($ url , 'script ' )) {
758
+ return 'exec ' ;
759
+ }
760
+
761
+ return 'select ' ;
762
+ }
763
+
764
+ if ($ method === 'post ' ) {
765
+ if (Str::contains ($ url , 'containers ' )) {
766
+ return 'update ' ;
767
+ }
768
+
769
+ if (Str::contains ($ url , '_find ' )) {
770
+ return 'select ' ;
771
+ }
772
+
773
+ return 'insert ' ;
774
+ }
775
+
776
+ return 'other ' ;
777
+ }
778
+
722
779
public function setRetries ($ retries )
723
780
{
724
781
$ this ->retries = $ retries ;
0 commit comments