Skip to content

Commit

Permalink
New add new status to webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Hystepik committed Oct 3, 2024
1 parent 916423f commit 086bbb8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$target_url = $static_object->fetchAll();
foreach ($target_url as $key => $tmpobject) {
$actionarray = explode(",", $tmpobject->trigger_codes);
if ($tmpobject->status == Target::STATUS_VALIDATED && is_array($actionarray) && in_array($action, $actionarray)) {
if ($tmpobject->status == Target::STATUS_AUTOMATIC_TRIGGER && is_array($actionarray) && in_array($action, $actionarray)) {
// Build the answer object
$resobject = new stdClass();
$resobject->triggercode = $action;
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/admin.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,8 @@ TriggerDisabledByName=Triggers in this file are disabled by the <b>-NORUN</b> su
TriggerDisabledAsModuleDisabled=Triggers in this file are disabled as module <b>%s</b> is disabled.
TriggerAlwaysActive=Triggers in this file are always active, whatever are the activated Dolibarr modules.
TriggerActiveAsModuleActive=Triggers in this file are active as module <b>%s</b> is enabled.
AutomaticTrigger=Automatic trigger
ManualTrigger=Manual trigger
GeneratedPasswordDesc=Choose the method to be used for auto-generated passwords.
DictionaryDesc=Insert all reference data. You can add your values to the default.
ConstDesc=This page allows you to edit (override) parameters not available in other pages. These are mostly reserved parameters for developers/advanced troubleshooting only.
Expand Down
29 changes: 18 additions & 11 deletions htdocs/webhook/class/target.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Target extends CommonObject

const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1;
const STATUS_AUTOMATIC_TRIGGER = 1;
const STATUS_MANUAL_TRIGGER = 2;
const STATUS_CANCELED = 9;


Expand Down Expand Up @@ -106,7 +108,7 @@ class Target extends CommonObject
'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'default' => '1', 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Disabled', '1' => 'Enabled'), 'validate' => 1,),
'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'default' => '1', 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Disabled', '1' => 'AutomaticTrigger', '2' => 'ManualTrigger'), 'validate' => 1,),
);
public $rowid;
public $ref;
Expand Down Expand Up @@ -524,7 +526,7 @@ public function validate($user, $notrigger = 0)
$error = 0;

// Protection
if ($this->status == self::STATUS_VALIDATED) {
if ($this->status == self::STATUS_AUTOMATIC_TRIGGER) {
dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
return 0;
}
Expand All @@ -545,7 +547,7 @@ public function validate($user, $notrigger = 0)
// Validate
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET ref = '".$this->db->escape($num)."',";
$sql .= " status = ".self::STATUS_VALIDATED;
$sql .= " status = ".self::STATUS_AUTOMATIC_TRIGGER;
if (!empty($this->fields['date_validation'])) {
$sql .= ", date_validation = '".$this->db->idate($now)."'";
}
Expand Down Expand Up @@ -620,7 +622,7 @@ public function validate($user, $notrigger = 0)
// Set new ref and current status
if (!$error) {
$this->ref = $num;
$this->status = self::STATUS_VALIDATED;
$this->status = self::STATUS_AUTOMATIC_TRIGGER;
}

if (!$error) {
Expand Down Expand Up @@ -660,7 +662,7 @@ public function setDraft($user, $notrigger = 0)
public function cancel($user, $notrigger = 0)
{
// Protection
if ($this->status != self::STATUS_VALIDATED) {
if ($this->status != self::STATUS_AUTOMATIC_TRIGGER) {
return 0;
}

Expand All @@ -681,7 +683,7 @@ public function reopen($user, $notrigger = 0)
return 0;
}

return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'TARGET_REOPEN');
return $this->setStatusCommon($user, self::STATUS_AUTOMATIC_TRIGGER, $notrigger, 'TARGET_REOPEN');
}

/**
Expand Down Expand Up @@ -835,16 +837,21 @@ public function LibStatut($status, $mode = 0)
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;

$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled');
$this->labelStatus[self::STATUS_AUTOMATIC_TRIGGER] = $langs->transnoentitiesnoconv('AutomaticTrigger');
$this->labelStatus[self::STATUS_MANUAL_TRIGGER] = $langs->transnoentitiesnoconv('ManualTrigger');
$this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled');
$this->labelStatusShort[self::STATUS_AUTOMATIC_TRIGGER] = $langs->transnoentitiesnoconv('AutomaticTrigger');
$this->labelStatusShort[self::STATUS_MANUAL_TRIGGER] = $langs->transnoentitiesnoconv('ManualTrigger');
$this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
}

$statusType = 'status'.$status;
if ($status == self::STATUS_VALIDATED) {
if ($status == self::STATUS_AUTOMATIC_TRIGGER) {
$statusType = 'status4';
}
if ($status == self::STATUS_MANUAL_TRIGGER) {
$statusType = 'status4';
}
if ($status == self::STATUS_CANCELED) {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/webhook/target_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@
}

// Disable
if ($object->status == $object::STATUS_VALIDATED) {
if (in_array($object->status, array($object::STATUS_AUTOMATIC_TRIGGER, $object::STATUS_MANUAL_TRIGGER))) {
print dolGetButtonAction('', $langs->trans('Disable'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
}

Expand Down

0 comments on commit 086bbb8

Please sign in to comment.