@@ -387,33 +387,35 @@ function plugin_formcreator_hook_update_ticket(CommonDBTM $item) {
387387function plugin_formcreator_hook_delete_ticket (CommonDBTM $ item ) {
388388 global $ DB ;
389389
390- if ($ item instanceof Ticket) {
391- $ id = $ item ->getID ();
390+ if (!($ item instanceof Ticket)) {
391+ return ;
392+ }
392393
393- // mark formanswers as deleted
394- $ iterator = $ DB ->request ([
395- 'SELECT ' => ['id ' ],
396- 'FROM ' => Item_Ticket::getTable (),
397- 'WHERE ' => [
398- 'itemtype ' => 'PluginFormcreatorFormAnswer ' ,
399- 'tickets_id ' => $ id ,
400- ]
401- ]);
402- foreach ($ iterator as $ row ) {
403- $ form_answer = new PluginFormcreatorFormAnswer ();
404- $ form_answer ->update ([
405- 'id ' => $ row ['id ' ],
406- 'is_deleted ' => 1 ,
407- ]);
408- }
394+ $ id = $ item ->getID ();
409395
410- // delete issue
411- $ issue = new PluginFormcreatorIssue ();
412- $ issue ->deleteByCriteria ([
413- 'display_id ' => "t_ $ id " ,
414- 'sub_itemtype ' => 'Ticket '
415- ], 1 );
396+ // mark formanswers as deleted
397+ $ iterator = $ DB ->request ([
398+ 'SELECT ' => ['id ' ],
399+ 'FROM ' => Item_Ticket::getTable (),
400+ 'WHERE ' => [
401+ 'itemtype ' => 'PluginFormcreatorFormAnswer ' ,
402+ 'tickets_id ' => $ id ,
403+ ]
404+ ]);
405+ foreach ($ iterator as $ row ) {
406+ $ form_answer = new PluginFormcreatorFormAnswer ();
407+ $ form_answer ->update ([
408+ 'id ' => $ row ['id ' ],
409+ 'is_deleted ' => 1 ,
410+ ]);
416411 }
412+
413+ // delete issue
414+ $ issue = new PluginFormcreatorIssue ();
415+ $ issue ->deleteByCriteria ([
416+ 'display_id ' => "t_ $ id " ,
417+ 'sub_itemtype ' => 'Ticket '
418+ ], 1 );
417419}
418420
419421function plugin_formcreator_hook_restore_ticket (CommonDBTM $ item ) {
0 commit comments