From dc187234989187911a74463460fbc122c8ab435c Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 6 Dec 2024 18:06:52 +0100 Subject: [PATCH] [Bugfix] Edition : exec a DELETE can return 0 in some cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `jDbConnection::exec()` returns the number of affected rows or False if the query has failed. In some cases, for exemple a DELETE on a view or a DELETE catches by a trigger can return no affected rows. So lizmap has to rollback() executed requests only if a query has failed. Funded by Conseil Départemental du Calvados and Ville d'Avignon --- lizmap/modules/lizmap/classes/qgisVectorLayer.class.php | 4 +++- lizmap/modules/lizmap/controllers/edition.classic.php | 2 +- lizmap/modules/lizmap/lib/Form/QgisForm.php | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php index 09af1a3d99..a1b77febc4 100644 --- a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php +++ b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php @@ -956,9 +956,11 @@ public function updateFeature($feature, $values, $loginFilteredLayers) * - attribute: filter attribute from the layer * @param null|jDbConnection $connection DBConnection, if not null then the parameter conneciton is used, default value null * - * @return int + * @return bool|int the number of affected rows. False if the query has failed. * * @throws Exception + * + * @see jDbConnection::exec() Launch a SQL Query (update, delete..) which doesn't return rows. */ public function deleteFeature($feature, $loginFilteredLayers, $connection = null) { diff --git a/lizmap/modules/lizmap/controllers/edition.classic.php b/lizmap/modules/lizmap/controllers/edition.classic.php index 6e22505ac9..f2cd64aa3d 100644 --- a/lizmap/modules/lizmap/controllers/edition.classic.php +++ b/lizmap/modules/lizmap/controllers/edition.classic.php @@ -1161,7 +1161,7 @@ public function deleteFeature() $feature = $this->featureData->features[0]; $rs = $qgisForm->deleteFromDb($feature, $cnx); - if ($rs) { + if ($rs !== false) { jMessage::add(jLocale::get('view~edition.message.success.delete'), 'success'); $eventParams['deleteFiles'] = $deleteFiles; $eventParams['success'] = true; diff --git a/lizmap/modules/lizmap/lib/Form/QgisForm.php b/lizmap/modules/lizmap/lib/Form/QgisForm.php index ade2078a0e..9ee8988a7a 100644 --- a/lizmap/modules/lizmap/lib/Form/QgisForm.php +++ b/lizmap/modules/lizmap/lib/Form/QgisForm.php @@ -1291,6 +1291,12 @@ protected function processWebDavUploadFile($form, $ref) * * @param mixed $feature * @param null|\jDbConnection $cnx DBConnection, passed along QGISVectorLayer deleteFeature method + * + * @return bool|int the number of affected rows. False if the query has failed. + * + * @throws \Exception + * + * @see \jDbConnection::exec() Launch a SQL Query (update, delete..) which doesn't return rows. */ public function deleteFromDb($feature, $cnx = null) { @@ -1316,7 +1322,7 @@ public function deleteFromDb($feature, $cnx = null) return 1; } if ($event->allResponsesByKeyAreFalse('cancelDelete') === false) { - return 0; + return false; } $result = $this->layer->deleteFeature($feature, $loginFilteredLayers, $cnx); $this->appContext->eventNotify('LizmapEditionFeaturePostDelete', $eventParams);