@@ -59,254 +59,5 @@ public function upgrade(Migration $migration) {
5959 $ table = 'glpi_plugin_formcreator_targettickets ' ;
6060 $ migration ->addField ($ table , 'associate_rule ' , 'integer ' , ['after ' => 'category_question ' ]);
6161 $ migration ->addField ($ table , 'associate_question ' , 'integer ' , ['after ' => 'associate_rule ' ]);
62-
63- // Rename the plugin
64- $ plugin = new Plugin ();
65- $ plugin ->getFromDBbyDir ('formcreator ' );
66- $ success = $ plugin ->update ([
67- 'id ' => $ plugin ->getID (),
68- 'name ' => 'Form Creator ' ,
69- ]);
70-
71- // Remove enum for formanswer
72- $ this ->enumToInt (
73- 'glpi_plugin_formcreator_formanswers ' ,
74- 'status ' ,
75- [
76- 'waiting ' => 101 ,
77- 'refused ' => 102 ,
78- 'accepted ' => 103 ,
79- ],
80- [
81- 'default_value ' => '1 '
82- ]
83- );
84-
85- // Remove enum for question
86- $ this ->enumToInt (
87- 'glpi_plugin_formcreator_questions ' ,
88- 'show_rule ' ,
89- [
90- 'always ' => 1 ,
91- 'hidden ' => 2 ,
92- 'shown ' => 3 ,
93- ],
94- [
95- 'default_value ' => '1 '
96- ]
97- );
98-
99- // Remove show_logic enum for question conditions
100- $ this ->enumToInt (
101- 'glpi_plugin_formcreator_questions_conditions ' ,
102- 'show_logic ' ,
103- [
104- 'AND ' => 1 ,
105- 'OR ' => 2 ,
106- ],
107- [
108- 'default_value ' => '1 '
109- ]
110- );
111-
112- // Remove show_condition enum for question conditions
113- $ this ->enumToInt (
114- 'glpi_plugin_formcreator_questions_conditions ' ,
115- 'show_condition ' ,
116- [
117- '== ' => 1 ,
118- '!= ' => 2 ,
119- '< ' => 3 ,
120- '> ' => 4 ,
121- '<= ' => 5 ,
122- '>= ' => 6 ,
123- ],
124- [
125- 'default_value ' => '1 '
126- ]
127- );
128-
129- $ tables = [
130- 'glpi_plugin_formcreator_targetchanges ' ,
131- 'glpi_plugin_formcreator_targettickets '
132- ];
133- foreach ($ tables as $ table ) {
134- $ this ->enumToInt (
135- $ table ,
136- 'due_date_rule ' ,
137- [
138- 'none ' => 1 ,
139- 'answer ' => 2 ,
140- 'ticket ' => 3 ,
141- 'calc ' => 4 ,
142- ],
143- [
144- 'default_value ' => '1 '
145- ]
146- );
147-
148- $ this ->enumToInt (
149- $ table ,
150- 'due_date_period ' ,
151- [
152- 'minute ' => 1 ,
153- 'hour ' => 2 ,
154- 'day ' => 3 ,
155- 'month ' => 4 ,
156- ],
157- [
158- 'default_value ' => '1 '
159- ]
160- );
161-
162- $ this ->enumToInt (
163- $ table ,
164- 'urgency_rule ' ,
165- [
166- 'none ' => 1 ,
167- 'specific ' => 2 ,
168- 'answer ' => 3 ,
169- ],
170- [
171- 'default_value ' => '1 '
172- ]
173- );
174-
175- // Remove enum for destination_entity
176- $ this ->enumToInt (
177- $ table ,
178- 'destination_entity ' ,
179- [
180- 'current ' => 1 ,
181- 'requester ' => 2 ,
182- 'requester_dynamic_first ' => 3 ,
183- 'requester_dynamic_last ' => 4 ,
184- 'form ' => 5 ,
185- 'validator ' => 6 ,
186- 'specific ' => 7 ,
187- 'user ' => 8 ,
188- 'entity ' => 9 ,
189- ],
190- [
191- 'default_value ' => '1 '
192- ]
193- );
194-
195- // Remove enum for urgency_rule
196- $ this ->enumToInt (
197- $ table ,
198- 'tag_type ' ,
199- [
200- 'none ' => 1 ,
201- 'questions ' => 2 ,
202- 'specifics ' => 3 ,
203- 'questions_and_specific ' => 4 ,
204- 'questions_or_specific ' => 5 ,
205- ],
206- [
207- 'default_value ' => '1 '
208- ]
209- );
210-
211- // Remove enum for category_rule
212- $ this ->enumToInt (
213- $ table ,
214- 'category_rule ' ,
215- [
216- 'none ' => 1 ,
217- 'specific ' => 2 ,
218- 'answer ' => 3 ,
219- ],
220- [
221- 'default_value ' => '1 '
222- ]
223- );
224- }
225-
226- $ this ->enumToInt (
227- 'glpi_plugin_formcreator_targettickets ' ,
228- 'location_rule ' ,
229- [
230- 'none ' => 1 ,
231- 'specific ' => 2 ,
232- 'answer ' => 3 ,
233- ],
234- [
235- 'default_value ' => '1 '
236- ]
237- );
238-
239- $ tables = [
240- 'glpi_plugin_formcreator_targetchanges_actors ' ,
241- 'glpi_plugin_formcreator_targettickets_actors '
242- ];
243- foreach ($ tables as $ table ) {
244- $ this ->enumToInt (
245- $ table ,
246- 'actor_role ' ,
247- [
248- 'requester ' => 1 ,
249- 'observer ' => 2 ,
250- 'assigned ' => 3 ,
251- ],
252- [
253- 'default_value ' => '1 '
254- ]
255- );
256-
257- $ this ->enumToInt (
258- $ table ,
259- 'actor_type ' ,
260- [
261- 'creator ' => 1 ,
262- 'validator ' => 2 ,
263- 'person ' => 3 ,
264- 'question_person ' => 4 ,
265- 'group ' => 5 ,
266- 'question_group ' => 6 ,
267- 'supplier ' => 7 ,
268- 'question_supplier ' => 8 ,
269- 'question_actors ' => 9 ,
270- ],
271- [
272- 'default_value ' => '1 '
273- ]
274- );
275- }
276- }
277-
278- /**
279- * convert an enum column into an int
280- *
281- * @param string $table
282- * @param string $field
283- * @param array $map map of enum value => equivalent integer
284- * @param array $options options to give to Migration::addField and Migration::changeField
285- * @return void
286- */
287- protected function enumToInt ($ table , $ field , array $ map , $ options = []) {
288- global $ DB ;
289- $ isEnum = PluginFormcreatorCommon::getEnumValues ($ table , $ field );
290- if (count ($ isEnum ) > 0 ) {
291- $ this ->migration ->addField (
292- $ table ,
293- "new_ $ field " ,
294- 'integer ' ,
295- ['after ' => $ field ] + $ options
296- );
297- $ this ->migration ->migrationOneTable ($ table );
298- foreach ($ map as $ enumValue => $ integerValue ) {
299- $ DB ->update (
300- $ table ,
301- ["new_ $ field " => $ integerValue ],
302- [$ field => $ enumValue ]
303- );
304- }
305- $ this ->migration ->changeField (
306- $ table ,
307- "new_ $ field " ,
308- $ field , 'integer '
309- );
310- }
31162 }
31263}
0 commit comments