/** * Cron for ticketsatisfaction's automatic generated * * @param $task : crontask object * * @return integer (0 : nothing done - 1 : done) **/ static function cronCreateInquest($task) { global $DB; $conf = new Entity(); $inquest = new TicketSatisfaction(); $tot = 0; $maxentity = array(); $tabentities = array(); $rate = Entity::getUsedConfig('inquest_config', 0, 'inquest_rate'); if ($rate > 0) { $tabentities[0] = $rate; } foreach ($DB->request('glpi_entities') as $entity) { $rate = Entity::getUsedConfig('inquest_config', $entity['id'], 'inquest_rate'); $parent = Entity::getUsedConfig('inquest_config', $entity['id'], 'entities_id'); if ($rate > 0) { $tabentities[$entity['id']] = $rate; } } foreach ($tabentities as $entity => $rate) { $parent = Entity::getUsedConfig('inquest_config', $entity, 'entities_id'); $delay = Entity::getUsedConfig('inquest_config', $entity, 'inquest_delay'); $duration = Entity::getUsedConfig('inquest_config', $entity, 'inquest_duration'); $type = Entity::getUsedConfig('inquest_config', $entity); $max_closedate = Entity::getUsedConfig('inquest_config', $entity, 'max_closedate'); $query = "SELECT `glpi_tickets`.`id`,\n `glpi_tickets`.`closedate`,\n `glpi_tickets`.`entities_id`\n FROM `glpi_tickets`\n LEFT JOIN `glpi_ticketsatisfactions`\n ON `glpi_ticketsatisfactions`.`tickets_id` = `glpi_tickets`.`id`\n LEFT JOIN `glpi_entities`\n ON `glpi_tickets`.`entities_id` = `glpi_entities`.`id`\n WHERE `glpi_tickets`.`entities_id` = '{$entity}'\n AND `glpi_tickets`.`is_deleted` = 0\n AND `glpi_tickets`.`status` = '" . self::CLOSED . "'\n AND `glpi_tickets`.`closedate` > '{$max_closedate}'\n AND ADDDATE(`glpi_tickets`.`closedate`, INTERVAL {$delay} DAY)<=NOW()\n AND ADDDATE(`glpi_entities`.`max_closedate`, INTERVAL {$duration} DAY)<=NOW()\n AND `glpi_ticketsatisfactions`.`id` IS NULL\n ORDER BY `closedate` ASC"; $nb = 0; $max_closedate = ''; foreach ($DB->request($query) as $tick) { $max_closedate = $tick['closedate']; if (mt_rand(1, 100) <= $rate) { if ($inquest->add(array('tickets_id' => $tick['id'], 'date_begin' => $_SESSION["glpi_currenttime"], 'entities_id' => $tick['entities_id'], 'type' => $type))) { $nb++; } } } // conservation de toutes les max_closedate des entites filles if (!empty($max_closedate) && (!isset($maxentity[$parent]) || $max_closedate > $maxentity[$parent])) { $maxentity[$parent] = $max_closedate; } if ($nb) { $tot += $nb; $task->addVolume($nb); $task->log(sprintf(__('%1$s: %2$s'), Dropdown::getDropdownName('glpi_entities', $entity), $nb)); } } // Sauvegarde du max_closedate pour ne pas tester les même tickets 2 fois foreach ($maxentity as $parent => $maxdate) { $conf->getFromDB($parent); $conf->update(array('id' => $conf->fields['id'], 'max_closedate' => $maxdate)); } return $tot > 0; }
/** Generate bigdump : add tickets to an item * * @param $type item type * @param $ID item ID * @param $ID_entity entity ID **/ function addTracking($type, $ID, $ID_entity) { global $percent, $DB, $MAX, $FIRST, $LAST; $current_year = date("Y"); while (mt_rand(0,100)<$percent['tracking_on_item']) { // ticket closed ? $status = CommonITILObject::CLOSED; $closedate = ""; $solvedate = ""; $opendate = time() - mt_rand(0, 365)*DAY_TIMESTAMP - mt_rand(0, 10)*HOUR_TIMESTAMP - mt_rand(0, 60)*MINUTE_TIMESTAMP - mt_rand(0, 60); if (mt_rand(0,100)<$percent['closed_tracking']) { $rtype = mt_rand(0, 100); if ($rtype<20) { $status = CommonITILObject::SOLVED; } else { $status = CommonITILObject::CLOSED; } } else { $rtype = mt_rand(0, 100); if ($rtype<20) { $status = CommonITILObject::INCOMING; } else if ($rtype<40) { $status = CommonITILObject::WAITING; } else if ($rtype<80) { $status = CommonITILObject::PLANNED; $date3 = $opendate+mt_rand(10800, 7776000); // + entre 3 heures et 3 mois $date4 = $date3+10800; // + 3 heures } else { $status = CommonITILObject::ASSIGNED; } } // Author $users[0] = mt_rand($FIRST['users_normal'], $LAST['users_postonly']); // Assign user $users[1] = 0; if ($status != CommonITILObject::INCOMING) { $users[1] = mt_rand($FIRST['users_sadmin'], $LAST['users_admin']); } $enterprise = 0; if (mt_rand(0,100)<20) { $enterprise = mt_rand($FIRST["enterprises"], $LAST['enterprises']); } $firstactiontime = mt_rand(0, 10)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP +mt_rand(0, 60)*MINUTE_TIMESTAMP; $solvetime = 0; $closetime = 0; $actiontime = 0; $solution = ""; $solutiontype = 0; $due_date = $opendate + $firstactiontime+mt_rand(0, 10)*DAY_TIMESTAMP+ mt_rand(0, 10)*HOUR_TIMESTAMP+mt_rand(0, 60)*MINUTE_TIMESTAMP; $duedatetoadd = date("Y-m-d H:i:s", intval($due_date)); if (($status == CommonITILObject::CLOSED) || ($status == CommonITILObject::SOLVED)) { $solvetime = $firstactiontime+mt_rand(0, 10)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP+ mt_rand(0, 60)*MINUTE_TIMESTAMP; $solvedate = $opendate+$solvetime; $closedate = $opendate+$solvetime; $actiontime = mt_rand(0, 10)*HOUR_TIMESTAMP+ mt_rand(0, 60)*MINUTE_TIMESTAMP; if ($status == CommonITILObject::CLOSED) { $closetime = $solvetime+mt_rand(0, 5)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP+ mt_rand(0, 60)*MINUTE_TIMESTAMP; $closedate = $opendate+$closetime; } $solutiontype = mt_rand($FIRST['solutiontypes'], $LAST['solutiontypes']); $solution = "Solution '".Toolbox::getRandomString(20); } $updatedate = $opendate+max($firstactiontime, $solvetime, $closetime); $hour_cost = 100; $closedatetoadd = 'NULL'; if (!empty($closedate)) { $closedatetoadd = date("Y-m-d H:i:s", intval($closedate)); } $solvedatetoadd = 'NULL'; if (!empty($solvedate)) { $solvedatetoadd = date("Y-m-d H:i:s",intval($solvedate)); } $t = new Ticket(); $tID = $t->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "Title '".Toolbox::getRandomString(20), 'date' => date("Y-m-d H:i:s", intval($opendate)), 'closedate' => $closedatetoadd, 'solvedate' => $solvedatetoadd, 'date_mod' => date("Y-m-d H:i:s", intval($updatedate)), 'users_id_lastupdater' => $users[0], 'status' => $status, 'users_id_recipient' => $users[0], 'requesttypes_id' => mt_rand(0,6), '_suppliers_id_assign' => $enterprise, 'itemtype' => $type, 'items_id' => $ID, 'content' => "tracking '".Toolbox::getRandomString(15), 'urgency' => mt_rand(1,5), 'impact' => mt_rand(1,5), 'priority' => mt_rand(1,5), 'itilcategories_id' => mt_rand(0, $MAX['tracking_category']), 'type' => mt_rand(1,2), 'solutiontypes_id' => $solutiontype, 'locations_id' => mt_rand($FIRST['locations'], $LAST['locations']), 'solution' => $solution, 'actiontime' => $actiontime, 'due_date' => $duedatetoadd, 'close_delay_stat' => $closetime, 'solve_delay_stat' => $solvetime, 'takeintoaccount_delay_stat' => $firstactiontime, '_users_id_requester' => $users[0], '_users_id_assign' => $users[1], '_groups_id_assign' => mt_rand($FIRST["techgroups"], $LAST['techgroups']), '_groups_id_requester' => mt_rand($FIRST["groups"], $LAST['groups']), ))); // Add followups $i = 0; $fID = 0; $first = true; $date = 0; $tf = new TicketFollowup(); while (mt_rand(0,100)<$percent['followups']) { if ($first) { $date = $opendate+$firstactiontime; $first = false; } else { $date += mt_rand(3600, 7776000); } $tf->add(toolbox::addslashes_deep( array('tickets_id' => $tID, 'date' => date("Y-m-d H:i:s", $date), 'users_id' => $users[1], 'content' => "followup $i '".Toolbox::getRandomString(15), 'requesttypes_id' => mt_rand(0, 3)))); $i++; } $tt = new TicketTask(); while (mt_rand(0,100)<$percent['tasks']) { $doplan=false; if ($first) { $date = $opendate+$firstactiontime; $first = false; $doplan = true; } else { $date += mt_rand(3600, 7776000); } $begin = $end = 'NULL'; $assign_user = 0; $state = 1; if ($status == CommonITILObject::PLANNED && $doplan) { $endtask = date("Y-m-d H:i:s", $date4); if ($endtask < date("Y-m-d H:i:s")) { $state = 2; // done } } $params = toolbox::addslashes_deep( array('tickets_id' => $tID, 'taskcategories_id' => mt_rand($FIRST['taskcategory'], $LAST['taskcategory']), 'date' => date("Y-m-d H:i:s",$date), 'users_id' => $users[1], 'content' => "task $i '".Toolbox::getRandomString(15), 'is_private' => mt_rand(0,1), 'state' => $state, 'users_id_tech' => $users[1])); if ($status == CommonITILObject::PLANNED && $doplan) { $params['plan'] = array('begin' => date("Y-m-d H:i:s", $date3), 'end' => $endtask); } $tt->add($params); $i++; } $tc = new TicketCost(); $params = toolbox::addslashes_deep( array('tickets_id' => $tID, 'entities_id' => $ID_entity, 'begin_date' => date("Y-m-d H:i:s", intval($opendate)), 'name' => "C'ost", 'cost_time' => $hour_cost, 'actiontime' => floor($actiontime/2))); // Insert satisfaction for stats if ($status == CommonITILObject::CLOSED && mt_rand(0,100) < $percent['satisfaction']) { $answerdate = 'NULL'; if (mt_rand(0,100) < $percent['answersatisfaction']) { $answerdate = $closedatetoadd; } $ts = new TicketSatisfaction(); $ts->add(toolbox::addslashes_deep( array('tickets_id' => $tID, 'type' => mt_rand(1,2), 'date_begin' => $closedatetoadd, 'date_answer' => $answerdate, 'satisfaction' => mt_rand(0,5), 'comment' => "comment ' satisfaction $tID"))); } } }