@@ -229,7 +229,7 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
229
229
if ($ wkt && \lizmapWkt::check ($ wkt )) {
230
230
$ geom = \lizmapWkt::parse ($ wkt );
231
231
if ($ geom === null ) {
232
- \jLog:: log ('Parsing WKT failed! ' .$ wkt , 'error ' );
232
+ $ this -> logMessage ('Parsing WKT failed: " ' .$ wkt. ' ". ' , 'lizmapadmin ' );
233
233
}
234
234
}
235
235
@@ -253,6 +253,19 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
253
253
$ form ->getContainer ()->privateData = array_merge ($ form ->getContainer ()->privateData , $ privateData );
254
254
}
255
255
256
+ /**
257
+ * Log a Form message.
258
+ *
259
+ * @param mixed $message The message to log
260
+ * @param string $cat The category of the logged message
261
+ */
262
+ protected function logMessage ($ message , $ cat = 'default ' ): void
263
+ {
264
+ $ project = $ this ->layer ->getProject ();
265
+ $ prefix = 'Error in form ' .$ project ->getRepository ()->getKey ().' / ' .$ project ->getKey ().' / ' .$ this ->layer ->getName ().': ' ;
266
+ $ this ->appContext ->logMessage ($ prefix .$ message , $ cat );
267
+ }
268
+
256
269
/**
257
270
* Get the default value of a QGIS field, if this is
258
271
* a simple raw value.
@@ -751,9 +764,23 @@ public function check($feature = null)
751
764
752
765
// Evaluate constraint expressions
753
766
if (count ($ constraintExpressions ) > 0 ) {
767
+
768
+ // build geom
769
+ $ geom = null ;
770
+ if ($ geometryColumn != '' ) {
771
+ // from wkt to geom
772
+ $ wkt = trim ($ form ->getData ($ values [$ geometryColumn ]));
773
+ if ($ wkt && \lizmapWkt::check ($ wkt )) {
774
+ $ geom = \lizmapWkt::parse ($ wkt );
775
+ if ($ geom === null ) {
776
+ $ this ->logMessage ('Parsing WKT failed: " ' .$ wkt .'". ' , 'lizmapadmin ' );
777
+ }
778
+ }
779
+ }
780
+
754
781
$ form_feature = array (
755
782
'type ' => 'Feature ' ,
756
- 'geometry ' => null ,
783
+ 'geometry ' => $ geom ,
757
784
'properties ' => $ values ,
758
785
);
759
786
$ results = $ this ->evaluateExpression ($ constraintExpressions , $ form_feature );
@@ -922,14 +949,14 @@ public function saveToDb($feature = null, $modifiedControls = array())
922
949
if ($ insertAction ) {
923
950
// For insertion, one field has to be set
924
951
// FIXME missing context
925
- $ this ->appContext -> logMessage ('Error in form, SQL cannot be constructed: no fields available for insert ! ' , 'lizmapadmin ' );
952
+ $ this ->logMessage ('SQL cannot be constructed: no fields available for insert. ' , 'lizmapadmin ' );
926
953
$ this ->form ->setErrorOn ($ geometryColumn , \jLocale::get ('view~edition.message.error.save ' ).' ' .\jLocale::get ('view~edition.message.error.save.fields ' ));
927
954
928
955
// do not throw an exception to let the user update the form
929
956
throw new \Exception ($ this ->appContext ->getLocale ('view~edition.link.error.sql ' ));
930
957
}
931
958
// For update, nothing has changed so nothing to do except close form
932
- $ this ->appContext -> logMessage ('SQL cannot be constructed: no fields available for update ! ' , 'lizmapadmin ' );
959
+ $ this ->logMessage ('SQL cannot be constructed: no fields available for update. ' , 'lizmapadmin ' );
933
960
934
961
return true ;
935
962
}
@@ -994,7 +1021,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
994
1021
} catch (\Exception $ e ) {
995
1022
// Need to catch Exception if operation on remote storage fails
996
1023
$ form ->setErrorOn ($ ref , $ e ->getMessage ());
997
- $ this ->appContext -> logMessage ($ e ->getMessage (), 'lizmapadmin ' );
1024
+ $ this ->logMessage ($ e ->getMessage (), 'lizmapadmin ' );
998
1025
$ this ->appContext ->logException ($ e , 'lizmapadmin ' );
999
1026
1000
1027
return false ;
@@ -1042,7 +1069,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
1042
1069
return $ pkVal ;
1043
1070
} catch (\Exception $ e ) {
1044
1071
$ form ->setErrorOn ($ geometryColumn , $ this ->appContext ->getLocale ('view~edition.message.error.save ' ));
1045
- $ this ->appContext -> logMessage ('An error has been raised when saving form data edition to db : ' , 'lizmapadmin ' );
1072
+ $ this ->logMessage ('An error has been raised when saving form data edition to the database. ' , 'lizmapadmin ' );
1046
1073
$ this ->appContext ->logException ($ e , 'lizmapadmin ' );
1047
1074
1048
1075
return false ;
@@ -1505,7 +1532,7 @@ protected function fillControlFromUniqueValues($fieldName, $formControl)
1505
1532
if (array_key_exists ('notNull ' , $ formControl ->uniqueValuesData )
1506
1533
&& $ formControl ->uniqueValuesData ['notNull ' ]
1507
1534
) {
1508
- $ this ->appContext -> logMessage ('notNull ' .$ formControl ->uniqueValuesData ['notNull ' ], 'lizmapadmin ' );
1535
+ $ this ->logMessage ('notNull ' .$ formControl ->uniqueValuesData ['notNull ' ], 'lizmapadmin ' );
1509
1536
$ formControl ->ctrl ->required = true ;
1510
1537
}
1511
1538
// combobox
@@ -1539,7 +1566,7 @@ private function fillControlFromValueRelationLayer($fieldName, $formControl)
1539
1566
if (array_key_exists ('notNull ' , $ formControl ->valueRelationData )
1540
1567
and $ formControl ->valueRelationData ['notNull ' ]
1541
1568
) {
1542
- \jLog:: log ('notNull ' .$ formControl ->valueRelationData ['notNull ' ], 'lizmapadmin ' );
1569
+ $ this -> logMessage ('notNull ' .$ formControl ->valueRelationData ['notNull ' ], 'lizmapadmin ' );
1543
1570
$ formControl ->ctrl ->required = true ;
1544
1571
}
1545
1572
// combobox
0 commit comments