dolibarr icon indicating copy to clipboard operation
dolibarr copied to clipboard

REST API PUT `/contacts/{id}`: `update` called with notrigger = 1

Open atm-florianm opened this issue 9 months ago • 0 comments

Bug

Currently, the API endpoint for contact update bypasses triggers (notrigger = 1).

The same is true for some other PUT endpoints (~~thirdparty for instance~~), but not all (contract, BOM, proposal, anything made with ModuleBuilder, etc.).

[edit] I was wrong about thirdparty because Societe::update's 3rd parameter is $call_trigger and not $notrigger as is usually the case. So the 3rd parameter is 1 but it does call the trigger. If the endpoint PUT /contacts/{id} was copy-pasted from the third party API, it could explain this issue because this detail is easy to overlook (I'm a good example of that).

I assume this is on purpose, but I can't find the reason why, and it is inconsinstent (why notrigger for updating and not for creating, why some objects and not others).

We are developing a feature using triggers to change information whenever a contact is created or updated, but because of this notrigger, we can't make it work in APIs.

Dolibarr Version

17.0, 18.0, 19.0, develop, …

Environment PHP

any

Environment Database

No response

Steps to reproduce the behavior and expected behavior

  1. Implement triggers CONTACT_MODIFY and CONTACT_CREATE (let's say they both do the same: they concatenate "elloworld" to the lastname of the contact)
  2. create a contact with lastname "h" using Dolibarr interface →OK, its name is "helloworld"
  3. edit the contact with lastname "h" using Dolibarr interface → OK, its name is "helloworld"
  4. create a contact with lastname "h" using Dolibarr API POST /contacts → OK, its name is "helloworld"
  5. update a contact with lastname "h"using Dolibarr API PUT /contacts/{id} → KO (its is still "h")

Attached files

No response

atm-florianm avatar May 03 '24 07:05 atm-florianm