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; }
/** * @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); }
/** * @test */ public function PrinterDiscoveryImportDenied() { global $DB; $DB->connect(); $a_inventory = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Brother NC-6400h, Firmware Ver.1.11 (06.12.20),MID 84UZ92', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '10.36.4.29', 'MAC' => '00:80:77:d9:51:c3', 'MANUFACTURER' => 'Brother', 'MODEL' => '', 'MODELSNMP' => 'Printer0442', 'NETBIOSNAME' => 'UH4DLPT01', 'SERIAL' => 'E8J596100A', 'SNMPHOSTNAME' => 'UH4DLPT01', 'TYPE' => 'PRINTER'); $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $printer = new Printer(); $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = 1; $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = '1'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'Printer'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = 0; $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = ''; $pfCommunicationNetworkDiscovery->sendCriteria($a_inventory); $a_printers = $printer->find(); $this->assertEquals(0, count($a_printers), 'May have only one Printer'); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $a_logs = $pfTaskjoblog->find("`comment` LIKE '%importdenied%'", '`id` DESC', 1); $a_log = current($a_logs); $this->assertEquals('==importdenied== [serial]:E8J596100A, ' . '[mac]:00:80:77:d9:51:c3, [ip]:10.36.4.29, [model]:Printer0442, ' . '[name]:UH4DLPT01, [entities_id]:0, [itemtype]:Printer', $a_log['comment'], 'Import denied message'); }
/** * Purge taskjoblog/state when delete taskjob * * @param type $parm * * @return nothing */ static function purgeTaskjob($parm) { // $parm["id"] $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); // all taskjobs $a_taskjobstates = $pfTaskjobstate->find("`plugin_fusioninventory_taskjobs_id`='" . $parm->fields["id"] . "'"); foreach ($a_taskjobstates as $a_taskjobstate) { $a_taskjoblogs = $pfTaskjoblog->find("`plugin_fusioninventory_taskjobstates_id`='" . $a_taskjobstate['id'] . "'"); foreach ($a_taskjoblogs as $a_taskjoblog) { $pfTaskjoblog->delete($a_taskjoblog, 1); } $pfTaskjobstate->delete($a_taskjobstate, 1); } }
function display($options = array()) { global $DB, $CFG_GLPI; $pfAgent = new PluginFusioninventoryAgent(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfStateInventory = new PluginFusioninventoryStateInventory(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $start = 0; if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } // Total Number of events $querycount = "SELECT count(*) AS cpt FROM `glpi_plugin_fusioninventory_taskjobstates`\n LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n WHERE `method` = 'networkdiscovery'\n GROUP BY `uniqid`\n ORDER BY `uniqid` DESC "; $resultcount = $DB->query($querycount); $number = $DB->numrows($resultcount); // Display the pager Html::printPager($start, $number, $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/stateinventory.php", ''); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Unique id', 'fusioninventory') . "</th>"; echo "<th>" . __('Task job', 'fusioninventory') . "</th>"; echo "<th>" . __('Agent', 'fusioninventory') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Starting date', 'fusioninventory') . "</th>"; echo "<th>" . __('Ending date', 'fusioninventory') . "</th>"; echo "<th>" . __('Total duration') . "</th>"; echo "<th>" . __('Threads number', 'fusioninventory') . "</th>"; echo "<th>" . __('Total discovery devices', 'fusioninventory') . "</th>"; echo "<th>" . __('Devices not imported', 'fusioninventory') . "</th>"; echo "<th>" . __('Devices linked', 'fusioninventory') . "</th>"; echo "<th>" . __('Devices imported', 'fusioninventory') . "</th>"; echo "</tr>"; $sql = "SELECT `glpi_plugin_fusioninventory_taskjobstates`.*\n FROM `glpi_plugin_fusioninventory_taskjobstates`\n LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n WHERE `method` = 'networkdiscovery'\n GROUP BY `uniqid`\n ORDER BY `uniqid` DESC\n LIMIT " . intval($start) . ", " . intval($_SESSION['glpilist_limit']); $result = $DB->query($sql); while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1'>"; echo "<td>" . $data['uniqid'] . "</td>"; $pfTaskjob->getFromDB($data['plugin_fusioninventory_taskjobs_id']); echo "<td>" . $pfTaskjob->getLink() . "</td>"; $pfAgent->getFromDB($data['plugin_fusioninventory_agents_id']); echo "<td>" . $pfAgent->getLink(1) . "</td>"; $nb_found = 0; $nb_threads = 0; $start_date = ""; $end_date = ""; $notimporteddevices = 0; $updateddevices = 0; $createddevices = 0; $a_taskjobstates = $pfTaskjobstate->find("`uniqid`='" . $data['uniqid'] . "'"); foreach ($a_taskjobstates as $datastate) { $a_taskjoblog = $pfTaskjoblog->find("`plugin_fusioninventory_taskjobstates_id`='" . $datastate['id'] . "'"); foreach ($a_taskjoblog as $taskjoblog) { if (strstr($taskjoblog['comment'], " ==devicesfound==")) { $nb_found += str_replace(" ==devicesfound==", "", $taskjoblog['comment']); } else { if (strstr($taskjoblog['comment'], "==importdenied==")) { $notimporteddevices++; } else { if (strstr($taskjoblog['comment'], "==updatetheitem==")) { $updateddevices++; } else { if (strstr($taskjoblog['comment'], "==addtheitem==")) { $createddevices++; } else { if ($taskjoblog['state'] == "1") { $nb_threads = str_replace(" threads", "", $taskjoblog['comment']); $start_date = $taskjoblog['date']; } } } } } if ($taskjoblog['state'] == "2" or $taskjoblog['state'] == "3" or $taskjoblog['state'] == "4" or $taskjoblog['state'] == "5") { if (!strstr($taskjoblog['comment'], 'Merged with ')) { $end_date = $taskjoblog['date']; } } } } // State echo "<td>"; switch ($data['state']) { case 0: echo __('Prepared', 'fusioninventory'); break; case 1: case 2: echo __('Started', 'fusioninventory'); break; case 3: echo __('Finished tasks', 'fusioninventory'); break; } echo "</td>"; echo "<td>" . Html::convDateTime($start_date) . "</td>"; echo "<td>" . Html::convDateTime($end_date) . "</td>"; if ($end_date == '') { $end_date = date("Y-m-d H:i:s"); } if ($start_date == '') { echo "<td>-</td>"; } else { $interval = ''; if (phpversion() >= 5.3) { $date1 = new DateTime($start_date); $date2 = new DateTime($end_date); $interval = $date1->diff($date2); $display_date = ''; if ($interval->h > 0) { $display_date .= $interval->h . "h "; } else { if ($interval->i > 0) { $display_date .= $interval->i . "min "; } } echo "<td>" . $display_date . $interval->s . "s</td>"; } else { $interval = $pfStateInventory->date_diff($start_date, $end_date); } } echo "<td>" . $nb_threads . "</td>"; echo "<td>" . $nb_found . "</td>"; echo "<td>" . $notimporteddevices . "</td>"; echo "<td>" . $updateddevices . "</td>"; echo "<td>" . $createddevices . "</td>"; echo "</tr>"; } echo "</table>"; }