Skip to content

Commit eeac86f

Browse files
authored
Merge pull request #146 from tomolimo/4.0/bugfixes
Fixed add solution that was not compliant with GLPI9.5
2 parents 3ba25a6 + e5ccb43 commit eeac86f

9 files changed

+378
-316
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ version 3.6.x is compatible with GLPI 9.4 and needs ProcessMaker 3.3.0-RE-1.x (h
1010

1111
version 4.0.x is compatible with GLPI 9.5 and needs ProcessMaker 3.3.0-RE-1.x (https://github.com/tomolimo/processmaker-server/releases/latest)
1212

13-
This plugin can run classic and bpmn processes
13+
This plugin can run classic (ProcessMaker server v2) and BPMN (ProcessMaker server v3 and later) processes
1414

15-
An IRC channel is available: #processmaker-glpi on https://webchat.freenode.net/

hook.php

+46-22
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function plugin_pre_item_update_processmaker(CommonITILObject $parm) {
127127
//global $DB;//, $PM_SOAP;
128128

129129
// look at previous status
130-
if (isset($parm->input['status'])
130+
if (isset($parm->input['status'])
131131
&& $parm->input['status'] == CommonITILObject::SOLVED
132132
&& !in_array($parm->fields['status'], [CommonITILObject::SOLVED, CommonITILObject::CLOSED])
133133
&& !PluginProcessmakerCase::canSolve(['item' => $parm])) {
@@ -194,7 +194,7 @@ function plugin_item_update_processmaker_satisfaction($parm) {
194194
global $PM_SOAP;
195195
if (Session::isCron()) { // Task cron log with user admin
196196
$PM_SOAP->login(true);
197-
}
197+
}
198198
$cases = PluginProcessmakerCase::getIDsFromItem('Ticket', $parm->fields['tickets_id']);
199199
foreach ($cases as $cases_id) {
200200
$locCase = new PluginProcessmakerCase;
@@ -282,7 +282,6 @@ function plugin_item_update_processmaker_tasks($parm) {
282282
$locCase = new PluginProcessmakerCase;
283283
$locCase->getFromDB($pmTask->fields['plugin_processmaker_cases_id']);
284284
$srccase_guid = $locCase->fields['case_guid'];
285-
286285
//$msg = Toolbox::backtrace(false);
287286
//$msg .= ' $locCase: '.str_replace("\n", "\n ", print_r($locCase, true))."\n";
288287
//$msg .= ' $task: '.str_replace("\n", "\n ", print_r($parm, true))."\n";
@@ -320,25 +319,34 @@ function plugin_item_update_processmaker_tasks($parm) {
320319
$casevariables = array_merge( $casevariables, $matches[1] );
321320
}
322321
}
322+
if (preg_match_all( "/@@(\w+)/u", $externalapplication['url'], $matches )) {
323+
$casevariables = array_merge( $casevariables, $matches[1] );
324+
}
325+
if(isset($externalapplication['headers']) && $externalapplication['headers'] != "") {
326+
if (preg_match_all( "/@@(\w+)/u", $externalapplication['headers'], $matches )) {
327+
$casevariables = array_merge( $casevariables, $matches[1] );
328+
}
329+
}
330+
323331
}
324332

325333
// ask for those case variables
326334
//$PM_SOAP = new PluginProcessmakerProcessmaker();
327335
//$PM_SOAP->login( );
328336
// now tries to get the variables to check condition
329337
$infoForTasks = $locCase->getVariables($casevariables);
338+
$infoForURL = [];
330339
foreach ($infoForTasks as $casevar => $varval) {
331340
$infoForTasks[ "@@$casevar" ] = "'$varval'";
341+
$infoForURL[ "@@$casevar" ] = $varval;
332342
unset( $infoForTasks[ $casevar ] );
333343
}
334344

335345
//$msg .= " ***********\n";
336346
//$msg .= ' $targetTask: '.str_replace("\n", "\n ", print_r($targetTask, true))."\n";
337347

338348
$targetTask['sourcecondition'] = str_replace( array_keys($infoForTasks), $infoForTasks, $targetTask['sourcecondition'] );
339-
340349
$eval = eval( "return (".$targetTask['sourcecondition']." ? 1 : 0);" );
341-
342350
//$msg .= ' $infoForTasks: '.str_replace("\n", "\n ", print_r($infoForTasks, true))."\n";
343351
//$msg .= ' $targetTask[\'sourcecondition\']: '.str_replace("\n", "\n ", print_r($targetTask['sourcecondition'], true))."\n";
344352
//$msg .= ' $result: '."$eval\n";
@@ -366,7 +374,8 @@ function plugin_item_update_processmaker_tasks($parm) {
366374
}
367375
$externalapplicationparams['callback'] = $CFG_GLPI["url_base"]."/plugins/processmaker/ajax/asynchronousdatas.php";
368376
$ch = curl_init();
369-
$externalapplication['url'] = eval( "return '".str_replace( array_keys($infoForTasks), $infoForTasks, $externalapplication['url'])."' ;" ); // '???
377+
378+
$externalapplication['url'] = str_replace( array_keys($infoForURL), $infoForURL, $externalapplication['url']);
370379
curl_setopt($ch, CURLOPT_URL, $externalapplication['url'] );
371380
if (isset($externalapplication['method']) && $externalapplication['method'] == 'POST') {
372381
curl_setopt($ch, CURLOPT_POST, 1);
@@ -391,18 +400,17 @@ function plugin_item_update_processmaker_tasks($parm) {
391400
$pmconfig = $PM_SOAP->config; //PluginProcessmakerConfig::getInstance();
392401

393402
$cronaction = new PluginProcessmakerCrontaskaction;
394-
$cronaction->add( [ 'plugin_processmaker_caselinks_id' => $targetTask['id'],
395-
'plugin_processmaker_cases_id' => $locCase->getID(),
396-
//'itemtype' => $itemtype,
397-
//'items_id' => $parm->fields['tickets_id'],
398-
'users_id' => $pmconfig->fields['users_id'],
399-
'is_targettoclaim' => $targetTask['is_targettoclaim'],
400-
'state' => ($targetTask['is_externaldata'] ? PluginProcessmakerCrontaskaction::WAITING_DATA : PluginProcessmakerCrontaskaction::DATA_READY),
401-
'postdata' => json_encode( $postdata, JSON_HEX_APOS | JSON_HEX_QUOT),
402-
'logs_out' => json_encode( $externalapplicationparams, JSON_HEX_APOS | JSON_HEX_QUOT)
403-
],
404-
null,
405-
false);
403+
$cronaction->add([
404+
'plugin_processmaker_caselinks_id' => $targetTask['id'],
405+
'plugin_processmaker_cases_id' => $locCase->getID(),
406+
//'itemtype' => $itemtype,
407+
//'items_id' => $parm->fields['tickets_id'],
408+
'users_id' => $pmconfig->fields['users_id'],
409+
'is_targettoclaim' => $targetTask['is_targettoclaim'],
410+
'state' => ($targetTask['is_externaldata'] ? PluginProcessmakerCrontaskaction::WAITING_DATA : PluginProcessmakerCrontaskaction::DATA_READY),
411+
'postdata' => json_encode( $postdata, JSON_HEX_APOS | JSON_HEX_QUOT),
412+
'logs_out' => json_encode( $externalapplicationparams, JSON_HEX_APOS | JSON_HEX_QUOT)
413+
], [], false);
406414

407415
if ($externalapplication) {
408416
// must call external application in order to get the needed data asynchroneously
@@ -415,12 +423,26 @@ function plugin_item_update_processmaker_tasks($parm) {
415423
$externalapplicationparams = json_encode( $externalapplicationparams, JSON_HEX_APOS | JSON_HEX_QUOT);
416424

417425
curl_setopt($ch, CURLOPT_POSTFIELDS, $externalapplicationparams);
418-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: ' . strlen($externalapplicationparams), 'Expect:']);
426+
$headers = [
427+
'Content-Type: application/json',
428+
'Content-Length: ' . strlen($externalapplicationparams),
429+
'Expect:'];
430+
if(isset($externalapplication['headers']) && $externalapplication['headers'] != "") {
431+
$externalapplication['headers'] = eval( "return ".str_replace( array_keys($infoForTasks), $infoForTasks, $externalapplication['headers'])." ;" ); // '???
432+
//Can't add an assoicative array in curlopt_httpheader
433+
foreach($externalapplication['headers'] as $key => $h) {
434+
array_push($headers, $key.": ".$h);
435+
}
436+
}
437+
//$headers = array_merge($headers, $externalapplication['headers']);
438+
439+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
419440
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
420441
curl_setopt($ch, CURLOPT_VERBOSE, 1);
421442

422-
if (isset($externalapplication['ssl_verify'])) {
423-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $externalapplication['ssl_verify']);
443+
if (isset($externalapplication['ssl_verify']) && $externalapplication['ssl_verify'] > 0) {
444+
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $externalapplication['ssl_verify']);
445+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
424446
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $externalapplication['ssl_verify']);
425447
}
426448

@@ -432,7 +454,9 @@ function plugin_item_update_processmaker_tasks($parm) {
432454
$response = curl_exec ($ch);
433455
if ($response === false) {
434456
//throw new Exception(curl_error($ch), curl_errno($ch));
435-
Toolbox::logDebug( curl_error($ch).":".curl_errno($ch) );
457+
Toolbox::logDebug(curl_error($ch) . ":" . curl_errno($ch));
458+
// Set 0 to the crontask action status
459+
$cronaction->update(['id ' => $cronaction->getID(), 'state' => PluginProcessmakerCrontaskaction::CURL_ERROR]);
436460
}
437461

438462
curl_close ($ch);

inc/crontaskaction.class.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
<?php
2-
3-
/**
4-
* PluginProcessmakerCrontaskaction is used to manage actions between cases
5-
*
6-
* Allows actions: routing cases (called slaves) from another case (called master)
7-
*
8-
*
9-
* @version 1.0
10-
* @author MoronO
11-
*/
12-
class PluginProcessmakerCrontaskaction extends CommonDBTM {
13-
14-
// postdata are of the form:
15-
// {"form":{"RELEASE_DONE":"0","btnGLPISendRequest":"submit"},"UID":"28421020557bffc5b374850018853291","__DynaformName__":"51126098657bd96b286ded7016691792_28421020557bffc5b374850018853291","__notValidateThisFields__":"[]","DynaformRequiredFields":"[]","APP_UID":"6077575685836f7d89cabe6013770123","DEL_INDEX":"4"}
16-
17-
18-
const WAITING_DATA = 1;
19-
const DATA_READY = 2;
20-
const DONE = 3;
21-
const NOT_DONE = 4;
22-
23-
}
1+
<?php
2+
3+
/**
4+
* PluginProcessmakerCrontaskaction is used to manage actions between cases
5+
*
6+
* Allows actions: routing cases (called slaves) from another case (called master)
7+
*
8+
*
9+
* @version 1.0
10+
* @author MoronO
11+
*/
12+
class PluginProcessmakerCrontaskaction extends CommonDBTM {
13+
14+
// postdata are of the form:
15+
// {"form":{"RELEASE_DONE":"0","btnGLPISendRequest":"submit"},"UID":"28421020557bffc5b374850018853291","__DynaformName__":"51126098657bd96b286ded7016691792_28421020557bffc5b374850018853291","__notValidateThisFields__":"[]","DynaformRequiredFields":"[]","APP_UID":"6077575685836f7d89cabe6013770123","DEL_INDEX":"4"}
16+
17+
const CURL_ERROR = 0;
18+
const WAITING_DATA = 1;
19+
const DATA_READY = 2;
20+
const DONE = 3;
21+
const NOT_DONE = 4;
22+
23+
}

inc/process.class.php

+53-23
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ function maybeDeleted() {
4545
}
4646

4747

48-
// static function getIcon() {
49-
//// return "fas fa-code-branch fa-rotate-90";
50-
// return "fas fa-blog fa-flip-vertical";
51-
//// return "fas fa-cogs fa-flip-vertical";
48+
// static function getIcon() {
49+
//// return "fas fa-code-branch fa-rotate-90";
50+
// return "fas fa-blog fa-flip-vertical";
51+
//// return "fas fa-cogs fa-flip-vertical";
5252
// }
5353

5454

@@ -151,16 +151,16 @@ function refreshTasks($post) {
151151
$countElt += $dbu->countElementsInTable( $dbu->getTableForItemType($obj), "taskcategories_id = ".$task['taskcategories_id'] );
152152
if ($countElt != 0) {
153153
// just set 'is_active' to 0
154-
$pmtask->Update( [ 'id' => $task['id'], 'is_start' => 0, 'is_active' => 0 ] );
154+
$pmtask->Update(['id' => $task['id'], 'is_start' => 0, 'is_active' => 0]);
155155
break;
156156
}
157157
}
158158
if ($countElt == 0) {
159159
// purge this category as it is not used anywhere
160160
$taskCat = new TaskCategory;
161-
$taskCat->delete([ 'id' => $task['taskcategories_id'] ], 1);
161+
$taskCat->delete(['id' => $task['taskcategories_id']], 1);
162162
$pmTaskCat = new PluginProcessmakerTaskCategory;
163-
$pmTaskCat->delete([ 'id' => $task['id'] ], 1);
163+
$pmTaskCat->delete(['id' => $task['id']], 1);
164164
}
165165
}
166166

@@ -169,32 +169,52 @@ function refreshTasks($post) {
169169
$taskCat = new TaskCategory;
170170
if ($pmTaskCat->getFromGUID( $taskGUID )) {
171171
// got it then check names, and if != update
172-
if ($taskCat->getFromDB( $pmTaskCat->fields['taskcategories_id'] )) {
172+
if ($taskCat->getFromDB($pmTaskCat->fields['taskcategories_id'])) {
173173
// found it must test if should be updated
174-
if ($taskCat->fields['name'] != $task['TAS_TITLE'] || $taskCat->fields['comment'] != $task['TAS_DESCRIPTION']) {
175-
$taskCat->update( [ 'id' => $taskCat->getID(), 'name' => $PM_DB->escape($task['TAS_TITLE']), 'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']), 'taskcategories_id' => $this->fields['taskcategories_id'] ] );
174+
if ($taskCat->fields['name'] != $task['TAS_TITLE']
175+
|| $taskCat->fields['comment'] != $task['TAS_DESCRIPTION']) {
176+
$taskCat->update([
177+
'id' => $taskCat->getID(),
178+
'name' => $PM_DB->escape($task['TAS_TITLE']),
179+
'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']),
180+
'taskcategories_id' => $this->fields['taskcategories_id'],
181+
'is_active' => 0 // to prevent use of this task cat in manual tasks
182+
] );
176183
}
177184
if ($pmTaskCat->fields['is_start'] != $task['is_start']) {
178-
$pmTaskCat->update( [ 'id' => $pmTaskCat->getID(), 'is_start' => $task['is_start'] ] );
185+
$pmTaskCat->update(['id' => $pmTaskCat->getID(), 'is_start' => $task['is_start']]);
179186
}
180187
} else {
181188
// taskcat must be created
182-
$taskCat->add( [ 'is_recursive' => true, 'name' => $PM_DB->escape($task['TAS_TITLE']), 'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']), 'taskcategories_id' => $this->fields['taskcategories_id'] ] );
189+
$taskCat->add([
190+
'is_recursive' => true,
191+
'name' => $PM_DB->escape($task['TAS_TITLE']),
192+
'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']),
193+
'taskcategories_id' => $this->fields['taskcategories_id'],
194+
'is_active' => 0 // to prevent use of this task cat in manual tasks
195+
] );
183196
// update pmTaskCat
184-
$pmTaskCat->update( [ 'id' => $pmTaskCat->getID(), 'taskcategories_id' => $taskCat->getID(), 'is_start' => $task['is_start'] ] );
197+
$pmTaskCat->update(['id' => $pmTaskCat->getID(), 'taskcategories_id' => $taskCat->getID(), 'is_start' => $task['is_start']]);
185198
}
186199
} else {
187200
// should create a new one
188201
// taskcat must be created
189-
$taskCat->add( [ 'is_recursive' => true, 'name' => $PM_DB->escape($task['TAS_TITLE']), 'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']), 'taskcategories_id' => $this->fields['taskcategories_id'] ] );
202+
$taskCat->add([
203+
'is_recursive' => true,
204+
'name' => $PM_DB->escape($task['TAS_TITLE']),
205+
'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']),
206+
'taskcategories_id' => $this->fields['taskcategories_id'],
207+
'is_active' => 0 // to prevent use of this task cat in manual tasks
208+
] );
190209
// pmTaskCat must be created too
191-
$pmTaskCat->add( ['plugin_processmaker_processes_id' => $this->getID(),
192-
'pm_task_guid' => $taskGUID,
193-
'taskcategories_id' => $taskCat->getID(),
194-
'is_start' => $task['is_start'],
195-
'is_active' => 1,
196-
'is_subprocess' => $task['is_subprocess']
197-
] );
210+
$pmTaskCat->add([
211+
'plugin_processmaker_processes_id' => $this->getID(),
212+
'pm_task_guid' => $taskGUID,
213+
'taskcategories_id' => $taskCat->getID(),
214+
'is_start' => $task['is_start'],
215+
'is_active' => 1,
216+
'is_subprocess' => $task['is_subprocess']
217+
]);
198218
}
199219
// here we should take into account translations if any
200220
if (isset($taskArray[ $taskGUID ])) {
@@ -371,7 +391,12 @@ function updateTaskCategory($pmMainTaskCat) {
371391
global $PM_DB;
372392
$taskCat = new TaskCategory;
373393
if ($taskCat->getFromDB( $this->fields['taskcategories_id'] ) && $taskCat->fields['name'] != $this->fields['name']) {
374-
return $taskCat->update( [ 'id' => $taskCat->getID(), 'taskcategories_id' => $pmMainTaskCat, 'name' => $PM_DB->escape($this->fields['name'])] );
394+
return $taskCat->update([
395+
'id' => $taskCat->getID(),
396+
'taskcategories_id' => $pmMainTaskCat,
397+
'name' => $PM_DB->escape($this->fields['name']),
398+
'is_active' => 0 // to prevent use of this task cat in a manual task
399+
] );
375400
}
376401
return false;
377402
}
@@ -385,7 +410,12 @@ function updateTaskCategory($pmMainTaskCat) {
385410
function addTaskCategory($pmMainTaskCat) {
386411
global $PM_DB;
387412
$taskCat = new TaskCategory;
388-
if ($taskCat->add( [ 'is_recursive' => true, 'taskcategories_id' => $pmMainTaskCat, 'name' => $PM_DB->escape($this->fields['name'])] )) {
413+
if ($taskCat->add([
414+
'is_recursive' => true,
415+
'taskcategories_id' => $pmMainTaskCat,
416+
'name' => $PM_DB->escape($this->fields['name']),
417+
'is_active' => 0 // to prevent use of this task cat in a manual task
418+
])) {
389419
return $this->update( [ 'id' => $this->getID(), 'taskcategories_id' => $taskCat->getID() ] );
390420
}
391421
return false;

0 commit comments

Comments
 (0)