Skip to content

Commit 5f2604a

Browse files
AdrienClairembaultbtry
authored andcommitted
Fix default document category
1 parent c5499ad commit 5f2604a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

inc/targetticket.class.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ protected function getTargetTemplate(array $data): int {
803803
* @return Ticket|null Generated ticket if success, null otherwise
804804
*/
805805
public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
806+
global $CFG_GLPI;
807+
806808
$ticket = new Ticket();
807809
$form = $formanswer->getForm();
808810
$data = $this->getDefaultData($formanswer);
@@ -904,6 +906,22 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
904906
return null;
905907
}
906908

909+
// Set default document category
910+
$document_category = $CFG_GLPI['documentcategories_id_forticket'] ?? 0;
911+
if ($document_category) {
912+
foreach (array_keys($this->attachedDocuments) as $documents_id) {
913+
$document = Document::getById($documents_id);
914+
if (!$document) {
915+
continue;
916+
}
917+
918+
$document->update([
919+
'id' => $document->fields['id'],
920+
'documentcategories_id' => $document_category,
921+
]);
922+
}
923+
}
924+
907925
$this->saveTags($formanswer, $ticketID);
908926

909927
// Add link between Ticket and FormAnswer

0 commit comments

Comments
 (0)