mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°931 new AttributeTag, handle field creation & update
SVN:trunk[6014]
This commit is contained in:
@@ -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)
|
||||
*
|
||||
|
||||
@@ -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)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,9 @@
|
||||
<count_min>0</count_min>
|
||||
<count_max>0</count_max>
|
||||
</field>
|
||||
<field id="tagfield" xsi:type="AttributeTagSet">
|
||||
<sql>tagfield</sql>
|
||||
</field>
|
||||
</fields>
|
||||
<methods>
|
||||
<method id="DBInsertNoReload">
|
||||
|
||||
@@ -179,6 +179,9 @@ Operators:<br/>
|
||||
|
||||
'Core:FriendlyName-Label' => 'Full name',
|
||||
'Core:FriendlyName-Description' => 'Full name',
|
||||
|
||||
'Core:AttributeTag' => 'Tags',
|
||||
'Core:AttributeTag+' => 'Tags',
|
||||
));
|
||||
|
||||
|
||||
|
||||
@@ -540,6 +540,9 @@ Opérateurs :<br/>
|
||||
'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é',
|
||||
|
||||
Reference in New Issue
Block a user