From 9dddd42c8897eaeeb13b58024e31af74272ea9e1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 18 Feb 2025 17:03:01 +0100 Subject: [PATCH] FIX compare to avoid delete new invoices --- class/facturesituationmigration.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/class/facturesituationmigration.class.php b/class/facturesituationmigration.class.php index 0aa6bfb..7e636a5 100644 --- a/class/facturesituationmigration.class.php +++ b/class/facturesituationmigration.class.php @@ -577,10 +577,16 @@ public function rollbackMigration() $this->db->begin(); + $sql = "SET FOREIGN_KEY_CHECKS=0;"; + $this->db->query($sql); + + // TODO this rollback restore all entities (Multicompany) + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_facturedet.""; $sql.= " WHERE rowid IN ("; $sql.= "SELECT * FROM (SELECT fd.rowid FROM ".MAIN_DB_PREFIX.$this->table_facturedet." as fd"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX.$this->table_facture." as f ON f.rowid = fd.fk_facture AND f.type = '".facture::TYPE_SITUATION."') as tmp"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX.$this->table_facture." as f ON f.rowid = fd.fk_facture AND f.type = '"Facture::TYPE_SITUATION."'"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX.$this->table_migration." as m ON m.rowid = f.rowid) as tmp"; // compare to avoid delete new invoices created after migration $sql.= ")"; dol_syslog('sql='.$sql, LOG_DEBUG, 0, '_situationmigration'); @@ -593,6 +599,9 @@ public function rollbackMigration() $res2 = $this->db->query($sql2); if (!$res2) : $this->db->rollback(); return - 2; endif; + $sql = "SET FOREIGN_KEY_CHECKS=1;"; + $this->db->query($sql); + if (!dolibarr_set_const($this->db, 'MAIN_MODULE_FACTURESITUATIONMIGRATION_STEP', '0', 'chaine', 0, '', $conf->entity)) : $this->db->rollback(); return -3; endif; if (!dolibarr_set_const($this->db, 'FACTURESITUATIONMIGRATION_ISDONE', '0', 'chaine', 0, '', $conf->entity)) : $this->db->rollback(); return -3; endif; if (!dolibarr_set_const($this->db, 'INVOICE_USE_SITUATION', '1', 'chaine', 0, '', $conf->entity)) : $this->db->rollback(); return -3; endif;