@@ -37,10 +37,11 @@ class PluginFormcreatorUpgradeTo2_13 {
3737 */
3838 public function upgrade (Migration $ migration ) {
3939 $ this ->migration = $ migration ;
40+ $ this ->migrateFkToUnsignedInt ();
4041 $ this ->addFormAnswerTitle ();
4142 $ this ->defaultValuesForTargets ();
4243 $ this ->migrateItemtypeInQuestion ();
43- $ this ->fixInconsistency ();
44+ // $this->fixInconsistency();
4445 $ this ->addTargetValidationSetting ();
4546 $ this ->addFormVisibility ();
4647 $ this ->addDashboardVisibility ();
@@ -140,4 +141,165 @@ protected function addDashboardVisibility() {
140141
141142 $ this ->migration ->addPostQuery ("UPDATE glpi_plugin_formcreator_entityconfigs SET `is_dashboard_visible`=1 WHERE `id`=0 " );
142143 }
144+
145+ protected function migrateFkToUnsignedInt () {
146+ global $ DB ;
147+
148+ $ table = 'glpi_plugin_formcreator_formanswers ' ;
149+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `requester_id` = 0 WHERE `requester_id` IS NULL " );
150+
151+ $ table = 'glpi_plugin_formcreator_targetchanges ' ;
152+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `due_date_question` = 0 WHERE `due_date_question` IS NULL " );
153+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `destination_entity_value` = 0 WHERE `destination_entity_value` IS NULL " );
154+
155+ $ table = 'glpi_plugin_formcreator_targettickets ' ;
156+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `due_date_question` = 0 WHERE `due_date_question` IS NULL " );
157+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `destination_entity_value` = 0 WHERE `destination_entity_value` IS NULL " );
158+
159+ $ table = 'glpi_plugin_formcreator_targetproblems ' ;
160+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `destination_entity_value` = 0 WHERE `destination_entity_value` IS NULL " );
161+
162+ $ table = 'glpi_plugin_formcreator_targets_actors ' ;
163+ $ DB ->queryOrDie ("UPDATE ` $ table`, SET `actor_value` = 0 WHERE `actor_value` IS NULL " );
164+
165+ $ tables = [
166+ 'glpi_plugin_formcreator_answers ' => [
167+ 'id ' ,
168+ 'plugin_formcreator_formanswers_id ' ,
169+ 'plugin_formcreator_questions_id ' ,
170+ ],
171+ 'glpi_plugin_formcreator_categories ' => [
172+ 'id ' ,
173+ 'plugin_formcreator_categories_id ' ,
174+ 'knowbaseitemcategories_id ' ,
175+ ],
176+ 'glpi_plugin_formcreator_entityconfigs ' => [
177+ 'plugin_formcreator_categories_id ' ,
178+ ],
179+ 'glpi_plugin_formcreator_forms ' => [
180+ 'id ' ,
181+ 'entities_id ' ,
182+ 'plugin_formcreator_categories_id ' ,
183+ ],
184+ 'glpi_plugin_formcreator_formanswers ' => [
185+ 'id ' ,
186+ 'entities_id ' ,
187+ 'plugin_formcreator_forms_id ' ,
188+ 'requester_id ' ,
189+ 'users_id_validator ' ,
190+ 'groups_id_validator ' ,
191+ ],
192+ 'glpi_plugin_formcreator_forms_profiles ' => [
193+ 'id ' ,
194+ 'plugin_formcreator_forms_id ' ,
195+ 'profiles_id ' ,
196+ ],
197+ 'glpi_plugin_formcreator_forms_validators ' => [
198+ 'id ' ,
199+ 'plugin_formcreator_forms_id ' ,
200+ 'items_id ' ,
201+ ],
202+ 'glpi_plugin_formcreator_questions ' => [
203+ 'id ' ,
204+ 'plugin_formcreator_sections_id ' ,
205+ ],
206+ 'glpi_plugin_formcreator_conditions ' => [
207+ 'id ' ,
208+ 'items_id ' ,
209+ 'plugin_formcreator_questions_id ' ,
210+ ],
211+ 'glpi_plugin_formcreator_sections ' => [
212+ 'id ' ,
213+ 'plugin_formcreator_forms_id ' ,
214+ ],
215+ 'glpi_plugin_formcreator_targetchanges ' => [
216+ 'id ' ,
217+ 'plugin_formcreator_forms_id ' ,
218+ 'changetemplates_id ' ,
219+ 'due_date_question ' ,
220+ 'urgency_question ' ,
221+ 'destination_entity_value ' ,
222+ 'category_question ' ,
223+ 'sla_question_tto ' ,
224+ 'sla_question_ttr ' ,
225+ 'ola_question_tto ' ,
226+ 'ola_question_ttr ' ,
227+ ],
228+ 'glpi_plugin_formcreator_targettickets ' => [
229+ 'id ' ,
230+ 'plugin_formcreator_forms_id ' ,
231+ 'type_question ' ,
232+ 'tickettemplates_id ' ,
233+ 'due_date_question ' ,
234+ 'urgency_question ' ,
235+ 'destination_entity_value ' ,
236+ 'category_question ' ,
237+ 'associate_question ' ,
238+ 'location_question ' ,
239+ 'sla_question_tto ' ,
240+ 'sla_question_ttr ' ,
241+ 'ola_question_tto ' ,
242+ 'ola_question_ttr ' ,
243+ ],
244+ 'glpi_plugin_formcreator_targetproblems ' => [
245+ 'id ' ,
246+ 'plugin_formcreator_forms_id ' ,
247+ 'problemtemplates_id ' ,
248+ 'urgency_question ' ,
249+ 'destination_entity_value ' ,
250+ 'category_question ' ,
251+ ],
252+ 'glpi_plugin_formcreator_targets_actors ' => [
253+ 'id ' ,
254+ 'items_id ' ,
255+ 'actor_value ' ,
256+ ],
257+ 'glpi_plugin_formcreator_issues ' => [
258+ 'id ' ,
259+ 'items_id ' ,
260+ 'entities_id ' ,
261+ 'requester_id ' ,
262+ 'users_id_validator ' ,
263+ 'groups_id_validator ' ,
264+ 'users_id_recipient ' ,
265+ ],
266+ 'glpi_plugin_formcreator_items_targettickets ' => [
267+ 'id ' ,
268+ 'plugin_formcreator_targettickets_id ' ,
269+ 'items_id ' ,
270+ ],
271+ 'glpi_plugin_formcreator_questiondependencies ' => [
272+ 'id ' ,
273+ 'plugin_formcreator_questions_id ' ,
274+ 'plugin_formcreator_questions_id_2 ' ,
275+ ],
276+ 'glpi_plugin_formcreator_questionregexes ' => [
277+ 'id ' ,
278+ 'plugin_formcreator_questions_id ' ,
279+ ],
280+ 'glpi_plugin_formcreator_questionranges ' => [
281+ 'id ' ,
282+ 'plugin_formcreator_questions_id ' ,
283+ ],
284+ 'glpi_plugin_formcreator_forms_languages ' => [
285+ 'id ' ,
286+ 'plugin_formcreator_forms_id ' ,
287+ ],
288+ ];
289+
290+ foreach ($ tables as $ table => $ fields ) {
291+ foreach ($ fields as $ field ) {
292+ if ($ field == 'id ' ) {
293+ $ type = 'autoincrement ' ;
294+ } else {
295+ $ type = "INT " . DBConnection::getDefaultPrimaryKeySignOption () . " NOT NULL DEFAULT 0 " ;
296+ }
297+ $ this ->migration ->changeField ($ table , $ field , $ field , $ type );
298+ }
299+ }
300+
301+ // Exception for ID key of glpi_plugin_formcreator_entityconfigs : it is not an autoincrement
302+ $ table = 'glpi_plugin_formcreator_entityconfigs ' ;
303+ $ this ->migration ->changeField ($ table , 'id ' , 'id ' , 'int ' . DBConnection::getDefaultPrimaryKeySignOption () . ' not null ' );
304+ }
143305}
0 commit comments