33require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
50 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
51 $this->family =
"demo";
54 $this->version =
'development';
55 $this->picto =
'webhook';
75 return $this->description;
93 if (empty($conf->webhook) || empty($conf->webhook->enabled)) {
96 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
101 $static_object =
new Target($this->db);
102 $target_url = $static_object->fetchAll();
103 foreach ($target_url as $key => $tmpobject) {
104 $actionarray = explode(
",", $tmpobject->trigger_codes);
105 if (is_array($actionarray) && in_array($action, $actionarray)) {
108 $resobject->triggercode = $action;
109 $resobject->object =
dol_clone($object, 2);
111 if (property_exists($resobject->object,
'fields')) {
112 unset($resobject->object->fields);
114 if (property_exists($resobject->object,
'error')) {
115 unset($resobject->object->error);
117 if (property_exists($resobject->object,
'errors')) {
118 unset($resobject->object->errors);
121 $jsonstr = json_encode($resobject);
124 'Content-Type: application/json'
128 $response =
getURLContent($tmpobject->url,
'POST', $jsonstr, 1, $headers, array(
'http',
'https'), 2, -1);
129 if (empty($response[
'curl_error_no']) && $response[
'http_code'] >= 200 && $response[
'http_code'] < 300) {
133 $errormsg =
"The WebHook for ".$action.
" failed to get URL ".$tmpobject->url.
" with httpcode=".(!empty($response[
'http_code']) ? $response[
'http_code'] :
"").
" curl_error_no=".(!empty($response[
'curl_error_no']) ? $response[
'curl_error_no'] :
"");
134 $this->errors[] = $errormsg;
142 if (!empty($errors)) {
Class to stock current configuration.
Class that all the triggers must extend.
Class of triggers for Webhook module.
__construct($db)
Constructor.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
getDesc()
Trigger description.
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_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.