Pārlūkot izejas kodu

Internal: detect unused columns while upgrading

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1535 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 gadi atpakaļ
vecāks
revīzija
363663d9c6
1 mainītis faili ar 12 papildinājumiem un 1 dzēšanām
  1. 12 1
      core/metamodel.class.php

+ 12 - 1
core/metamodel.class.php

@@ -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();