diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 4de06151eb..38440d17fe 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -662,6 +662,11 @@ abstract class AttributeDefinition return array(); } public function RequiresIndex() {return false;} + + public function RequiresFullTextIndex() + { + return false; + } public function CopyOnAllTables() {return false;} public function GetOrderBySQLExpressions($sClassAlias) @@ -5883,6 +5888,34 @@ class AttributeExternalField extends AttributeDefinition } + +/** + * Multi value list of tags + * + * @see TagSetFieldData + * @since 2.6 N°931 tag fields + */ +class AttributeTagSet extends AttributeString +{ + //TODO SQL type length (nb of tags per record, max tag length) + //TODO implement ?? + //TODO specific filters + public function RequiresIndex() + { + return true; + } + + public function RequiresFullTextIndex() + { + return true; + } + + public function IsNullAllowed() + { + return true; + } +} + /** * Map a varchar column to an URL (formats the ouput in HMTL) * diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 79ad701c65..06cd005eba 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -5065,6 +5065,7 @@ abstract class MetaModel $aTableInfo['Fields'][$sField]['used'] = true; $bIndexNeeded = $oAttDef->RequiresIndex(); + $bFullTextIndexNeeded = false; if (!$bIndexNeeded) { // Add an index on the columns of the friendlyname @@ -5073,6 +5074,13 @@ abstract class MetaModel $bIndexNeeded = true; } } + else + { + if ($oAttDef->RequiresFullTextIndex()) + { + $bFullTextIndexNeeded = true; + } + } $sFieldDefinition = "`$sField` $sDBFieldSpec"; if (!CMDBSource::IsField($sTable, $sField)) @@ -5092,21 +5100,32 @@ abstract class MetaModel if ($bIndexNeeded) { $aTableInfo['Indexes'][$sField]['used'] = true; - $aColumns = array($sField); - $aLength = self::DBGetIndexesLength($sClass, $aColumns, $aTableInfo); + $sIndexName = $sField; $sColumns = '`'.$sField.'`'; - if (!is_null($aLength[0])) + + if ($bFullTextIndexNeeded) { - $sColumns .= ' ('.$aLength[0].')'; - } - $aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` ADD INDEX `$sField` ($sColumns)"; - if ($bTableToCreate) - { - $aCreateTableItems[$sTable][] = "INDEX `$sField` ($sColumns)"; + $sIndexType = 'FULLTEXT INDEX'; } else { - $aAlterTableItems[$sTable][] = "ADD INDEX `$sField` ($sColumns)"; + $sIndexType = 'INDEX'; + $aColumns = array($sField); + $aLength = self::DBGetIndexesLength($sClass, $aColumns, $aTableInfo); + if (!is_null($aLength[0])) + { + $sColumns .= ' ('.$aLength[0].')'; + } + } + + $aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` ADD $sIndexType `$sIndexName` ($sColumns)"; + if ($bTableToCreate) + { + $aCreateTableItems[$sTable][] = "$sIndexType `$sIndexName` ($sColumns)"; + } + else + { + $aAlterTableItems[$sTable][] = "ADD $sIndexType `$sIndexName` ($sColumns)"; } } @@ -5119,12 +5138,24 @@ abstract class MetaModel $sAlterTableItemsAfterChange = ''; if ($bIndexNeeded) { - $aColumns = array($sField); - $aLength = self::DBGetIndexesLength($sClass, $aColumns, $aTableInfo); $aTableInfo['Indexes'][$sField]['used'] = true; + if ($bFullTextIndexNeeded) + { + $sIndexType = 'FULLTEXT INDEX'; + $aColumns = null; + $aLength = null; + } + else + { + $sIndexType = 'INDEX'; + $aColumns = array($sField); + $aLength = self::DBGetIndexesLength($sClass, $aColumns, $aTableInfo); + } + if (!CMDBSource::HasIndex($sTable, $sField, $aColumns, $aLength)) { + $sIndexName = $sField; $sColumns = '`'.$sField.'`'; if (!is_null($aLength[0])) { @@ -5134,16 +5165,11 @@ abstract class MetaModel $aErrors[$sClass][$sAttCode][] = "Foreign key '$sField' in table '$sTable' should have an index"; if (CMDBSource::HasIndex($sTable, $sField)) { - $aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` DROP INDEX `$sField`"; - $sSugFixAfterChange = "ALTER TABLE `$sTable` ADD INDEX `$sField` ($sColumns)"; - $aAlterTableItems[$sTable][] = "DROP INDEX `$sField`"; - $sAlterTableItemsAfterChange = "ADD INDEX `$sField` ($sColumns)"; - } - else - { - $sSugFixAfterChange = "ALTER TABLE `$sTable` ADD INDEX `$sField` ($sColumns)"; - $sAlterTableItemsAfterChange = "ADD INDEX `$sField` ($sColumns)"; + $aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` DROP INDEX `$sIndexName`"; + $aAlterTableItems[$sTable][] = "DROP INDEX `$sIndexName`"; } + $sSugFixAfterChange = "ALTER TABLE `$sTable` ADD $sIndexType `$sIndexName` ($sColumns)"; + $sAlterTableItemsAfterChange = "ADD $sIndexType `$sIndexName` ($sColumns)"; } } diff --git a/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml b/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml index 2145809d4e..2fc03de439 100755 --- a/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml +++ b/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml @@ -196,6 +196,9 @@ 0 0 + + tagfield + diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 714f6faaac..8aefdc5b2c 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -179,6 +179,9 @@ Operators:
'Core:FriendlyName-Label' => 'Full name', 'Core:FriendlyName-Description' => 'Full name', + + 'Core:AttributeTag' => 'Tags', + 'Core:AttributeTag+' => 'Tags', )); diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index b15a47e6e9..bb6ae6ae2f 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -540,6 +540,9 @@ Opérateurs :
'Core:FriendlyName-Label' => 'Nom complet', 'Core:FriendlyName-Description' => 'Nom complet', + 'Core:AttributeTag' => 'Taxon', + 'Core:AttributeTag+' => 'Taxon', + 'Change:ObjectCreated' => 'Elément créé', 'Change:ObjectDeleted' => 'Elément effacé', 'Change:ObjectModified' => 'Elément modifié',