public function submitForm($postvars) { if (isset($postvars['forcestart'])) { Session::checkRight('plugin_fusioninventory_task', UPDATE); /** * TODO: forcing the task execution should be done in the task object */ $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjob->forceRunningTask($postvars['id']); Html::back(); } else { if (isset($postvars["add"])) { Session::checkRight('plugin_fusioninventory_task', CREATE); $items_id = $this->add($postvars); Html::redirect(str_replace("add=1", "", $_SERVER['HTTP_REFERER']) . "?id=" . $items_id); } else { if (isset($postvars["purge"])) { Session::checkRight('plugin_fusioninventory_task', PURGE); $pfTaskJob = new PluginFusioninventoryTaskjob(); $taskjobs = $pfTaskJob->find("`plugin_fusioninventory_tasks_id` = '" . $postvars['id'] . "' "); foreach ($taskjobs as $taskjob) { $pfTaskJob->delete($taskjob); } $this->delete($postvars); Html::redirect(Toolbox::getItemTypeSearchURL(get_class($this))); } else { if (isset($_POST["update"])) { Session::checkRight('plugin_fusioninventory_task', UPDATE); $this->getFromDB($postvars['id']); //Ensure empty value are set to NULL for datetime fields if (isset($postvars['datetime_start']) and $postvars['datetime_start'] === '') { $postvars['datetime_start'] = 'NULL'; } if (isset($postvars['datetime_end']) and $postvars['datetime_end'] === '') { $postvars['datetime_end'] = 'NULL'; } $this->update($postvars); Html::back(); } } } } }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { $pfTask = new self(); $pfTaskjob = new PluginFusioninventoryTaskjob(); switch ($ma->getAction()) { case "transfert": foreach ($ids as $key) { if ($pfTask->getFromDB($key)) { $a_taskjobs = $pfTaskjob->find("`plugin_fusioninventory_tasks_id`='" . $key . "'"); foreach ($a_taskjobs as $data1) { $input = array(); $input['id'] = $data1['id']; $input['entities_id'] = $_POST['entities_id']; $pfTaskjob->update($input); } $input = array(); $input['id'] = $key; $input['entities_id'] = $_POST['entities_id']; if ($pfTask->update($input)) { //set action massive ok for this item $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { // KO $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } break; case 'target_task': $taskjob = new PluginFusioninventoryTaskjob(); $tasks = array(); // prepare base insertion $input = array('plugin_fusioninventory_tasks_id' => $ma->POST['tasks_id'], 'entities_id' => 0, 'name' => 'deploy', 'method' => 'deployinstall', 'targets' => '[{"PluginFusioninventoryDeployPackage":"' . $ma->POST['packages_id'] . '"}]', 'actor' => array()); if (array_key_exists('separate_jobs', $_POST)) { foreach ($ids as $key) { $input['actors'] = '[{"Computer":"' . $key . '"}]'; if ($pfTaskjob->add($input)) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } else { foreach ($ids as $key) { $input['actors'][] = array('Computer' => $key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } $input['actors'] = json_encode($input['actors']); $pfTaskjob->add($input); } break; } }
if (!isset($_POST["id"])) { exit; } if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $pfTask = new PluginFusioninventoryTask(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $a_taskjob = $pfTaskjob->find("`plugin_fusioninventory_tasks_id`='" . $_POST["id"] . "'\n AND `rescheduled_taskjob_id`='0' ", "id"); $i = 1; switch ($_POST['glpi_tab']) { case -1: foreach ($a_taskjob as $taskjob_id => $datas) { $pfTaskjob->showForm($taskjob_id); $pfTaskjoblog->showHistory($taskjob_id); $taskjob_id_next = $taskjob_id; for ($j = 2; $j > 1; $j++) { $a_taskjobreties = $pfTaskjob->find("`rescheduled_taskjob_id`='" . $taskjob_id_next . "' ", "", 1); if (!empty($a_taskjobreties)) { foreach ($a_taskjobreties as $taskjob_id_next => $datas2) { $pfTaskjob->showForm($taskjob_id_next); } } else { $j = 0;
function pre_deleteItem() { global $CFG_GLPI; //if task active, delete denied if ($this->getField('is_active') == 1) { Session::addMessageAfterRedirect(__('This task is active. delete denied', 'fusioninventory')); Html::redirect($CFG_GLPI["root_doc"] . "/plugins/fusinvdeploy/front/task.form.php?id=" . $this->getField('id')); return FALSE; } $task_id = $this->getField('id'); $job = new PluginFusioninventoryTaskjob(); $status = new PluginFusioninventoryTaskjobstate(); $log = new PluginFusioninventoryTaskjoblog(); // clean all sub-tables $a_taskjobs = $job->find("`plugin_fusioninventory_tasks_id`='{$task_id}'"); foreach ($a_taskjobs as $a_taskjob) { $a_taskjobstatuss = $status->find("`plugin_fusioninventory_taskjobs_id`='" . $a_taskjob['id'] . "'"); foreach ($a_taskjobstatuss as $a_taskjobstatus) { $a_taskjoblogs = $log->find("`plugin_fusioninventory_taskjobstates_id`='" . $a_taskjobstatus['id'] . "'"); foreach ($a_taskjoblogs as $a_taskjoblog) { $log->delete($a_taskjoblog, 1); } $status->delete($a_taskjobstatus, 1); } $job->delete($a_taskjob, 1); } return TRUE; }
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($tabnum == 'task') { $pfTask = new PluginFusioninventoryTask(); $pfTask->showJobLogs(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $a_taskjobs = $pfTaskjob->find('`targets` LIKE \'%"PluginFusioninventoryIPRange":"' . $item->getID() . '"%\''); foreach ($a_taskjobs as $data) { //$pfTask->getFromDB($data['plugin_fusioninventory_tasks_id']); } } }
/** * @test */ public function deleteTask() { global $DB; $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjobState = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); //delete task $return = $pfTask->delete(array('id' => self::$tasks_id)); $this->assertEquals(true, $return); //check deletion of job $jobs_found = $pfTaskjob->find("id = " . self::$taskjobs_id); $this->assertEquals(array(), $jobs_found); //check deletion of state $states_found = $pfTaskjobState->find("id = " . self::$taskjobstates_id); $this->assertEquals(array(), $states_found); //check deletion of log $logs_found = $pfTaskjoblog->find("id = " . self::$taskjobstates_id); $this->assertEquals(array(), $logs_found); }
static function quickList($method) { $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTask = new PluginFusioninventoryTask(); $a_list = $pfTaskjob->find("`method`='" . $method . "'"); echo "<table class='tab_cadrehov' style='width:950px'>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Active') . "</th>"; echo "<th>" . __('Scheduled date', 'fusioninventory') . "</th>"; echo "<th>" . __('Periodicity', 'fusioninventory') . "</th>"; echo "<th>" . __('Definition', 'fusioninventory') . "</td>"; echo "<th>" . __('Action', 'fusioninventory') . "</th>"; echo "</tr>"; foreach ($a_list as $data) { $pfTaskjob->getFromDB($data['id']); $pfTask->getFromDB($data['plugin_fusioninventory_tasks_id']); echo "<tr class='tab_bg_1'>"; $link_item = $pfTaskjob->getFormURL(); $link = $link_item; $link .= (strpos($link, '?') ? '&' : '?') . 'id=' . $pfTaskjob->fields['id']; echo "<td><a href='" . $link . "'>" . $pfTaskjob->getNameID(1) . "</a></td>"; echo "<td>" . Dropdown::getYesNo($pfTask->fields['is_active']) . "</td>"; echo "<td>" . $pfTask->fields['datetime_start'] . "</td>"; $a_time = ''; switch ($pfTask->fields['periodicity_type']) { case 'minutes': $a_time = $pfTask->fields['periodicity_count'] . " " . strtolower(__('Minute(s)', 'fusioninventory')); break; case 'hours': $a_time = $pfTask->fields['periodicity_count'] . " " . strtolower(__('hour(s)', 'fusioninventory')); break; case 'days': $a_time = $pfTask->fields['periodicity_count'] . " " . __('day(s)', 'fusioninventory'); break; case 'months': $a_time = $pfTask->fields['periodicity_count'] . " " . __('months'); break; } echo "<td>" . $a_time . "</td>"; $a_defs = importArrayFromDB($data['definition']); echo "<td>"; foreach ($a_defs as $datadef) { foreach ($datadef as $itemtype => $items_id) { $class = new $itemtype(); $class->getFromDB($items_id); echo $class->getLink(1) . " (" . $class->getTypeName() . ")<br/>"; } } echo "</td>"; echo "<td>"; $a_acts = importArrayFromDB($data['action']); foreach ($a_acts as $dataact) { foreach ($dataact as $itemtype => $items_id) { $class = new $itemtype(); $itemname = $class->getTypeName(); $class->getFromDB($items_id); $name = ''; if ($items_id == '.1') { $name = __('Auto managenement dynamic of agents', 'fusioninventory'); } else { if ($items_id == '.2') { $name = __('Auto managenement dynamic of agents (same subnet)', 'fusioninventory'); } else { $name = $class->getLink(1); } } echo $name . ' (' . $itemname . ')<br/>'; } } echo "</td>"; echo "</tr>"; } echo "</table>"; }
$computerId = $_POST['host_id']; if (!isset($_POST['host_name'])) { $_SESSION["MESSAGE_AFTER_REDIRECT"] = __('Missing computer name in parameters !', 'monitoring'); Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php"); } $computerName = $_POST['host_name']; $agent = new PluginFusioninventoryAgent(); $fusionAgentId = $agent->getAgentWithComputerid($computerId); // Get FusionInventory task associated with host command ... if (!isset($_POST['host_command'])) { $_SESSION["MESSAGE_AFTER_REDIRECT"] = __('Missing host command in parameters !', 'monitoring'); Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php"); } $host_command = $_POST['host_command']; $pfTaskjob = new PluginFusioninventoryTaskjob(); $a_lists = $pfTaskjob->find("name LIKE '{$host_command}'", '', 1); if (count($a_lists) == 0) { $_SESSION["MESSAGE_AFTER_REDIRECT"] = __('Host command task not found : ', 'monitoring') . $host_command; Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php"); } $a_list = current($a_lists); $taskjob_id = $a_list['id']; $definition = importArrayFromDB($a_list['definition']); /* Pour les valeurs : $query = "INSERT INTO `glpi_plugin_fusioninventory_taskjobstates` (`plugin_fusioninventory_taskjobs_id`, `items_id`, `itemtype`, `state`, `plugin_fusioninventory_agents_id`, `uniqid`) VALUES ('0', '0', 'PluginFusioninventoryDeployPackage', '0', '0', '".uniqid()."')"; '0', => l'id du job dans glpi_plugin_fusioninventory_taskjobs (fixe a chaque exécution) '0', => l'id du package 'PluginFusioninventoryDeployPackage',