From e38788dfd15090e7a0da99e7b1a465f357cbb528 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 24 Oct 2017 16:30:53 +0200 Subject: [PATCH] Added a flag on tasks to be able to view active tasks Added task deletion when they are not yet used and are deleted from PM Fixed also issue on quote for process main taskcategory Fixed issue GATEWAYTOGATEWAY: no longer import these as if they were tasks --- hook.php | 7 +++++ inc/process.class.php | 63 +++++++++++++++++++++++++++++++++++--- inc/taskcategory.class.php | 41 +++++++++++++++++++------ locales/en_GB.php | 1 + locales/fr_FR.php | 1 + 5 files changed, 98 insertions(+), 15 deletions(-) diff --git a/hook.php b/hook.php index 5b5e575..367c8af 100644 --- a/hook.php +++ b/hook.php @@ -331,6 +331,7 @@ function plugin_processmaker_install() { `pm_task_guid` VARCHAR(32) NOT NULL, `taskcategories_id` INT(11) NOT NULL, `start` BIT(1) NOT NULL DEFAULT b'0', + `is_active` TINYINT(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE INDEX `pm_task_guid` (`pm_task_guid`), UNIQUE INDEX `items` (`taskcategories_id`), @@ -342,8 +343,14 @@ function plugin_processmaker_install() { "; $DB->query($query) or die("error creating glpi_plugin_processmaker_taskcategories" . $DB->error()); + } + if (!FieldExists('glpi_plugin_processmaker_taskcategories', 'is_active')) { + $query = "ALTER TABLE `glpi_plugin_processmaker_taskcategories` + ADD COLUMN `is_active` TINYINT(1) NOT NULL DEFAULT '1' AFTER `start`;" ; + $DB->query($query) or die("error adding field is_active to glpi_plugin_processmaker_taskcategories table" . $DB->error()); } + if (!$DB->TableExists("glpi_plugin_processmaker_crontaskactions")) { $query = "CREATE TABLE `glpi_plugin_processmaker_crontaskactions` ( diff --git a/inc/process.class.php b/inc/process.class.php index 2232017..26b5005 100644 --- a/inc/process.class.php +++ b/inc/process.class.php @@ -70,7 +70,7 @@ class PluginProcessmakerProcess extends CommonDBTM { $lang = locale_get_primary_language( $CFG_GLPI['language'] ); $query = "SELECT TASK.TAS_UID, TASK.TAS_START, CONTENT.CON_LANG, CONTENT.CON_CATEGORY, CONTENT.CON_VALUE FROM TASK INNER JOIN CONTENT ON CONTENT.CON_ID=TASK.TAS_UID - WHERE TASK.PRO_UID = '".$this->fields['process_guid']."' AND CONTENT.CON_CATEGORY IN ('TAS_TITLE', 'TAS_DESCRIPTION') ".($translates ? "" : " AND CONTENT.CON_LANG='$lang'")." ;"; + WHERE TASK.TAS_TYPE = 'NORMAL' AND TASK.PRO_UID = '".$this->fields['process_guid']."' AND CONTENT.CON_CATEGORY IN ('TAS_TITLE', 'TAS_DESCRIPTION') ".($translates ? "" : " AND CONTENT.CON_LANG='$lang'")." ;"; $taskArray = array(); $defaultLangTaskArray=array(); foreach ($PM_DB->request( $query ) as $task) { @@ -84,6 +84,33 @@ class PluginProcessmakerProcess extends CommonDBTM { } } + $pmtask = new PluginProcessmakerTaskCategory; + $currentasksinprocess = getAllDatasFromTable($pmtask->getTable(), 'is_active = 1 AND processes_id = '.$this->getID()); + foreach($currentasksinprocess as $task){ + $tasks[$task['pm_task_guid']] = $task; + } + $inactivetasks = array_diff_key($tasks, $defaultLangTaskArray); + foreach($inactivetasks as $taskkey => $task) { + // must verify if this taskcategory are used in a task somewhere + $objs = ['TicketTask', 'ProblemTask', 'ChangeTask']; + $countElt = 0 ; + foreach($objs as $obj) { + $countElt += countElementsInTable( getTableForItemType($obj), "taskcategories_id = ".$task['taskcategories_id'] ); + if ($countElt != 0) { + // just set 'is_active' to 0 + $pmtask->Update( array( 'id' => $task['id'], 'start' => 0, 'is_active' => 0 ) ); + break; + } + } + if ($countElt == 0) { + // purge this category as it is not used anywhere + $taskCat = new TaskCategory; + $taskCat->delete(array( 'id' => $task['taskcategories_id'] ), 1); + $pmTaskCat = new PluginProcessmakerTaskCategory; + $pmTaskCat->delete(array( 'id' => $task['id'] ), 1); + } + } + foreach ($defaultLangTaskArray as $taskGUID => $task) { $pmTaskCat = new PluginProcessmakerTaskCategory; $taskCat = new TaskCategory; @@ -108,7 +135,7 @@ class PluginProcessmakerProcess extends CommonDBTM { // taskcat must be created $taskCat->add( array( 'is_recursive' => true, 'name' => $PM_DB->escape($task['TAS_TITLE']), 'comment' => $PM_DB->escape($task['TAS_DESCRIPTION']), 'taskcategories_id' => $this->fields['taskcategories_id'] ) ); // pmTaskCat must be created too - $pmTaskCat->add( array( 'processes_id' => $this->getID(), 'pm_task_guid' => $taskGUID, 'taskcategories_id' => $taskCat->getID(), 'start' => $task['start'] ) ); + $pmTaskCat->add( array( 'processes_id' => $this->getID(), 'pm_task_guid' => $taskGUID, 'taskcategories_id' => $taskCat->getID(), 'start' => $task['start'], 'is_active' => 1 ) ); } // here we should take into account translations if any if ($translates && isset($taskArray[ $taskGUID ])) { @@ -150,6 +177,30 @@ class PluginProcessmakerProcess extends CommonDBTM { } + function prepareInputForAdd($input){ + global $PM_DB; + if (isset($input['name'])) { + $input['name'] = $PM_DB->escape($input['name']); + } + return $input; + } + + function prepareInputForUpdate($input){ + global $PM_DB; + if (isset($input['name'])) { + $input['name'] = $PM_DB->escape($input['name']); + } + return $input; + } + + function post_addItem() { + $this->getFromDB($this->getID()); + } + + function post_updateItem($history = 1) { + $this->getFromDB($this->getID()); + } + /** * Summary of refresh * used to refresh process list and task category list @@ -171,7 +222,7 @@ class PluginProcessmakerProcess extends CommonDBTM { if ($glpiprocess->getFromDBbyExternalID($process->guid)) { // then update it only if name has changed if ($glpiprocess->fields['name'] != $process->name) { - $glpiprocess->update( array( 'id' => $glpiprocess->getID(), 'name' => $process->name ) ); + $glpiprocess->update( array( 'id' => $glpiprocess->getID(), 'name' => $process->name) ); } // and check if main task category needs update if (!$glpiprocess->fields['taskcategories_id']) { @@ -207,9 +258,10 @@ class PluginProcessmakerProcess extends CommonDBTM { * @return boolean true if update is done, false otherwise */ function updateTaskCategory( $pmMainTaskCat ) { + global $PM_DB; $taskCat = new TaskCategory; if ($taskCat->getFromDB( $this->fields['taskcategories_id'] ) && $taskCat->fields['name'] != $this->fields['name']) { - return $taskCat->update( array( 'id' => $taskCat->getID(), 'taskcategories_id' => $pmMainTaskCat, 'name' => $this->fields['name'] ) ); + return $taskCat->update( array( 'id' => $taskCat->getID(), 'taskcategories_id' => $pmMainTaskCat, 'name' => $PM_DB->escape($this->fields['name'])) ); } return false; } @@ -221,8 +273,9 @@ class PluginProcessmakerProcess extends CommonDBTM { * @return boolean true if TaskCategory has been created and updated into $this process, else otherwise */ function addTaskCategory( $pmMainTaskCat ) { + global $PM_DB; $taskCat = new TaskCategory; - if ($taskCat->add( array( 'is_recursive' => true, 'taskcategories_id' => $pmMainTaskCat, 'name' => $this->fields['name']) )) { + if ($taskCat->add( array( 'is_recursive' => true, 'taskcategories_id' => $pmMainTaskCat, 'name' => $PM_DB->escape($this->fields['name'])) )) { return $this->update( array( 'id' => $this->getID(), 'taskcategories_id' => $taskCat->getID() ) ); } return false; diff --git a/inc/taskcategory.class.php b/inc/taskcategory.class.php index b055610..cfbaf04 100644 --- a/inc/taskcategory.class.php +++ b/inc/taskcategory.class.php @@ -25,33 +25,54 @@ class PluginProcessmakerTaskCategory extends CommonDBTM static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { - global $LANG, $DB; + global $LANG, $DB, $CFG_GLPI; self::title($item); echo "

"; - echo ""; + echo ""; echo "". "" . - "" . "" . - ""; + "" . + "" . + "" . + ""; - $query = "SELECT pm.pm_task_guid, pm.taskcategories_id, pm.`start`, gl.name, gl.completename, gl.`comment` FROM glpi_plugin_processmaker_taskcategories AS pm + $query = "SELECT pm.pm_task_guid, pm.taskcategories_id, pm.`start`, gl.name, gl.completename, gl.`comment`, pm.is_active FROM glpi_plugin_processmaker_taskcategories AS pm LEFT JOIN glpi_taskcategories AS gl ON pm.taskcategories_id=gl.id WHERE pm.processes_id=".$item->getID().";"; foreach ($DB->request($query) as $taskCat) { - echo " - ". - ""; + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; } echo "
".$LANG['processmaker']['title'][3]."
".$LANG['processmaker']['title'][3]."
".$LANG['processmaker']['process']['taskcategories']['name']."".$LANG['processmaker']['process']['taskcategories']['completename']."".$LANG['processmaker']['process']['taskcategories']['guid']."".$LANG['processmaker']['process']['taskcategories']['start']."".$LANG['processmaker']['process']['taskcategories']['comment']."
".$LANG['processmaker']['process']['taskcategories']['guid']."".$LANG['processmaker']['process']['taskcategories']['comment']."".$LANG['processmaker']['process']['taskcategories']['is_active']."
"; + + echo "".str_replace(" ", " ", $taskCat['name']); if ($_SESSION["glpiis_ids_visible"]) { echo " (".$taskCat['taskcategories_id'].")"; } - echo "".str_replace(" ", " ", $taskCat['completename'])."".$taskCat['pm_task_guid']."".($taskCat['start']?'x':'')."". - $taskCat['comment']."
".str_replace(" ", " ", $taskCat['completename']).""; + if ($taskCat['start']) { + echo "\""."; + } + echo "".$taskCat['pm_task_guid']."".$taskCat['comment'].""; + if ($taskCat['is_active']) { + echo "\""."; + } + echo "
"; diff --git a/locales/en_GB.php b/locales/en_GB.php index 283b4bd..8121d55 100644 --- a/locales/en_GB.php +++ b/locales/en_GB.php @@ -25,6 +25,7 @@ $LANG['processmaker']['process']['taskcategories']['name']="Task name"; $LANG['processmaker']['process']['taskcategories']['completename']="Complete name"; $LANG['processmaker']['process']['taskcategories']['start']="Start"; $LANG['processmaker']['process']['taskcategories']['comment']="Comment"; +$LANG['processmaker']['process']['taskcategories']['is_active']="Active"; $LANG['processmaker']['process']['profile']="Delete permanently"; $LANG['processmaker']['config']['name']="Name"; diff --git a/locales/fr_FR.php b/locales/fr_FR.php index 13cf940..9acde7c 100644 --- a/locales/fr_FR.php +++ b/locales/fr_FR.php @@ -25,6 +25,7 @@ $LANG['processmaker']['process']['taskcategories']['name']="Nom de la Tâche"; $LANG['processmaker']['process']['taskcategories']['completename']="Nom complet"; $LANG['processmaker']['process']['taskcategories']['start']="Début"; $LANG['processmaker']['process']['taskcategories']['comment']="Commentaire"; +$LANG['processmaker']['process']['taskcategories']['is_active']="Active"; $LANG['processmaker']['process']['profile']="Effacer définitivement"; $LANG['processmaker']['config']['name']="Nom";