Skip to content

Commit 38f24ce

Browse files
authored
Merge pull request #5462 from rldhont/fix-constraint-geom
[Fix] QGIS constraint with geometry
2 parents 1bf3962 + 0d58ac9 commit 38f24ce

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

lizmap/modules/lizmap/lib/Form/QgisForm.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
229229
if ($wkt && \lizmapWkt::check($wkt)) {
230230
$geom = \lizmapWkt::parse($wkt);
231231
if ($geom === null) {
232-
\jLog::log('Parsing WKT failed! '.$wkt, 'error');
232+
$this->logMessage('Parsing WKT failed: "'.$wkt.'".', 'lizmapadmin');
233233
}
234234
}
235235

@@ -253,6 +253,19 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
253253
$form->getContainer()->privateData = array_merge($form->getContainer()->privateData, $privateData);
254254
}
255255

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+
256269
/**
257270
* Get the default value of a QGIS field, if this is
258271
* a simple raw value.
@@ -751,9 +764,23 @@ public function check($feature = null)
751764

752765
// Evaluate constraint expressions
753766
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+
754781
$form_feature = array(
755782
'type' => 'Feature',
756-
'geometry' => null,
783+
'geometry' => $geom,
757784
'properties' => $values,
758785
);
759786
$results = $this->evaluateExpression($constraintExpressions, $form_feature);
@@ -922,14 +949,14 @@ public function saveToDb($feature = null, $modifiedControls = array())
922949
if ($insertAction) {
923950
// For insertion, one field has to be set
924951
// 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');
926953
$this->form->setErrorOn($geometryColumn, \jLocale::get('view~edition.message.error.save').' '.\jLocale::get('view~edition.message.error.save.fields'));
927954

928955
// do not throw an exception to let the user update the form
929956
throw new \Exception($this->appContext->getLocale('view~edition.link.error.sql'));
930957
}
931958
// 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');
933960

934961
return true;
935962
}
@@ -994,7 +1021,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
9941021
} catch (\Exception $e) {
9951022
// Need to catch Exception if operation on remote storage fails
9961023
$form->setErrorOn($ref, $e->getMessage());
997-
$this->appContext->logMessage($e->getMessage(), 'lizmapadmin');
1024+
$this->logMessage($e->getMessage(), 'lizmapadmin');
9981025
$this->appContext->logException($e, 'lizmapadmin');
9991026

10001027
return false;
@@ -1042,7 +1069,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
10421069
return $pkVal;
10431070
} catch (\Exception $e) {
10441071
$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');
10461073
$this->appContext->logException($e, 'lizmapadmin');
10471074

10481075
return false;
@@ -1505,7 +1532,7 @@ protected function fillControlFromUniqueValues($fieldName, $formControl)
15051532
if (array_key_exists('notNull', $formControl->uniqueValuesData)
15061533
&& $formControl->uniqueValuesData['notNull']
15071534
) {
1508-
$this->appContext->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
1535+
$this->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
15091536
$formControl->ctrl->required = true;
15101537
}
15111538
// combobox
@@ -1539,7 +1566,7 @@ private function fillControlFromValueRelationLayer($fieldName, $formControl)
15391566
if (array_key_exists('notNull', $formControl->valueRelationData)
15401567
and $formControl->valueRelationData['notNull']
15411568
) {
1542-
\jLog::log('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
1569+
$this->logMessage('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
15431570
$formControl->ctrl->required = true;
15441571
}
15451572
// combobox

tests/end2end/playwright/axis_orientation.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ test.describe('Axis Orientation',
5151
const contentLength = await getMapResponse?.headerValue('Content-Length');
5252
expect(parseInt(contentLength ? contentLength : '0')).toBeGreaterThan(5552);
5353

54+
// Wait for transition
55+
await page.waitForTimeout(1000);
56+
5457
buffer = await page.screenshot({clip:{x:950/2-380/2, y:600/2-380/2, width:380, height:380}});
5558
const bundeslanderByteLength = buffer.byteLength;
5659
await expect(bundeslanderByteLength).toBeGreaterThan(blankByteLength);
@@ -142,6 +145,9 @@ test.describe('Axis Orientation',
142145
// image size lesser than disorder axis
143146
expect(parseInt(contentLength ? contentLength : '0')).toBeLessThan(240115);
144147

148+
// Wait for transition
149+
await page.waitForTimeout(1000);
150+
145151
buffer = await page.screenshot({clip:{x:950/2-380/2, y:600/2-380/2, width:380, height:380}});
146152
const judetByteLength = buffer.byteLength;
147153
await expect(judetByteLength).toBeGreaterThan(blankByteLength);

tests/units/classes/Form/QgisFormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function testFillControlFromUniqueValue($uniqueValues, $required, $setAtt
508508
}
509509
$control->uniqueValuesData = $uniqueValues;
510510
$control->ctrl->required = $required;
511-
$layer = new QgisLayerForTests();
511+
$layer = $this->setUpEnv('test', 'test', $dbFieldValues);
512512
$layer->dbFieldValues = $dbFieldValues;
513513
$form->setLayer($layer);
514514
$form->appContext = new ContextForTests();

0 commit comments

Comments
 (0)