|
@@ -4325,7 +4325,7 @@ abstract class CommonObject
|
|
|
* @param int $status Status to set
|
|
|
* @param int $elementId Id of element to force (use this->id by default if null)
|
|
|
* @param string $elementType Type of element to force (use this->table_element by default)
|
|
|
- * @param string $trigkey Trigger key to use for trigger. Use '' means automatic but it not recommended and is deprecated.
|
|
|
+ * @param string $trigkey Trigger key to use for trigger. Use '' means automatic but it is not recommended and is deprecated.
|
|
|
* @param string $fieldstatus Name of status field in this->table_element
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
@@ -4375,41 +4375,49 @@ abstract class CommonObject
|
|
|
if ($status == 1 && in_array($elementTable, array('inventory'))) {
|
|
|
$sql .= ", date_validation = '".$this->db->idate(dol_now())."'";
|
|
|
}
|
|
|
- $sql .= " WHERE rowid=".((int) $elementId);
|
|
|
+ $sql .= " WHERE rowid = ".((int) $elementId);
|
|
|
+ $sql .= " AND ".$fieldstatus." <> ".((int) $status); // We avoid update if status already correct
|
|
|
|
|
|
dol_syslog(get_class($this)."::setStatut", LOG_DEBUG);
|
|
|
- if ($this->db->query($sql)) {
|
|
|
+ $resql = $this->db->query($sql);
|
|
|
+ if ($resql) {
|
|
|
$error = 0;
|
|
|
|
|
|
- // Try autoset of trigkey
|
|
|
- if (empty($trigkey)) {
|
|
|
- if ($this->element == 'supplier_proposal' && $status == 2) {
|
|
|
- $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
|
|
|
- }
|
|
|
- if ($this->element == 'supplier_proposal' && $status == 3) {
|
|
|
- $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
|
|
|
- }
|
|
|
- if ($this->element == 'supplier_proposal' && $status == 4) {
|
|
|
- $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
|
|
|
- }
|
|
|
- if ($this->element == 'fichinter' && $status == 3) {
|
|
|
- $trigkey = 'FICHINTER_CLASSIFY_DONE';
|
|
|
- }
|
|
|
- if ($this->element == 'fichinter' && $status == 2) {
|
|
|
- $trigkey = 'FICHINTER_CLASSIFY_BILLED';
|
|
|
- }
|
|
|
- if ($this->element == 'fichinter' && $status == 1) {
|
|
|
- $trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
|
|
|
+ $nb_rows_affected = $this->db->affected_rows($resql); // should be 1 or 0 if status was already correct
|
|
|
+
|
|
|
+ if ($nb_rows_affected >= 0) {
|
|
|
+ if (empty($trigkey)) {
|
|
|
+ // Try to guess trigkey (for backward compatibility, now we should have trigkey defined into the call of setStatus)
|
|
|
+ if ($this->element == 'supplier_proposal' && $status == 2) {
|
|
|
+ $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
|
|
|
+ }
|
|
|
+ if ($this->element == 'supplier_proposal' && $status == 3) {
|
|
|
+ $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
|
|
|
+ }
|
|
|
+ if ($this->element == 'supplier_proposal' && $status == 4) {
|
|
|
+ $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
|
|
|
+ }
|
|
|
+ if ($this->element == 'fichinter' && $status == 3) {
|
|
|
+ $trigkey = 'FICHINTER_CLASSIFY_DONE';
|
|
|
+ }
|
|
|
+ if ($this->element == 'fichinter' && $status == 2) {
|
|
|
+ $trigkey = 'FICHINTER_CLASSIFY_BILLED';
|
|
|
+ }
|
|
|
+ if ($this->element == 'fichinter' && $status == 1) {
|
|
|
+ $trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if ($trigkey) {
|
|
|
- // Call trigger
|
|
|
- $result = $this->call_trigger($trigkey, $user);
|
|
|
- if ($result < 0) {
|
|
|
- $error++;
|
|
|
+ if ($trigkey) {
|
|
|
+ // Call trigger
|
|
|
+ $result = $this->call_trigger($trigkey, $user);
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
+ // End call triggers
|
|
|
}
|
|
|
- // End call triggers
|
|
|
+ } else {
|
|
|
+ // The status was probably already good. We do nothing more, no triggers.
|
|
|
}
|
|
|
|
|
|
if (!$error) {
|