Bläddra i källkod

#132 Finalized: do check if an attribute is missing in a view

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@430 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 år sedan
förälder
incheckning
44bbd7be22
2 ändrade filer med 74 tillägg och 13 borttagningar
  1. 56 10
      core/metamodel.class.php
  2. 18 3
      pages/ITopConsultant.php

+ 56 - 10
core/metamodel.class.php

@@ -2047,11 +2047,21 @@ abstract class MetaModel
 	public static function DBShowApplyForm($sRepairUrl, $sSQLStatementArgName, $aSQLFixes)
 	{
 		if (empty($sRepairUrl)) return;
-		if (count($aSQLFixes) == 0) return;
+
+		// By design, some queries might be blank, we have to ignore them
+		$aCleanFixes = array();
+		foreach($aSQLFixes as $sSQLFix)
+		{
+			if (!empty($sSQLFix))
+			{
+				$aCleanFixes[] = $sSQLFix;
+			}
+		}
+		if (count($aCleanFixes) == 0) return;
 
 		echo "<form action=\"$sRepairUrl\" method=\"POST\">\n";
-		echo "   <input type=\"hidden\" name=\"$sSQLStatementArgName\" value=\"".htmlentities(implode("##SEP##", $aSQLFixes))."\">\n";
-		echo "   <input type=\"submit\" value=\" Apply the changes (".count($aSQLFixes)." queries) \">\n";
+		echo "   <input type=\"hidden\" name=\"$sSQLStatementArgName\" value=\"".htmlentities(implode("##SEP##", $aCleanFixes))."\">\n";
+		echo "   <input type=\"submit\" value=\" Apply changes (".count($aCleanFixes)." queries) \">\n";
 		echo "</form>\n";
 	}
 
@@ -2160,9 +2170,12 @@ abstract class MetaModel
 			{
 				foreach ($aQueries as $sQuery)
 				{
-					//$aSQL[] = $sQuery;
-					// forces a refresh of cached information
-					CMDBSource::CreateTable($sQuery);
+					if (!empty($sQuery))
+					{
+						//$aSQL[] = $sQuery;
+						// forces a refresh of cached information
+						CMDBSource::CreateTable($sQuery);
+					}
 				}
 			}
 		}
@@ -2181,9 +2194,12 @@ abstract class MetaModel
 			{
 				foreach ($aQueries as $sQuery)
 				{
-					//$aSQL[] = $sQuery;
-					// forces a refresh of cached information
-					CMDBSource::CreateTable($sQuery);
+					if (!empty($sQuery))
+					{
+						//$aSQL[] = $sQuery;
+						// forces a refresh of cached information
+						CMDBSource::CreateTable($sQuery);
+					}
 				}
 			}
 		}
@@ -2441,8 +2457,38 @@ abstract class MetaModel
 		foreach (self::GetClasses('bizmodel') as $sClass)
 		{
 			$sView = "view_$sClass";
-			if (!CMDBSource::IsTable($sView))
+			if (CMDBSource::IsTable($sView))
 			{
+				// Check that the view is complete
+				//
+				$bIsComplete = true;
+				foreach(self::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
+				{
+					foreach($oAttDef->GetSQLExpressions() as $sSuffix => $sTrash)
+					{
+						$sCol = $sAttCode.$sSuffix;
+						if (!CMDBSource::IsField($sView, $sCol))
+						{
+							$bIsComplete = false;
+							$aErrors[$sClass][$sAttCode][] = "field '$sCol' could not be found in view '$sView'";
+							$aSugFix[$sClass][$sAttCode][] = "";
+						}
+					}
+				}
+				if (!$bIsComplete)
+				{
+					// Rework the view
+					//
+					$oFilter = new DBObjectSearch($sClass, '');
+					$sSQL = self::MakeSelectQuery($oFilter);
+					$aErrors[$sClass]['*'][] = "View '$sView' is currently not complete";
+					$aSugFix[$sClass]['*'][] = "ALTER VIEW `$sView` AS $sSQL";
+				}
+			}
+			else
+			{
+				// Create the view
+				//
 				$oFilter = new DBObjectSearch($sClass, '');
 				$sSQL = self::MakeSelectQuery($oFilter);
 				$aErrors[$sClass]['*'][] = "Missing view for class: $sClass";

+ 18 - 3
pages/ITopConsultant.php

@@ -380,9 +380,24 @@ function DisplayDBFormatIssues($aErrors, $aSugFix, $sRepairUrl = "", $sSQLStatem
 				if (!empty($sRepairUrl))
 				{
 					$aSQLFixes = array_merge($aSQLFixes, $aSugFix[$sClass][$sTarget]);
-					$sSQLFixes = implode('; ', $aSugFix[$sClass][$sTarget]);
-					$sUrl = "$sRepairUrl&$sSQLStatementArgName=".urlencode($sSQLFixes);
-					echo "<li>$sMsg (<a href=\"$sUrl\" title=\"".htmlentities($sSQLFixes)."\" target=\"_blank\">fix it now!</a>)</li>\n";
+					$aCleanFixes = array();
+					foreach($aSugFix[$sClass][$sTarget] as $sSQLFix)
+					{
+						if (!empty($sSQLFix))
+						{
+							$aCleanFixes[] = $sSQLFix;
+						}
+					}
+					if (count($aCleanFixes) > 0)
+					{
+						$sSQLFixes = implode('; ', $aCleanFixes);
+						$sUrl = "$sRepairUrl&$sSQLStatementArgName=".urlencode($sSQLFixes);
+						echo "<li>$sMsg (<a href=\"$sUrl\" title=\"".htmlentities($sSQLFixes)."\" target=\"_blank\">fix it now!</a>)</li>\n";
+					}
+					else
+					{
+						echo "<li>$sMsg</li>\n";
+					}
 				}
 				else
 				{