@@ -200,6 +200,32 @@ function plugin_formcreator_updateForm_Answer_2_5(Migration $migration) {
200200 $ migration ->addKey ('glpi_plugin_formcreator_forms_answers ' , 'requester_id ' );
201201 $ migration ->addKey ('glpi_plugin_formcreator_forms_answers ' , 'validator_id ' );
202202 $ migration ->addField ('glpi_plugin_formcreator_forms_answers ' , 'is_deleted ' , 'bool ' );
203+
204+ // Update Form Answers
205+ $ table = 'glpi_plugin_formcreator_forms_answers ' ;
206+
207+ if ($ DB ->fieldExists ($ table , 'validator_id ' , false )) {
208+ $ migration ->addField ($ table , 'users_id_validator ' , 'integer ' , ['after ' => 'requester_id ' ]);
209+ $ migration ->addField ($ table , 'groups_id_validator ' , 'integer ' , ['after ' => 'users_id_validator ' ]);
210+ $ migration ->addKey ($ table , 'users_id_validator ' );
211+ $ migration ->addKey ($ table , 'groups_id_validator ' );
212+ $ migration ->migrationOneTable ($ table );
213+
214+ $ formTable = 'glpi_plugin_formcreator_forms ' ;
215+ $ query = "UPDATE ` $ table`
216+ INNER JOIN ` $ formTable` ON (` $ table`.`plugin_formcreator_forms_id` = ` $ formTable`.`id`)
217+ SET `users_id_validator` = 'validator_id'
218+ WHERE ` $ formTable`.`validation_required` = '1' " ;
219+ $ DB ->query ($ query ) or plugin_formcreator_upgrade_error ($ migration );
220+ $ query = "UPDATE ` $ table`
221+ INNER JOIN ` $ formTable` ON (` $ table`.`plugin_formcreator_forms_id` = ` $ formTable`.`id`)
222+ SET `groups_id_validator` = 'validator_id'
223+ WHERE ` $ formTable`.`validation_required` = '2' " ;
224+ $ DB ->query ($ query ) or plugin_formcreator_upgrade_error ($ migration );
225+
226+ $ migration ->dropKey ($ table , 'validator_id ' );
227+ $ migration ->dropField ($ table , 'validator_id ' );
228+ }
203229}
204230
205231function plugin_formcreator_updateForm_Profile_2_5 (Migration $ migration ) {
@@ -414,8 +440,67 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) {
414440 'mode ' => CronTask::MODE_EXTERNAL
415441 ]
416442 );
417- $ task = new CronTask ();
418- PluginFormcreatorIssue::cronSyncIssues ($ task );
443+
444+ $ query = "SELECT DISTINCT
445+ NULL AS `id`,
446+ CONCAT('f_',`fanswer`.`id`) AS `display_id`,
447+ `fanswer`.`id` AS `original_id`,
448+ 'PluginFormcreatorForm_Answer' AS `sub_itemtype`,
449+ `f`.`name` AS `name`,
450+ `fanswer`.`status` AS `status`,
451+ `fanswer`.`request_date` AS `date_creation`,
452+ `fanswer`.`request_date` AS `date_mod`,
453+ `fanswer`.`entities_id` AS `entities_id`,
454+ `fanswer`.`is_recursive` AS `is_recursive`,
455+ `fanswer`.`requester_id` AS `requester_id`,
456+ `fanswer`.`users_id_validator` AS `validator_id`,
457+ `fanswer`.`comment` AS `comment`
458+ FROM `glpi_plugin_formcreator_forms_answers` AS `fanswer`
459+ LEFT JOIN `glpi_plugin_formcreator_forms` AS `f`
460+ ON`f`.`id` = `fanswer`.`plugin_formcreator_forms_id`
461+ LEFT JOIN `glpi_items_tickets` AS `itic`
462+ ON `itic`.`items_id` = `fanswer`.`id`
463+ AND `itic`.`itemtype` = 'PluginFormcreatorForm_Answer'
464+ WHERE `fanswer`.`is_deleted` = '0'
465+ GROUP BY `original_id`
466+ HAVING COUNT(`itic`.`tickets_id`) != 1
467+
468+ UNION
469+
470+ SELECT DISTINCT
471+ NULL AS `id`,
472+ CONCAT('t_',`tic`.`id`) AS `display_id`,
473+ `tic`.`id` AS `original_id`,
474+ 'Ticket' AS `sub_itemtype`,
475+ `tic`.`name` AS `name`,
476+ `tic`.`status` AS `status`,
477+ `tic`.`date` AS `date_creation`,
478+ `tic`.`date_mod` AS `date_mod`,
479+ `tic`.`entities_id` AS `entities_id`,
480+ 0 AS `is_recursive`,
481+ `tic`.`users_id_recipient` AS `requester_id`,
482+ 0 AS `validator_id`,
483+ `tic`.`content` AS `comment`
484+ FROM `glpi_tickets` AS `tic`
485+ LEFT JOIN `glpi_items_tickets` AS `itic`
486+ ON `itic`.`tickets_id` = `tic`.`id`
487+ AND `itic`.`itemtype` = 'PluginFormcreatorForm_Answer'
488+ WHERE `tic`.`is_deleted` = 0
489+ GROUP BY `original_id`
490+ HAVING COUNT(`itic`.`items_id`) <= 1 " ;
491+
492+ $ countQuery = "SELECT COUNT(*) AS `cpt` FROM ( $ query) AS `issues` " ;
493+ $ result = $ DB ->query ($ countQuery );
494+ if ($ result !== false ) {
495+ $ count = $ DB ->fetch_assoc ($ result );
496+ $ table = PluginFormcreatorIssue::getTable ();
497+ if (countElementsInTable ($ table ) != $ count ['cpt ' ]) {
498+ if ($ DB ->query ("TRUNCATE ` $ table` " )) {
499+ $ DB ->query ("INSERT INTO ` $ table` SELECT * FROM ( $ query) as `dt` " );
500+ $ volume = 1 ;
501+ }
502+ }
503+ }
419504}
420505
421506function plugin_formcreator_updateQuestionCondition_2_5 (Migration $ migration ) {
0 commit comments