Commit 48aecb33 authored by Cédric Anne's avatar Cédric Anne Committed by Johan Cwiklinski

Fix '_date_creation_calendars_id' criteria on ticket update rules (#5876)

parent 8b4507af
......@@ -1122,7 +1122,9 @@ class Ticket extends CommonITILObject {
}
}
/// Process Business Rules
// Process Business Rules
$this->fillInputForBusinessRules($input);
// Add actors on standard input
$rules = new RuleTicketCollection($entid);
$rule = $rules->getRuleClass();
......@@ -1827,25 +1829,9 @@ class Ticket extends CommonITILObject {
$input['_users_id_assign'] = Session::getLoginUserID();
}
// add calendars matching date creation (for business rules)
$calendars = [];
$ite_calandar = $DB->request([
'SELECT' => ['id'],
'FROM' => Calendar::getTable(),
'WHERE' => getEntitiesRestrictCriteria('', '', $input['entities_id'], true)
]);
foreach ($ite_calandar as $calendar_data) {
$calendar = new Calendar;
$calendar->getFromDB($calendar_data['id']);
if ($calendar->isAWorkingHour(time())) {
$calendars[] = $calendar_data['id'];
}
}
if (count($calendars)) {
$input['_date_creation_calendars_id'] = $calendars;
}
// Process Business Rules
$this->fillInputForBusinessRules($input);
$rules = new RuleTicketCollection($input['entities_id']);
// Set unset variables with are needed
......@@ -7000,4 +6986,43 @@ class Ticket extends CommonITILObject {
'add_now' => $this->getField('closedate') == ""
]);
}
/**
* Fill input with values related to business rules.
*
* @param array $input
*
* @return void
*/
private function fillInputForBusinessRules(array &$input) {
global $DB;
$entities_id = isset($input['entities_id'])
? $input['entities_id']
: $this->fields['entities_id'];
// If creation date is not set, then this function is called during ticket creation
$creation_date = !empty($this->fields['date_creation'])
? strtotime($this->fields['date_creation'])
: time();
// add calendars matching date creation (for business rules)
$calendars = [];
$ite_calendar = $DB->request([
'SELECT' => ['id'],
'FROM' => Calendar::getTable(),
'WHERE' => getEntitiesRestrictCriteria('', '', $entities_id, true)
]);
foreach ($ite_calendar as $calendar_data) {
$calendar = new Calendar();
$calendar->getFromDB($calendar_data['id']);
if ($calendar->isAWorkingHour($creation_date)) {
$calendars[] = $calendar_data['id'];
}
}
if (count($calendars)) {
$input['_date_creation_calendars_id'] = $calendars;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment