Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 089b94c

Browse files
committed
Use default sign on primary/foreign keys
1 parent ac3ab5a commit 089b94c

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

inc/config.class.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ function showForm($ID, $options = []) {
241241
static function install(Migration $migration) {
242242
global $DB;
243243

244+
$default_charset = DBConnection::getDefaultCharset();
245+
$default_collation = DBConnection::getDefaultCollation();
246+
$default_key_sign = method_exists('DBConnection', 'getDefaultPrimaryKeySignOption') ? DBConnection::getDefaultPrimaryKeySignOption() : '';
247+
244248
$table = getTableForItemType(__CLASS__);
245249

246250
if (!$DB->tableExists($table)) {
247-
$default_charset = DBConnection::getDefaultCharset();
248-
$default_collation = DBConnection::getDefaultCollation();
249-
250251
$query = "CREATE TABLE `".$table."` (
251-
`id` int NOT NULL AUTO_INCREMENT,
252+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
252253
`host` varchar(255) NOT NULL default '',
253254
`url` varchar(255) NOT NULL default '',
254255
`login` varchar(255) NOT NULL default '',
@@ -262,8 +263,8 @@ static function install(Migration $migration) {
262263
`doc_categorie` int NOT NULL default 0,
263264
`itemType` varchar(255) NOT NULL default '',
264265
`etatMantis` varchar(100) NOT NULL default '',
265-
`solutiontypes_id` int NOT NULL DEFAULT 0,
266-
`users_id` int NOT NULL DEFAULT 0,
266+
`solutiontypes_id` int {$default_key_sign} NOT NULL DEFAULT 0,
267+
`users_id` int {$default_key_sign} NOT NULL DEFAULT 0,
267268
`check_ssl` int NOT NULL DEFAULT 0,
268269
`use_proxy` int NOT NULL DEFAULT 0,
269270
`is_password_sodium_encrypted` int NOT NULL DEFAULT 1,
@@ -280,11 +281,11 @@ static function install(Migration $migration) {
280281
}
281282

282283
if (!$DB->fieldExists($table, 'solutiontypes_id')) {
283-
$migration->addField($table, "solutiontypes_id", "INT NOT NULL DEFAULT 0");
284+
$migration->addField($table, "solutiontypes_id", "INT {$default_key_sign} NOT NULL DEFAULT 0");
284285
}
285286

286287
if (!$DB->fieldExists($table, 'users_id')) {
287-
$migration->addField($table, "users_id", "INT NOT NULL DEFAULT 0");
288+
$migration->addField($table, "users_id", "INT {$default_key_sign} NOT NULL DEFAULT 0");
288289
}
289290

290291
if (!$DB->fieldExists($table, 'check_ssl')) {

inc/mantis.class.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ public static function countForItem(CommonDBTM $item) {
104104
static function install(Migration $migration) {
105105
global $DB;
106106

107+
$default_charset = DBConnection::getDefaultCharset();
108+
$default_collation = DBConnection::getDefaultCollation();
109+
$default_key_sign = method_exists('DBConnection', 'getDefaultPrimaryKeySignOption') ? DBConnection::getDefaultPrimaryKeySignOption() : '';
110+
107111
$table = getTableForItemType(__CLASS__);
108112

109113
if (!$DB->tableExists($table)) {
110-
$default_charset = DBConnection::getDefaultCharset();
111-
$default_collation = DBConnection::getDefaultCollation();
112-
113114
$query = "CREATE TABLE `".$table."` (
114-
`id` int NOT NULL AUTO_INCREMENT,
115-
`items_id` int NOT NULL,
115+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
116+
`items_id` int {$default_key_sign} NOT NULL,
116117
`idMantis` int NOT NULL,
117118
`dateEscalade` date NOT NULL,
118119
`itemtype` varchar(255) NOT NULL,
@@ -134,7 +135,7 @@ static function install(Migration $migration) {
134135
}
135136

136137
if ($DB->fieldExists($table, 'idTicket') && !$DB->fieldExists($table, 'items_id')) {
137-
$migration->changeField($table, 'idTicket', 'items_id', 'integer', []);
138+
$migration->changeField($table, 'idTicket', 'items_id', "`items_id` int {$default_key_sign} NOT NULL", []);
138139
$migration->executeMigration();
139140
}
140141
}

inc/userpref.class.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,24 @@ class PluginMantisUserpref extends CommonDBTM {
4242
static function install($migration) {
4343
global $DB;
4444

45+
$default_charset = DBConnection::getDefaultCharset();
46+
$default_collation = DBConnection::getDefaultCollation();
47+
$default_key_sign = method_exists('DBConnection', 'getDefaultPrimaryKeySignOption') ? DBConnection::getDefaultPrimaryKeySignOption() : '';
48+
4549
if (!$DB->tableExists("glpi_plugin_mantis_userprefs")) {
4650
$query = "CREATE TABLE `glpi_plugin_mantis_userprefs` (
47-
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT,
48-
`users_id` int NOT NULL ,
49-
`followTask` int NOT NULL default '0',
50-
`followFollow` int NOT NULL default '0',
51-
`followAttachment` int NOT NULL default '0',
52-
`followTitle` int NOT NULL default '0',
53-
`followDescription` int NOT NULL default '0',
54-
`followCategorie` int NOT NULL default '0',
55-
`followLinkedItem` int NOT NULL default '0',
56-
UNIQUE KEY (`users_id`))";
51+
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
52+
`users_id` int {$default_key_sign} NOT NULL ,
53+
`followTask` int NOT NULL default '0',
54+
`followFollow` int NOT NULL default '0',
55+
`followAttachment` int NOT NULL default '0',
56+
`followTitle` int NOT NULL default '0',
57+
`followDescription` int NOT NULL default '0',
58+
`followCategorie` int NOT NULL default '0',
59+
`followLinkedItem` int NOT NULL default '0',
60+
PRIMARY KEY (`id`),
61+
UNIQUE KEY (`users_id`)
62+
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
5763
$DB->query($query) or die($DB->error());
5864
}
5965
}

0 commit comments

Comments
 (0)