function pre_deleteItem()
{
global $DB;
// fordocument mandatory
if ($this->fields['itemtype'] == 'Ticket') {
$ticket = new Ticket();
$ticket->getFromDB($this->fields['items_id']);
$tt = $ticket->getTicketTemplateToUse(0, $ticket->fields['type'], $ticket->fields['itilcategories_id'], $ticket->fields['entities_id']);
if (isset($tt->mandatory['_documents_id'])) {
// refuse delete if only one document
if (countElementsInTable($this->getTable(), ['items_id' => $this->fields['items_id'], 'itemtype' => 'Ticket']) == 1) {
$message = sprintf(__('Mandatory fields are not filled. Please correct: %s'), _n('Document', 'Documents', 2));
Session::addMessageAfterRedirect($message, false, ERROR);
return false;
}
}
}
return true;
}