From 3ec894c1676ed495f1f21115f01f43b82ae78c3b Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 4 Sep 2026 22:02:58 +0200 Subject: [PATCH] =?UTF-8?q?Don't=20block=20type=20changes=20on=20a=20pre-e?= =?UTF-8?q?xisting=20r=C3=A9partition=20=C3=A9cart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updateType() only ever touches field_type_ligne (and possibly field_entree_liee) -- never montant_ht or field_repartition -- so it can't introduce a new répartition mismatch, only leave an existing one (preserved from historical data, per the module's own docblock) untouched. Wrap the save in the same skip_validation state flag the migration scripts use, scoped tightly with try/finally so it always clears even if save() throws for an unrelated reason. Verified: changing the type of a line with a known -0.02€ écart now succeeds, the écart is unchanged afterward (montant_ht and the répartition sum both identical to before), and the state flag reads back unset once the request completes. --- .../src/Controller/LedgerActionsController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/modules/custom/figli_compta_ledger/src/Controller/LedgerActionsController.php b/web/modules/custom/figli_compta_ledger/src/Controller/LedgerActionsController.php index 52ead26..5e3b8d7 100644 --- a/web/modules/custom/figli_compta_ledger/src/Controller/LedgerActionsController.php +++ b/web/modules/custom/figli_compta_ledger/src/Controller/LedgerActionsController.php @@ -66,12 +66,26 @@ class LedgerActionsController extends ControllerBase { $node->set('field_entree_liee', NULL); } + // Only field_type_ligne (and possibly field_entree_liee) changes here + // -- montant_ht and field_repartition are untouched, so this can never + // *introduce* a répartition mismatch, only leave a pre-existing one + // (from historical data, never corrected -- see figli_compta_ledger's + // module docblock) exactly as it was. The présave check exists to + // catch new inconsistent entries, not to block relabeling the type of + // an already-migrated line, so skip it for this save only. try/finally + // guarantees the global flag clears even if save() throws for an + // unrelated reason -- leaving it on would silently skip validation on + // every other save on the site. + \Drupal::state()->set('figli_compta_ledger.skip_validation', TRUE); try { $node->save(); } catch (EntityStorageException $e) { return new JsonResponse(['error' => $e->getMessage()], 422); } + finally { + \Drupal::state()->delete('figli_compta_ledger.skip_validation'); + } return new JsonResponse([ 'success' => TRUE,