Skip to content

Commit 2561a03

Browse files
authored
Merge pull request #5507 from rldhont/backport-5462-to-release_3_8
[Backport release_3_8] [Fix] QGIS constraint with geometry
2 parents ed4e620 + 0f458fb commit 2561a03

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
210210
$form->getContainer()->privateData = array_merge($form->getContainer()->privateData, $privateData);
211211
}
212212

213+
/**
214+
* Log a Form message.
215+
*
216+
* @param mixed $message The message to log
217+
* @param string $cat The category of the logged message
218+
*/
219+
protected function logMessage($message, $cat = 'default'): void
220+
{
221+
$project = $this->layer->getProject();
222+
$prefix = 'Error in form '.$project->getRepository()->getKey().' / '.$project->getKey().' / '.$this->layer->getName().': ';
223+
$this->appContext->logMessage($prefix.$message, $cat);
224+
}
225+
213226
/**
214227
* Get the default value of a QGIS field, if this is
215228
* a simple raw value.
@@ -708,9 +721,23 @@ public function check($feature = null)
708721

709722
// Evaluate constraint expressions
710723
if (count($constraintExpressions) > 0) {
724+
725+
// build geom
726+
$geom = null;
727+
if ($geometryColumn != '') {
728+
// from wkt to geom
729+
$wkt = trim($form->getData($values[$geometryColumn]));
730+
if ($wkt && \lizmapWkt::check($wkt)) {
731+
$geom = \lizmapWkt::parse($wkt);
732+
if ($geom === null) {
733+
$this->logMessage('Parsing WKT failed: "'.$wkt.'".', 'lizmapadmin');
734+
}
735+
}
736+
}
737+
711738
$form_feature = array(
712739
'type' => 'Feature',
713-
'geometry' => null,
740+
'geometry' => $geom,
714741
'properties' => $values,
715742
);
716743
$results = $this->evaluateExpression($constraintExpressions, $form_feature);
@@ -879,14 +906,14 @@ public function saveToDb($feature = null, $modifiedControls = array())
879906
if ($insertAction) {
880907
// For insertion, one field has to be set
881908
// FIXME missing context
882-
$this->appContext->logMessage('Error in form, SQL cannot be constructed: no fields available for insert !', 'lizmapadmin');
909+
$this->logMessage('SQL cannot be constructed: no fields available for insert.', 'lizmapadmin');
883910
$this->form->setErrorOn($geometryColumn, \jLocale::get('view~edition.message.error.save').' '.\jLocale::get('view~edition.message.error.save.fields'));
884911

885912
// do not throw an exception to let the user update the form
886913
throw new \Exception($this->appContext->getLocale('view~edition.link.error.sql'));
887914
}
888915
// For update, nothing has changed so nothing to do except close form
889-
$this->appContext->logMessage('SQL cannot be constructed: no fields available for update !', 'lizmapadmin');
916+
$this->logMessage('SQL cannot be constructed: no fields available for update.', 'lizmapadmin');
890917

891918
return true;
892919
}
@@ -951,7 +978,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
951978
} catch (\Exception $e) {
952979
// Need to catch Exception if operation on remote storage fails
953980
$form->setErrorOn($ref, $e->getMessage());
954-
$this->appContext->logMessage($e->getMessage(), 'lizmapadmin');
981+
$this->logMessage($e->getMessage(), 'lizmapadmin');
955982
$this->appContext->logException($e, 'lizmapadmin');
956983

957984
return false;
@@ -999,7 +1026,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
9991026
return $pkVal;
10001027
} catch (\Exception $e) {
10011028
$form->setErrorOn($geometryColumn, $this->appContext->getLocale('view~edition.message.error.save'));
1002-
$this->appContext->logMessage('An error has been raised when saving form data edition to db : ', 'lizmapadmin');
1029+
$this->logMessage('An error has been raised when saving form data edition to the database.', 'lizmapadmin');
10031030
$this->appContext->logException($e, 'lizmapadmin');
10041031

10051032
return false;
@@ -1462,7 +1489,7 @@ protected function fillControlFromUniqueValues($fieldName, $formControl)
14621489
if (array_key_exists('notNull', $formControl->uniqueValuesData)
14631490
&& $formControl->uniqueValuesData['notNull']
14641491
) {
1465-
$this->appContext->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
1492+
$this->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
14661493
$formControl->ctrl->required = true;
14671494
}
14681495
// combobox
@@ -1496,7 +1523,7 @@ private function fillControlFromValueRelationLayer($fieldName, $formControl)
14961523
if (array_key_exists('notNull', $formControl->valueRelationData)
14971524
and $formControl->valueRelationData['notNull']
14981525
) {
1499-
\jLog::log('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
1526+
$this->logMessage('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
15001527
$formControl->ctrl->required = true;
15011528
}
15021529
// 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)