add some call_triggers (#39449)

* add triggers in fichinter.class.php

* Update api_users.class.php

* FIX: Add missing triggers on setters that were silently skipping them

Societe::setAsCustomer(), Don::set_cancel(), Expedition::setDeliveryDate()/setShippingDate()
and the whole FichinterRec class were updating rows without ever calling call_trigger(),
unlike sibling methods/classes (update(), reopen(), FactureRec) that do. FichinterRec also
gets its own TRIGGER_PREFIX ('FICHINTERREC') since it inherited Fichinter's 'FICHINTER'
prefix, which would have collided with real intervention triggers.
This commit is contained in:
Frédéric FRANCE 2026-08-11 02:34:08 +02:00 committed by GitHub
parent ab8daf516f
commit 7858059c63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 230 additions and 26 deletions

View file

@ -6,7 +6,7 @@
* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2019-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2021 Maxime DEMAREST <maxime@indelog.fr>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
*
@ -835,24 +835,48 @@ class Don extends CommonObject
/**
* Set donation to status cancelled
*
* @param int $id id of donation
* @return int Return integer <0 if KO, >0 if OK
* @param int $id id of donation
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int Return integer <0 if KO, >0 if OK
*/
public function set_cancel($id)
public function set_cancel($id, $notrigger = 0)
{
// phpcs:enable
global $user;
$error = 0;
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".((int) $id);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->affected_rows($resql)) {
$this->status = -1;
return 1;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('DON_CANCEL', $user);
if ($result < 0) {
$error++;
}
// End call triggers
}
} else {
$this->db->commit();
return 0;
}
} else {
dol_print_error($this->db);
$this->error = $this->db->error();
$error++;
}
if (!$error) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}

View file

