New fetch object class for a certain objecttype for webhook test (#30101)

Co-authored-by: Hystepik <lmarcouiller@nltechno.com>
This commit is contained in:
Lucas Marcouiller 2024-06-22 19:05:03 +02:00 committed by GitHub
parent b89940de75
commit f722ae59c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 10 deletions

View File

@ -12746,6 +12746,13 @@ function getElementProperties($elementType)
$classname = 'Ccountry';
$table_element = 'c_country';
$subelement = '';
} elseif ($elementType == 'knowledgerecord') {
$module = '';
$classpath = 'knowledgemanagement/class';
$classfile = 'knowledgerecord';
$classname = 'KnowledgeRecord';
$table_element = 'knowledgemanagement_knowledgerecord';
$subelement = '';
}
if (empty($classfile)) {

View File

@ -86,11 +86,25 @@ if ($action == "getjsonformtrigger") {
$json->triggercode = empty($objecttriggername[1]) ? $triggercode : $objecttriggername[1];
if (!empty($objecttriggername[1])) {
$objtype = explode("_", $objecttriggername[1])[0];
if (!empty($json->triggercode)) {
$objtype = explode("_", $json->triggercode)[0];
$obj = findobjecttosend($objtype);
if (is_object($obj)) {
//TODO: Case if obj is an object
dol_syslog("Ajax webhook: We clean object fetched");
$properties = dol_get_object_properties($obj);
foreach ($properties as $key => $property) {
if (empty($property)) {
unset($obj->$key);
}
}
unset($obj->db);
unset($obj->fields);
unset($obj->table_element);
unset($obj->picto);
unset($obj->isextrafieldmanaged);
unset($obj->ismultientitymanaged);
$json->object = $obj;
} else {
$objnotfound ++;
}
@ -99,8 +113,8 @@ if ($action == "getjsonformtrigger") {
}
if ($objnotfound) {
dol_syslog("Ajax webhook: Class not found for trigger code ".$json->triggercode);
$json->object = new stdClass();
//$json->object->initAsSpecimen();
$json->object->field1 = 'field1';
$json->object->field2 = 'field2';
$json->object->field3 = 'field3';
@ -119,9 +133,12 @@ if ($action == "getjsonformtrigger") {
*/
function findobjecttosend($objecttype)
{
// TODO: Find right object from objecttype and initAsSpecimen
// You can use fetchObjectByElement()
return false;
dol_syslog("Ajax webhook: We fetch object of type = ".$objecttype." and we init it as specimen");
$obj = fetchObjectByElement(0, dol_strtolower($objecttype));
if (is_object($obj)) {
$obj->initAsSpecimen();
} else {
return false;
}
return $obj;
}

View File

@ -602,7 +602,7 @@ if ($action == "test") {
$.ajax({
method: \'GET\',
url: \''.DOL_URL_ROOT.'/webhook/ajax/webhook.php\',
data: { action: "getjsonformtrigger", triggercode: triggercode },
data: { action: "getjsonformtrigger", triggercode: triggercode , token:"'.currentToken().'"},
success: function(response) {
obj = JSON.stringify(response);
$("#jsondata").val(obj);