Skip to content

Commit 4af002a

Browse files
committed
feat: convert foreign keys to unsigned integers
1 parent fb267cf commit 4af002a

10 files changed

+318
-156
lines changed

front/targetticket.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
if (!$targetTicket->canUpdateItem()) {
5656
Session::addMessageAfterRedirect(__('No right to update this item.', 'formcreator'), false, ERROR);
5757
} else {
58-
$actor_value = $_POST['actor_value_' . $_POST['actor_type']] ?? null;
58+
$actor_value = $_POST['actor_value_' . $_POST['actor_type']] ?? 0;
5959
$use_notification = ($_POST['use_notification'] == 0) ? 0 : 1;
6060
$targetTicket_actor = new PluginFormcreatorTarget_Actor();
6161
$targetTicket_actor->add([

inc/abstracttarget.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ protected function setTargetDueDate($data, PluginFormcreatorFormAnswer $formansw
15951595
global $DB;
15961596

15971597
$answer = new PluginFormcreatorAnswer();
1598-
if ($this->fields['due_date_question'] !== null) {
1598+
if ($this->fields['due_date_question'] != 0) {
15991599
$request = [
16001600
'FROM' => $answer::getTable(),
16011601
'WHERE' => [

inc/target_actor.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function prepareInputForAdd($input) {
9898
return false;
9999
}
100100

101-
$input['actor_value'] = $input['actor_value_' . $input['actor_type']] ?? null;
101+
$input['actor_value'] = $input['actor_value_' . $input['actor_type']] ?? 0;
102102

103103
if (isset($input['use_notification'])) {
104104
$input['use_notification'] = ($input['use_notification'] == 0) ? 0 : 1;

inc/targetchange.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function prepareInputForUpdate($input) {
523523
unset($input['_destination_entity_value_entity']);
524524
break;
525525
default :
526-
$input['destination_entity_value'] = 'NULL';
526+
$input['destination_entity_value'] = 0;
527527
break;
528528
}
529529
}

inc/targetproblem.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function prepareInputForUpdate($input) {
269269
unset($input['_destination_entity_value_entity']);
270270
break;
271271
default :
272-
$input['destination_entity_value'] = 'NULL';
272+
$input['destination_entity_value'] = 0;
273273
break;
274274
}
275275
}

inc/targetticket.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public function prepareInputForUpdate($input) {
556556
$input['destination_entity_value'] = $input['_destination_entity_value_entity'];
557557
break;
558558
default :
559-
$input['destination_entity_value'] = 'NULL';
559+
$input['destination_entity_value'] = 0;
560560
break;
561561
}
562562
}

install/mysql/plugin_formcreator_empty.sql

Lines changed: 147 additions & 147 deletions
Large diffs are not rendered by default.

install/upgrade_to_2.13.php

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/3-unit/PluginFormcreatorTargetChange.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public function testImport() {
500500
'urgency_question' => '0',
501501
'validation_followup' => '1',
502502
'destination_entity' => '0',
503-
'destination_entity_value' => null,
503+
'destination_entity_value' => '0',
504504
'tag_type' => \PluginFormcreatorTargetChange::TAG_TYPE_NONE,
505505
'tag_questions' => '0',
506506
'tag_specifics' => '',

tests/3-unit/PluginFormcreatorTargetTicket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ public function testImport() {
702702
'location_question' => '0',
703703
'validation_followup' => '1',
704704
'destination_entity' => '0',
705-
'destination_entity_value' => null,
705+
'destination_entity_value' => 0,
706706
'tag_type' => \PluginFormcreatorTargetTicket::TAG_TYPE_NONE,
707707
'tag_questions' => '0',
708708
'tag_specifics' => '',

0 commit comments

Comments
 (0)