@ -11,7 +11,7 @@
* Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
* Copyright (C) 2016-2024 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2020 Lenin Rivas <lenin@leninrivas.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
@ -2784,11 +2784,14 @@ class Expedition extends CommonObject
*
* @param User $user Object user that modify
* @param integer $delivery_date Date of delivery
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setDeliveryDate($user, $delivery_date)
public function setDeliveryDate($user, $delivery_date, $notrigger = 0)
{
if ($user->hasRight('expedition', 'creer')) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
$sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null');
$sql .= " WHERE rowid = ".((int) $this->id);
@ -2797,9 +2800,22 @@ class Expedition extends CommonObject
$resql = $this->db->query($sql);
if ($resql) {
$this->date_delivery = $delivery_date;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('SHIPPING_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
// End call triggers
}
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
} else {
@ -2812,11 +2828,14 @@ class Expedition extends CommonObject
*
* @param User $user Object user that modify
* @param integer $shipping_date Date of shipping
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setShippingDate($user, $shipping_date)
public function setShippingDate($user, $shipping_date, $notrigger = 0)
{
if ($user->hasRight('expedition', 'creer')) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
$sql .= " SET date_expedition = ".($shipping_date ? "'".$this->db->idate($shipping_date)."'" : 'null');
$sql .= " WHERE rowid = ".((int) $this->id);
@ -2825,9 +2844,22 @@ class Expedition extends CommonObject
$resql = $this->db->query($sql);
if ($resql) {
$this->date_shipping = $shipping_date;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('SHIPPING_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
// End call triggers
}
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
} else {

View file

@ -1245,6 +1245,8 @@ class Fichinter extends CommonObject
{
// phpcs:enable
if ($user->hasRight('ficheinter', 'creer')) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
$sql .= " SET datei = '".$this->db->idate($delivery_date_receipt)."'";
$sql .= " WHERE rowid = ".((int) $this->id);
@ -1253,10 +1255,19 @@ class Fichinter extends CommonObject
if ($this->db->query($sql)) {
$this->date_delivery = $delivery_date_receipt;
$this->delivery_date_receipt = $delivery_date_receipt;
$result = $this->call_trigger($this->TRIGGER_PREFIX . '_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
dol_syslog("Fichinter::set_date_delivery Erreur SQL");
$this->db->rollback();
return -1;
}
}
@ -1276,6 +1287,8 @@ class Fichinter extends CommonObject
{
// phpcs:enable
if ($user->hasRight('ficheinter', 'creer')) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
$sql .= " SET description = '".$this->db->escape($description)."',";
$sql .= " fk_user_modif = ".((int) $user->id);
@ -1283,10 +1296,19 @@ class Fichinter extends CommonObject
if ($this->db->query($sql)) {
$this->description = $description;
$result = $this->call_trigger($this->TRIGGER_PREFIX . '_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
dol_syslog("Fichinter::set_description Erreur SQL");
$this->db->rollback();
return -1;
}
}
@ -1307,15 +1329,26 @@ class Fichinter extends CommonObject
{
// phpcs:enable
if ($user->hasRight('ficheinter', 'creer')) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
$sql .= " SET fk_contrat = ".((int) $contractid);
$sql .= " WHERE rowid = ".((int) $this->id);
if ($this->db->query($sql)) {
$this->fk_contrat = $contractid;
$result = $this->call_trigger($this->TRIGGER_PREFIX . '_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}

View file

@ -45,6 +45,12 @@ class FichinterRec extends Fichinter
public $table_element = 'fichinter_rec';
public $table_element_line = 'fichinterdet_rec';
/**
* @var string Prefix of trigger name (distinct from the parent Fichinter's 'FICHINTER' prefix since
* this class manages recurring intervention templates, not actual interventions)
*/
public $TRIGGER_PREFIX = 'FICHINTERREC';
/**
* {@inheritdoc}
*/
@ -263,6 +269,15 @@ class FichinterRec extends Fichinter
}
}
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_CREATE', $user);
if ($result < 0) {
$error++;
}
// End call triggers
}
if ($error) {
$this->db->rollback();
return -1;
@ -459,6 +474,15 @@ class FichinterRec extends Fichinter
$error = -2;
}
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_DELETE', $user);
if ($result < 0) {
$error = -3;
}
// End call triggers
}
if (!$error) {
$this->db->commit();
return 1;
@ -600,12 +624,13 @@ class FichinterRec extends Fichinter
/**
* Rend la fichinter automatique
*
* @param User $user User object
* @param int $freq Freq
* @param string $courant Courant
* @return int 0 if OK, <0 if KO
* @param User $user User object
* @param int $freq Freq
* @param string $courant Courant
* @param int<0,1> $notrigger Disable the trigger
* @return int 0 if OK, <0 if KO
*/
public function set_auto($user, $freq, $courant)
public function set_auto($user, $freq, $courant, $notrigger = 0)
{
// phpcs:enable
if ($user->hasRight('fichinter', 'creer')) {
@ -619,6 +644,16 @@ class FichinterRec extends Fichinter
if ($resql) {
$this->frequency = $freq;
$this->date_last_gen = $courant;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 0;
} else {
dol_print_error($this->db);
@ -733,12 +768,15 @@ class FichinterRec extends Fichinter
/**
* Update frequency and unit
*
* @param ?int $frequency value of frequency
* @param string $unit unit of frequency (d, m, y)
* @return int Return integer <0 if KO, >0 if OK
* @param ?int $frequency value of frequency
* @param string $unit unit of frequency (d, m, y)
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setFrequencyAndUnit($frequency, $unit)
public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
return -1;
@ -762,6 +800,16 @@ class FichinterRec extends Fichinter
if (!empty($unit)) {
$this->unit_frequency = $unit;
}
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -774,10 +822,13 @@ class FichinterRec extends Fichinter
*
* @param int $date date of execution
* @param int<0,max> $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setNextDate($date, $increment_nb_gen_done = 0)
public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
return -1;
@ -795,6 +846,16 @@ class FichinterRec extends Fichinter
if ($increment_nb_gen_done > 0) {
$this->nb_gen_done++;
}
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -805,11 +866,14 @@ class FichinterRec extends Fichinter
/**
* Update the maximum period
*
* @param int $nb number of maximum period
* @return int Return integer <0 if KO, >0 if OK
* @param int $nb number of maximum period
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setMaxPeriod($nb)
public function setMaxPeriod($nb, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
return -1;
@ -826,6 +890,16 @@ class FichinterRec extends Fichinter
dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->nb_gen_max = $nb;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -836,11 +910,14 @@ class FichinterRec extends Fichinter
/**
* Update the auto validate fichinter
*
* @param int $validate 0 to create in draft, 1 to create and validate fichinter
* @param int $validate 0 to create in draft, 1 to create and validate fichinter
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function setAutoValidate($validate)
public function setAutoValidate($validate, $notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
return -1;
@ -853,6 +930,16 @@ class FichinterRec extends Fichinter
dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->auto_validate = $validate;
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);
@ -863,10 +950,13 @@ class FichinterRec extends Fichinter
/**
* Update the Number of Generation Done
*
* @param int<0,1> $notrigger Disable the trigger
* @return int Return integer <0 if KO, >0 if OK
*/
public function updateNbGenDone()
public function updateNbGenDone($notrigger = 0)
{
global $user;
if (!$this->table_element) {
dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
return -1;
@ -882,11 +972,21 @@ class FichinterRec extends Fichinter
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
dol_syslog(get_class($this)."::updateNbGenDone", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->nb_gen_done++;
$this->date_last_gen = dol_now();
//$this->date_when = ...
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
if ($result < 0) {
return -1;
}
// End call triggers
}
return 1;
} else {
dol_print_error($this->db);

View file

@ -2743,6 +2743,8 @@ class Societe extends CommonObject
*/
public function setAsCustomer()
{
global $user;
if ($this->id) {
$newclient = 1;
if (($this->client == 2 || $this->client == 3) && !getDolGlobalInt('SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
@ -2752,11 +2754,24 @@ class Societe extends CommonObject
$sql .= " SET client = ".((int) $newclient);
$sql .= " WHERE rowid = ".((int) $this->id);
$this->db->begin();
$resql = $this->db->query($sql);
if ($resql) {
$this->client = $newclient;
// Call trigger
$result = $this->call_trigger('COMPANY_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
return -1;
}
// End call triggers
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}