Skip to content

Commit

Permalink
fix(install): move upgrade to 2.9
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent d9c9828 commit b9ad9a3
Show file tree
Hide file tree
Showing 2 changed files with 321 additions and 249 deletions.
249 changes: 0 additions & 249 deletions install/upgrade_to_2.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,254 +59,5 @@ public function upgrade(Migration $migration) {
$table = 'glpi_plugin_formcreator_targettickets';
$migration->addField($table, 'associate_rule', 'integer', ['after' => 'category_question']);
$migration->addField($table, 'associate_question', 'integer', ['after' => 'associate_rule']);

// Rename the plugin
$plugin = new Plugin();
$plugin->getFromDBbyDir('formcreator');
$success = $plugin->update([
'id' => $plugin->getID(),
'name' => 'Form Creator',
]);

// Remove enum for formanswer
$this->enumToInt(
'glpi_plugin_formcreator_formanswers',
'status',
[
'waiting' => 101,
'refused' => 102,
'accepted' => 103,
],
[
'default_value' => '1'
]
);

// Remove enum for question
$this->enumToInt(
'glpi_plugin_formcreator_questions',
'show_rule',
[
'always' => 1,
'hidden' => 2,
'shown' => 3,
],
[
'default_value' => '1'
]
);

// Remove show_logic enum for question conditions
$this->enumToInt(
'glpi_plugin_formcreator_questions_conditions',
'show_logic',
[
'AND' => 1,
'OR' => 2,
],
[
'default_value' => '1'
]
);

// Remove show_condition enum for question conditions
$this->enumToInt(
'glpi_plugin_formcreator_questions_conditions',
'show_condition',
[
'==' => 1,
'!=' => 2,
'<' => 3,
'>' => 4,
'<=' => 5,
'>=' => 6,
],
[
'default_value' => '1'
]
);

$tables = [
'glpi_plugin_formcreator_targetchanges',
'glpi_plugin_formcreator_targettickets'
];
foreach ($tables as $table) {
$this->enumToInt(
$table,
'due_date_rule',
[
'none' => 1,
'answer' => 2,
'ticket' => 3,
'calc' => 4,
],
[
'default_value' => '1'
]
);

$this->enumToInt(
$table,
'due_date_period',
[
'minute' => 1,
'hour' => 2,
'day' => 3,
'month' => 4,
],
[
'default_value' => '1'
]
);

$this->enumToInt(
$table,
'urgency_rule',
[
'none' => 1,
'specific' => 2,
'answer' => 3,
],
[
'default_value' => '1'
]
);

// Remove enum for destination_entity
$this->enumToInt(
$table,
'destination_entity',
[
'current' => 1,
'requester' => 2,
'requester_dynamic_first' => 3,
'requester_dynamic_last' => 4,
'form' => 5,
'validator' => 6,
'specific' => 7,
'user' => 8,
'entity' => 9,
],
[
'default_value' => '1'
]
);

// Remove enum for urgency_rule
$this->enumToInt(
$table,
'tag_type',
[
'none' => 1,
'questions' => 2,
'specifics' => 3,
'questions_and_specific' => 4,
'questions_or_specific' => 5,
],
[
'default_value' => '1'
]
);

// Remove enum for category_rule
$this->enumToInt(
$table,
'category_rule',
[
'none' => 1,
'specific' => 2,
'answer' => 3,
],
[
'default_value' => '1'
]
);
}

$this->enumToInt(
'glpi_plugin_formcreator_targettickets',
'location_rule',
[
'none' => 1,
'specific' => 2,
'answer' => 3,
],
[
'default_value' => '1'
]
);

$tables = [
'glpi_plugin_formcreator_targetchanges_actors',
'glpi_plugin_formcreator_targettickets_actors'
];
foreach ($tables as $table) {
$this->enumToInt(
$table,
'actor_role',
[
'requester' => 1,
'observer' => 2,
'assigned' => 3,
],
[
'default_value' => '1'
]
);

$this->enumToInt(
$table,
'actor_type',
[
'creator' => 1,
'validator' => 2,
'person' => 3,
'question_person' => 4,
'group' => 5,
'question_group' => 6,
'supplier' => 7,
'question_supplier' => 8,
'question_actors' => 9,
],
[
'default_value' => '1'
]
);
}
}

/**
* convert an enum column into an int
*
* @param string $table
* @param string $field
* @param array $map map of enum value => equivalent integer
* @param array $options options to give to Migration::addField and Migration::changeField
* @return void
*/
protected function enumToInt($table, $field, array $map, $options = []) {
global $DB;
$isEnum = PluginFormcreatorCommon::getEnumValues($table, $field);
if (count($isEnum) > 0) {
$this->migration->addField(
$table,
"new_$field",
'integer',
['after' => $field] + $options
);
$this->migration->migrationOneTable($table);
foreach ($map as $enumValue => $integerValue) {
$DB->update(
$table,
["new_$field" => $integerValue],
[$field => $enumValue]
);
}
$this->migration->changeField(
$table,
"new_$field",
$field, 'integer'
);
}
}
}
Loading

0 comments on commit b9ad9a3

Please sign in to comment.