Skip to content

Commit

Permalink
fix(questionregex,questionrange): remove bad FK rows
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 18, 2022
1 parent f1dc088 commit 1d5577e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion install/upgrade_to_2.13.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ public function addDefaultFormListMode() {
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `default_form_list_mode`=0 WHERE `entities_id`=0");
}

/**
* It is possible to have inconsistencies in DB where several identical parameters exist for a single question
* Removing all duplicates, and add unicity in the tables
*
* @return void
*/
public function questionParameterUnicity() {
global $DB;

Expand Down Expand Up @@ -373,17 +379,25 @@ public function questionParameterUnicity() {
WHERE dr.plugin_formcreator_questions_id = j.question_id AND dr.id <> j.qrid
");


$tables = [
'glpi_plugin_formcreator_questionranges',
'glpi_plugin_formcreator_questionregexes',
];

foreach ($tables as $table) {
$DB->delete($table, [
'plugin_formcreator_questions_id' => '0'
]);
$this->migration->addKey($table, ['plugin_formcreator_questions_id', 'fieldname'], 'unicity', 'UNIQUE');
}
}

/**
* It is possible to have questions using parameters, but none exist in the DB
* ading empty parameters where needed
*
* @return void
*/
public function questionParameterRepair() {
global $DB;

Expand Down

0 comments on commit 1d5577e

Please sign in to comment.