diff --git a/inc/process.class.php b/inc/process.class.php index 9555966..5ddb3a2 100644 --- a/inc/process.class.php +++ b/inc/process.class.php @@ -51,7 +51,7 @@ class PluginProcessmakerProcess extends CommonDBTM { //$config = PluginProcessmakerConfig::getInstance() ; //$database = $config->fields['pm_workspace'] ; $translates = false; - $mapLangs = array( ); + $mapLangs = []; // if (class_exists('DropdownTranslation')) { // to force rights to add translations $_SESSION['glpi_dropdowntranslations']['TaskCategory']['name'] = 'name'; @@ -67,8 +67,8 @@ class PluginProcessmakerProcess extends CommonDBTM { $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.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(); + $taskArray = []; + $defaultLangTaskArray = []; foreach ($PM_DB->request( $query ) as $task) { if ($task['CON_LANG'] == $lang) { $defaultLangTaskArray[ $task['TAS_UID'] ][ $task['CON_CATEGORY'] ] = $task['CON_VALUE']; @@ -82,6 +82,7 @@ class PluginProcessmakerProcess extends CommonDBTM { $pmtask = new PluginProcessmakerTaskCategory; $currentasksinprocess = getAllDatasFromTable($pmtask->getTable(), 'is_active = 1 AND processes_id = '.$this->getID()); + $tasks=[]; foreach($currentasksinprocess as $task){ $tasks[$task['pm_task_guid']] = $task; } diff --git a/inc/processmaker.class.php b/inc/processmaker.class.php index 045cecd..7e1e38a 100644 --- a/inc/processmaker.class.php +++ b/inc/processmaker.class.php @@ -931,7 +931,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { * 0 : nothing to do */ static function cronPMTaskActions($task) { - global $DB, $CFG_GLPI, $PM_DB; + global $DB, $PM_DB; if (!isset($PM_DB)) { $PM_DB = new PluginProcessmakerDB; @@ -976,13 +976,13 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { throw new Exception("Can't claim case"); } - $donotif = $CFG_GLPI["use_mailing"]; - $CFG_GLPI["use_mailing"] = false; + // do not send notifications + $donotif = self::saveNotification(false); // now manage tasks associated with item $pm->claimTask( $postdata['APP_UID'], $postdata['DEL_INDEX'], $taskaction['users_id'] ); - $CFG_GLPI["use_mailing"] = $donotif; + self::restoreNotification($donotif); } $myCase = new PluginProcessmakerCase; @@ -1449,27 +1449,24 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { * @return boolean true if added, */ public static function addWatcher( $itemType, $itemId, $techId ) { - global $CFG_GLPI; // currently use $CFG_GLPI to disable notif - //$plug = new Plugin; - if ($techId && $itemType != '' && $itemId > 0) { //!$plug->isActivated('arbehaviours') && + if ($techId && $itemType != '' && $itemId > 0) { $glpi_item = getItemForItemtype( $itemType ); $glpi_item->getFromDB( $itemId ); // then we should check if this user has rights on the item, if not then we must add it to the watcher list! $glpi_item = getItemForItemtype( $itemType ); $glpi_item->getFromDB( $itemId ); - //$user_entities = Profile_User::getUserEntities( $techId, true, true ); - //$user_can_view = in_array( $glpi_item->fields['entities_id'], $user_entities ); if (!$glpi_item->isUser( CommonITILActor::REQUESTER, $techId ) && !$glpi_item->isUser( CommonITILActor::OBSERVER, $techId ) && !$glpi_item->isUser( CommonITILActor::ASSIGN, $techId ) ) { - //&& !$user_can_view ) { + // then we must add this tech user to watcher list $glpi_item_user = getItemForItemtype( $glpi_item->getType() . "_User" ); - $donotif = $CFG_GLPI["use_mailing"]; - $CFG_GLPI["use_mailing"] = false; - $glpi_item_user->add( array( $glpi_item::getForeignKeyField() => $glpi_item->getId(), 'users_id' => $techId, 'type' => CommonITILActor::OBSERVER, '_disablenotif' => true ) ); // , '_no_notif' => true - $CFG_GLPI["use_mailing"]= $donotif; + + // do not send notifications + $donotif = self::saveNotification(false); + $glpi_item_user->add( array( $glpi_item::getForeignKeyField() => $glpi_item->getId(), 'users_id' => $techId, 'type' => CommonITILActor::OBSERVER, '_disablenotif' => true ) ); + self::restoreNotification($donotif); return true; } } @@ -1496,7 +1493,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { * @return */ public function addTask( $itemType, $itemId, $caseInfo, $delIndex, $techId, $groupId, $pmTaskId, $options=array() ) { - global $DB, $PM_DB, $LANG, $CFG_GLPI, $_SESSION; + global $DB, $PM_DB, $LANG, $_SESSION; $default_options = array( 'txtTaskContent' => '', @@ -1610,13 +1607,9 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { $input['groups_id_tech'] = $groups_id_tech; } - $donotif = $CFG_GLPI["use_mailing"]; - if (!$options['notif']) { - //$input['_no_notif'] = true; - $CFG_GLPI["use_mailing"] = false; - } + $donotif = self::saveNotification($options['notif']); $glpi_task->add( Toolbox::addslashes_deep( $input ) ); - $CFG_GLPI["use_mailing"] = $donotif; + self::restoreNotification($donotif); if ($glpi_task->getId() > 0) { // stores link to task in DB @@ -1625,6 +1618,24 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { } } + + private static function saveNotification($donotif) { + global $CFG_GLPI; + // $CFG_GLPI["use_notifications"] is available since 9.2 + $savenotif = isset($CFG_GLPI["use_notifications"]) ? $CFG_GLPI["use_notifications"] : $CFG_GLPI["use_mailing"]; + if (!$donotif) { + isset($CFG_GLPI["use_notifications"]) ? $CFG_GLPI["use_notifications"] = false : $CFG_GLPI["use_mailing"] = false; + } + return $savenotif; + } + + + private static function restoreNotification($savenotif) { + global $CFG_GLPI; + // $CFG_GLPI["use_notifications"] is available since 9.2 + isset($CFG_GLPI["use_notifications"]) ? $CFG_GLPI["use_notifications"] = $savenotif : $CFG_GLPI["use_mailing"] = $savenotif; + } + /** * Summary of add1stTask * adds a GLPI task to ticket @@ -1714,7 +1725,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { * @param mixed $newTech */ public function reassignTask ( $caseId, $delIndex, $newDelIndex, $newTech) { - global $DB, $CFG_GLPI; // $CFG_GLPI is only used to _disablenotif + global $DB; $query = "SELECT * FROM glpi_plugin_processmaker_tasks WHERE case_id='$caseId' and del_index=$delIndex; "; $res = $DB->query($query); @@ -1726,23 +1737,6 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { $itemType = str_replace( 'Task', '', $row['itemtype'] ); $foreignkey = getForeignKeyFieldForItemType( $itemType ); - //$glpi_item = getItemForItemtype( $itemType ); - //$glpi_item->getFromDB( $glpi_task->fields[ getForeignKeyFieldForItemType( $itemType ) ] ) ; - - //$plug = new Plugin; - //if( !$plug->isActivated('arbehaviours') ) { // check is done during Task update in this plugin - // $user_entities = Profile_User::getUserEntities( $newTech, true, true ) ; - // $user_can_view = in_array( $glpi_item->fields['entities_id'], $user_entities ); - // if( !$glpi_item->isUser( CommonITILActor::REQUESTER, $newTech ) && !$glpi_item->isUser( CommonITILActor::OBSERVER, $newTech ) && !$glpi_item->isUser( CommonITILActor::ASSIGN, $newTech ) && !$user_can_view ) { - // // then we must add this tech user to watcher list - // $glpi_item_user = getItemForItemtype( "{$itemType}_User" ); - // $donotif = $CFG_GLPI["use_mailing"] ; - // $CFG_GLPI["use_mailing"] = false; - // $glpi_item_user->add( array( $glpi_item->getForeignKeyField() => $glpi_item->getId() , 'users_id' => $newTech, 'type' => CommonITILActor::OBSERVER ) ) ; // , '_no_notif' => true - // $CFG_GLPI["use_mailing"] = $donotif; - // } - //} - self::addWatcher( $itemType, $glpi_task->fields[ $foreignkey ], $newTech ); $glpi_task->update( array( 'id' => $row['items_id'], $foreignkey => $glpi_task->fields[ $foreignkey ], 'users_id_tech' => $newTech )); @@ -1771,7 +1765,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { * 'users_id_tech' => is the users_id of the tech that solved the task */ public function solveTask( $caseId, $delIndex, $options=array() ) { - global $DB, $CFG_GLPI; + global $DB; // change current glpi_currenttime to be sure that date_mode for solved task will not be identical than date_mode of the newly started task $start_date = new DateTime( $_SESSION["glpi_currenttime"] ); @@ -1812,13 +1806,9 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { 'groups_id_tech' => 0, 'content' => $DB->escape($glpi_task->fields[ 'content' ].$options['txtToAppend']) ); - $donotif = $CFG_GLPI["use_mailing"]; - if (!$options['notif']) { - $CFG_GLPI["use_mailing"] = false; - // $params['_no_notif']=true; - } + $donotif = self::saveNotification($options['notif']); $glpi_task->update( $params ); - $CFG_GLPI["use_mailing"]= $donotif; + self::restoreNotification($donotif); } // restore current glpi time diff --git a/inc/processmakerconfig.class.php b/inc/processmakerconfig.class.php deleted file mode 100644 index 505fa3b..0000000 --- a/inc/processmakerconfig.class.php +++ /dev/null @@ -1,98 +0,0 @@ -addStandardTab(__CLASS__, $ong, $options); - - return $ong; - } - - - function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { - global $LANG, $CFG_GLPI; - - switch ($item->getType()) { - case __CLASS__ : - $tabs[1] = $LANG['common'][12]; - return $tabs; - } - return ''; - } - - - static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { - global $CFG_GLPI; - - if ($item->getType() == __CLASS__) { - switch ($tabnum) { - case 1 : - $item->showFormMailServerConfig(); - break; - } - } - return true; - } - - - /** - * Print the mailing config form - * - * @param $ID integer ID of the item - * @param $options array - * - target filename : where to go when done. - * - tabs integer : ID of the tab to display - * - * @return Nothing (display) - * - **/ - function showForm($ID, $options=array()) { - global $LANG, $CFG_GLPI; - - if (!Session::haveRight("config", UPDATE)) { - return false; - } - if (!$CFG_GLPI['use_mailing']) { - $options['colspan'] = 1; - } - - $this->getFromDB($ID); - $this->showTabs($options); - $this->addDivForTabs(); - return true; - } - - - static function canCreate() { - return Session::haveRight('config', UPDATE); - } - - - static function canView() { - return Session::haveRight('config', READ); - } - - - -} - - diff --git a/processmaker.xml b/processmaker.xml index 1ad4658..09d8f39 100644 --- a/processmaker.xml +++ b/processmaker.xml @@ -23,11 +23,11 @@ - 3.2.1 + 3.2.2 9.2 - 3.2.1 + 3.2.2 9.1 diff --git a/setup.php b/setup.php index e0acfdb..7685bcd 100644 --- a/setup.php +++ b/setup.php @@ -114,7 +114,7 @@ function plugin_version_processmaker() { global $LANG; return array ('name' => 'Process Maker', - 'version' => '3.2.1', + 'version' => '3.2.2', 'author' => 'Olivier Moron', 'homepage' => 'https://github.com/tomolimo/processmaker', 'minGlpiVersion' => '9.1');