Skip to content

Commit

Permalink
Merge pull request #5507 from rldhont/backport-5462-to-release_3_8
Browse files Browse the repository at this point in the history
[Backport release_3_8] [Fix] QGIS constraint with geometry
  • Loading branch information
rldhont authored Mar 3, 2025
2 parents ed4e620 + 0f458fb commit 2561a03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
41 changes: 34 additions & 7 deletions lizmap/modules/lizmap/lib/Form/QgisForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
$form->getContainer()->privateData = array_merge($form->getContainer()->privateData, $privateData);
}

/**
* Log a Form message.
*
* @param mixed $message The message to log
* @param string $cat The category of the logged message
*/
protected function logMessage($message, $cat = 'default'): void
{
$project = $this->layer->getProject();
$prefix = 'Error in form '.$project->getRepository()->getKey().' / '.$project->getKey().' / '.$this->layer->getName().': ';
$this->appContext->logMessage($prefix.$message, $cat);
}

/**
* Get the default value of a QGIS field, if this is
* a simple raw value.
Expand Down Expand Up @@ -708,9 +721,23 @@ public function check($feature = null)

// Evaluate constraint expressions
if (count($constraintExpressions) > 0) {

// build geom
$geom = null;
if ($geometryColumn != '') {
// from wkt to geom
$wkt = trim($form->getData($values[$geometryColumn]));
if ($wkt && \lizmapWkt::check($wkt)) {
$geom = \lizmapWkt::parse($wkt);
if ($geom === null) {
$this->logMessage('Parsing WKT failed: "'.$wkt.'".', 'lizmapadmin');
}
}
}

$form_feature = array(
'type' => 'Feature',
'geometry' => null,
'geometry' => $geom,
'properties' => $values,
);
$results = $this->evaluateExpression($constraintExpressions, $form_feature);
Expand Down Expand Up @@ -879,14 +906,14 @@ public function saveToDb($feature = null, $modifiedControls = array())
if ($insertAction) {
// For insertion, one field has to be set
// FIXME missing context
$this->appContext->logMessage('Error in form, SQL cannot be constructed: no fields available for insert !', 'lizmapadmin');
$this->logMessage('SQL cannot be constructed: no fields available for insert.', 'lizmapadmin');
$this->form->setErrorOn($geometryColumn, \jLocale::get('view~edition.message.error.save').' '.\jLocale::get('view~edition.message.error.save.fields'));

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

return true;
}
Expand Down Expand Up @@ -951,7 +978,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
} catch (\Exception $e) {
// Need to catch Exception if operation on remote storage fails
$form->setErrorOn($ref, $e->getMessage());
$this->appContext->logMessage($e->getMessage(), 'lizmapadmin');
$this->logMessage($e->getMessage(), 'lizmapadmin');
$this->appContext->logException($e, 'lizmapadmin');

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

return false;
Expand Down Expand Up @@ -1462,7 +1489,7 @@ protected function fillControlFromUniqueValues($fieldName, $formControl)
if (array_key_exists('notNull', $formControl->uniqueValuesData)
&& $formControl->uniqueValuesData['notNull']
) {
$this->appContext->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
$this->logMessage('notNull '.$formControl->uniqueValuesData['notNull'], 'lizmapadmin');
$formControl->ctrl->required = true;
}
// combobox
Expand Down Expand Up @@ -1496,7 +1523,7 @@ private function fillControlFromValueRelationLayer($fieldName, $formControl)
if (array_key_exists('notNull', $formControl->valueRelationData)
and $formControl->valueRelationData['notNull']
) {
\jLog::log('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
$this->logMessage('notNull '.$formControl->valueRelationData['notNull'], 'lizmapadmin');
$formControl->ctrl->required = true;
}
// combobox
Expand Down
6 changes: 6 additions & 0 deletions tests/end2end/playwright/axis_orientation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ test.describe('Axis Orientation',
const contentLength = await getMapResponse?.headerValue('Content-Length');
expect(parseInt(contentLength ? contentLength : '0')).toBeGreaterThan(5552);

// Wait for transition
await page.waitForTimeout(1000);

buffer = await page.screenshot({clip:{x:950/2-380/2, y:600/2-380/2, width:380, height:380}});
const bundeslanderByteLength = buffer.byteLength;
await expect(bundeslanderByteLength).toBeGreaterThan(blankByteLength);
Expand Down Expand Up @@ -142,6 +145,9 @@ test.describe('Axis Orientation',
// image size lesser than disorder axis
expect(parseInt(contentLength ? contentLength : '0')).toBeLessThan(240115);

// Wait for transition
await page.waitForTimeout(1000);

buffer = await page.screenshot({clip:{x:950/2-380/2, y:600/2-380/2, width:380, height:380}});
const judetByteLength = buffer.byteLength;
await expect(judetByteLength).toBeGreaterThan(blankByteLength);
Expand Down
2 changes: 1 addition & 1 deletion tests/units/classes/Form/QgisFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public function testFillControlFromUniqueValue($uniqueValues, $required, $setAtt
}
$control->uniqueValuesData = $uniqueValues;
$control->ctrl->required = $required;
$layer = new QgisLayerForTests();
$layer = $this->setUpEnv('test', 'test', $dbFieldValues);
$layer->dbFieldValues = $dbFieldValues;
$form->setLayer($layer);
$form->appContext = new ContextForTests();
Expand Down

0 comments on commit 2561a03

Please sign in to comment.