mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
Internal: detect unused columns while upgrading
SVN:trunk[1535]
This commit is contained in:
@@ -3443,7 +3443,7 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
// Check that any defined field exists
|
||||
//
|
||||
$aTableInfo = CMDBSource::GetTableInfo($sTable);
|
||||
|
||||
$aTableInfo['Fields'][$sKeyField]['used'] = true;
|
||||
foreach(self::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
|
||||
{
|
||||
// Skip this attribute if not originaly defined in this class
|
||||
@@ -3451,6 +3451,9 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
|
||||
foreach($oAttDef->GetSQLColumns() as $sField => $sDBFieldType)
|
||||
{
|
||||
// Keep track of columns used by iTop
|
||||
$aTableInfo['Fields'][$sField]['used'] = true;
|
||||
|
||||
$bIndexNeeded = $oAttDef->RequiresIndex();
|
||||
$sFieldDefinition = "`$sField` ".($oAttDef->IsNullAllowed() ? "$sDBFieldType NULL" : "$sDBFieldType NOT NULL");
|
||||
if (!CMDBSource::IsField($sTable, $sField))
|
||||
@@ -3518,6 +3521,14 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Find out unused columns
|
||||
foreach($aTableInfo['Fields'] as $sField => $aFieldData)
|
||||
{
|
||||
if (!isset($aFieldData['used']) || !$aFieldData['used'])
|
||||
{
|
||||
$aErrors[$sClass]['*'][] = "Column '$sField' in table '$sTable' is not used";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aCondensedQueries = array();
|
||||
|
||||
Reference in New Issue
Block a user