24require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
41 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
42 $this->family =
"technic";
45 $this->version = self::VERSION_DEVELOPMENT;
46 $this->picto =
'zapier';
63 if (empty($conf->zapier) || empty($conf->zapier->enabled)) {
68 $logtriggeraction =
false;
71 $actions = explode(
'_', $action);
72 $sql =
'SELECT rowid, url FROM '.MAIN_DB_PREFIX.
'zapier_hook';
73 $sql .=
' WHERE module="'.$this->db->escape(strtolower($actions[0])).
'" AND action="'.$this->db->escape(strtolower($actions[1])).
'"';
80 $resql = $this->db->query($sql);
82 while ($resql && $obj = $this->db->fetch_array($resql)) {
83 $cleaned = cleanObjectDatas(
dol_clone($object));
84 $json = json_encode($cleaned);
86 zapierPostWebhook($obj[
'url'], $json);
88 $logtriggeraction =
true;
91 $resql = $this->db->query($sql);
93 while ($resql && $obj = $this->db->fetch_array($resql)) {
94 $cleaned = cleanObjectDatas(
dol_clone($object));
95 $json = json_encode($cleaned);
97 zapierPostWebhook($obj[
'url'], $json);
99 $logtriggeraction =
true;
109 case 'ACTION_MODIFY':
112 case 'ACTION_CREATE':
113 $resql = $this->db->query($sql);
115 while ($resql && $obj = $this->db->fetch_array($resql)) {
116 $cleaned = cleanObjectDatas(
dol_clone($object));
117 $cleaned = cleanAgendaEventsDatas($cleaned);
118 $json = json_encode($cleaned);
120 zapierPostWebhook($obj[
'url'], $json);
123 $logtriggeraction =
true;
125 case 'ACTION_DELETE':
141 case 'COMPANY_CREATE':
142 $resql = $this->db->query($sql);
143 while ($resql && $obj = $this->db->fetch_array($resql)) {
144 $cleaned = cleanObjectDatas(
dol_clone($object));
145 $json = json_encode($cleaned);
147 zapierPostWebhook($obj[
'url'], $json);
149 $logtriggeraction =
true;
151 case 'COMPANY_MODIFY':
152 $resql = $this->db->query($sql);
153 while ($resql && $obj = $this->db->fetch_array($resql)) {
154 $cleaned = cleanObjectDatas(
dol_clone($object));
155 $json = json_encode($cleaned);
157 zapierPostWebhook($obj[
'url'], $json);
159 $logtriggeraction =
true;
161 case 'COMPANY_DELETE':
166 case 'CONTACT_CREATE':
167 $resql = $this->db->query($sql);
168 while ($resql && $obj = $this->db->fetch_array($resql)) {
169 $cleaned = cleanObjectDatas(
dol_clone($object));
170 $json = json_encode($cleaned);
172 zapierPostWebhook($obj[
'url'], $json);
174 $logtriggeraction =
true;
176 case 'CONTACT_MODIFY':
177 $resql = $this->db->query($sql);
178 while ($resql && $obj = $this->db->fetch_array($resql)) {
179 $cleaned = cleanObjectDatas(
dol_clone($object));
180 $json = json_encode($cleaned);
182 zapierPostWebhook($obj[
'url'], $json);
184 $logtriggeraction =
true;
186 case 'CONTACT_DELETE':
188 case 'CONTACT_ENABLEDISABLE':
208 $resql = $this->db->query($sql);
209 while ($resql && $obj = $this->db->fetch_array($resql)) {
210 $cleaned = cleanObjectDatas(
dol_clone($object));
211 $json = json_encode($cleaned);
213 zapierPostWebhook($obj[
'url'], $json);
215 $logtriggeraction =
true;
219 case 'ORDER_VALIDATE':
223 case 'ORDER_SENTBYMAIL':
224 case 'ORDER_CLASSIFY_BILLED':
225 case 'ORDER_SETDRAFT':
226 case 'LINEORDER_INSERT':
227 case 'LINEORDER_UPDATE':
228 case 'LINEORDER_DELETE':
332 case 'MEMBER_CREATE':
333 $resql = $this->db->query($sql);
334 while ($resql && $obj = $this->db->fetch_array($resql)) {
335 $cleaned = cleanObjectDatas(
dol_clone($object));
336 $json = json_encode($cleaned);
338 zapierPostWebhook($obj[
'url'], $json);
340 $logtriggeraction =
true;
342 case 'MEMBER_MODIFY':
343 $resql = $this->db->query($sql);
344 while ($resql && $obj = $this->db->fetch_array($resql)) {
345 $cleaned = cleanObjectDatas(
dol_clone($object));
346 $json = json_encode($cleaned);
348 zapierPostWebhook($obj[
'url'], $json);
350 $logtriggeraction =
true;
372 case 'TICKET_CREATE':
373 $resql = $this->db->query($sql);
375 while ($resql && $obj = $this->db->fetch_array($resql)) {
376 $cleaned = cleanObjectDatas(
dol_clone($object));
377 $json = json_encode($cleaned);
379 zapierPostWebhook($obj[
'url'], $json);
381 $logtriggeraction =
true;
398 if ($logtriggeraction) {
399 dol_syslog(
"Trigger '".$this->
name.
"' for action '".$action.
"' launched by ".__FILE__.
" id=".$object->id);
411function zapierPostWebhook($url, $json)
413 $headers = array(
'Accept: application/json',
'Content-Type: application/json');
418 getURLContent($url,
'POSTALREADYFORMATED', $json, 1, $headers, array(
'http',
'https'), 0);
441function cleanObjectDatas($toclean)
447 unset($toclean->linkedObjects);
449 unset($toclean->lines);
451 unset($toclean->fields);
453 unset($toclean->oldline);
455 unset($toclean->error);
456 unset($toclean->errors);
458 unset($toclean->ref_previous);
459 unset($toclean->ref_next);
461 unset($toclean->projet);
462 unset($toclean->project);
463 unset($toclean->author);
464 unset($toclean->timespent_old_duration);
465 unset($toclean->timespent_id);
466 unset($toclean->timespent_duration);
467 unset($toclean->timespent_date);
468 unset($toclean->timespent_datehour);
469 unset($toclean->timespent_withhour);
470 unset($toclean->timespent_fk_user);
471 unset($toclean->timespent_note);
473 unset($toclean->statuts);
474 unset($toclean->statuts_short);
475 unset($toclean->statuts_logo);
476 unset($toclean->statuts_long);
478 unset($toclean->element);
479 unset($toclean->fk_element);
480 unset($toclean->table_element);
481 unset($toclean->table_element_line);
482 unset($toclean->picto);
484 unset($toclean->skip_update_total);
485 unset($toclean->context);
496 unset($toclean->oldcopy);
499 if (isset($toclean->lines) && count($toclean->lines) > 0) {
500 $nboflines = count($toclean->lines);
501 for ($i = 0; $i < $nboflines; $i++) {
502 cleanObjectDatas($toclean->lines[$i]);
525function cleanAgendaEventsDatas($toclean)
527 unset($toclean->usermod);
528 unset($toclean->libelle);
530 unset($toclean->context);
531 unset($toclean->canvas);
532 unset($toclean->contact);
533 unset($toclean->contact_id);
534 unset($toclean->thirdparty);
535 unset($toclean->user);
536 unset($toclean->origin);
537 unset($toclean->origin_id);
538 unset($toclean->ref_ext);
539 unset($toclean->statut);
540 unset($toclean->country);
541 unset($toclean->country_id);
542 unset($toclean->country_code);
543 unset($toclean->barcode_type);
544 unset($toclean->barcode_type_code);
545 unset($toclean->barcode_type_label);
546 unset($toclean->barcode_type_coder);
547 unset($toclean->mode_reglement_id);
548 unset($toclean->cond_reglement_id);
549 unset($toclean->cond_reglement);
550 unset($toclean->fk_delivery_address);
551 unset($toclean->shipping_method_id);
552 unset($toclean->fk_account);
553 unset($toclean->total_ht);
554 unset($toclean->total_tva);
555 unset($toclean->total_localtax1);
556 unset($toclean->total_localtax2);
557 unset($toclean->total_ttc);
558 unset($toclean->fk_incoterms);
559 unset($toclean->libelle_incoterms);
560 unset($toclean->location_incoterms);
561 unset($toclean->name);
562 unset($toclean->lastname);
563 unset($toclean->firstname);
564 unset($toclean->civility_id);
565 unset($toclean->contact);
566 unset($toclean->societe);
Class to stock current configuration.
Class that all the triggers must extend.
Class of triggers for Zapier module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
__construct($db)
Constructor.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
$conf db name
Only used if Module[ID]Name translation string is not found.