Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(glpi_item): add default value to prevent error when field is not filled #534

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/migration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function getSQLFields(string $field_name, string $field_type): arr
$fields[$field_name] = 'INT NOT NULL DEFAULT 0';
break;
case $field_type === 'glpi_item':
$fields[sprintf('itemtype_%s', $field_name)] = 'varchar(100) NOT NULL';
$fields[sprintf('itemtype_%s', $field_name)] = 'varchar(100) DEFAULT NULL';
$fields[sprintf('items_id_%s', $field_name)] = "int {$default_key_sign} NOT NULL DEFAULT 0";
break;
case $field_type === 'date':
Expand Down
18 changes: 18 additions & 0 deletions templates/container.class.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ class %%CLASSNAME%% extends CommonDBTM
(`itemtype`, `items_id`, `plugin_fields_containers_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
$DB->query($query) or die ($DB->error());
} else {
// 1.15.4
// fix nullable state for 'glpi_item' field
$result = $DB->query("SHOW COLUMNS FROM `$table`");
if ($result && $DB->numrows($result) > 0) {
$changed = false;
$migration = new PluginFieldsMigration(0);
while ($data = $DB->fetchAssoc($result)) {
if (str_starts_with($data['Field'], 'itemtype_') && $data['Null'] !== 'YES') {
Toolbox::logDebug($data);
$migration->changeField($table, $data['Field'], $data['Field'], "varchar(100) DEFAULT NULL");
$changed = true;
}
}
if ($changed) {
$migration->executeMigration();
}
}
}
}

Expand Down