瀏覽代碼

Improved the upgrade/toolkit: make sure that NULL is allowed for SQL columns found in the DB but not defined in the data model (attribute removed or renamed)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1637 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 年之前
父節點
當前提交
1d75dd2c3f
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      core/metamodel.class.php

+ 9 - 0
core/metamodel.class.php

@@ -3522,11 +3522,20 @@ 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";
+					if (!CMDBSource::IsNullAllowed($sTable, $sField))
+					{
+						// Allow null values so that new record can be inserted
+						// without specifying the value of this unknown column
+						$sFieldDefinition = "`$sField` ".CMDBSource::GetFieldType($sTable, $sField).' NULL';
+						$aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` CHANGE `$sField` $sFieldDefinition";
+						$aAlterTableItems[$sTable][$sField] = "CHANGE `$sField` $sFieldDefinition";
+					}
 				}
 			}
 		}