34require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
49 parent::__construct($db);
50 $this->family =
"demo";
52 $this->version = self::VERSIONS[
'dev'];
53 $this->picto =
'webhook';
69 if (empty($conf->webhook) || empty($conf->webhook->enabled)) {
72 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
77 $static_object =
new Target($this->db);
78 $target_url = $static_object->fetchAll();
79 foreach ($target_url as $key => $tmpobject) {
80 $actionarray = explode(
",", $tmpobject->trigger_codes);
81 if ($tmpobject->status == Target::STATUS_VALIDATED && is_array($actionarray) && in_array($action, $actionarray)) {
84 $resobject->triggercode = $action;
87 if (property_exists($resobject->object,
'fields')) {
88 unset($resobject->object->fields);
90 if (property_exists($resobject->object,
'error')) {
91 unset($resobject->object->error);
93 if (property_exists($resobject->object,
'errors')) {
94 unset($resobject->object->errors);
97 $jsonstr = json_encode($resobject);
100 'Content-Type: application/json'
106 $method =
'POSTALREADYFORMATED';
108 $response =
getURLContent($tmpobject->url, $method, $jsonstr, 1, $headers, array(
'http',
'https'), 2, -1);
110 if (empty($response[
'curl_error_no']) && $response[
'http_code'] >= 200 && $response[
'http_code'] < 300) {
114 $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'] :
"");
115 $this->errors[] = $errormsg;
123 if (!empty($errors)) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to stock current configuration.
Class that all triggers must inherit.
Class of triggers for Webhook module.
__construct($db)
Constructor.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
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 =...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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).