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

SVN:trunk[430]
This commit is contained in:
Romain Quetiez
2010-06-04 16:23:18 +00:00
parent d115022132
commit 65eb567f63
2 changed files with 74 additions and 13 deletions

View File

@@ -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";

View File

@@ -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
{