N°5900 - DB integrity analysis crashes when too many errors - limit the results to 100 to avoid memory errors

This commit is contained in:
Eric Espie
2023-01-19 08:51:02 +01:00
parent 9dc54d6e4c
commit f75a51d59e
6 changed files with 25 additions and 4 deletions

View File

@@ -21,6 +21,8 @@ use Combodo\iTop\Core\MetaModel\HierarchicalKey;
class DatabaseAnalyzer
{
const LIMIT = 100;
var $iTimeLimitPerOperation;
public function __construct($iTimeLimitPerOperation = null)
@@ -45,7 +47,7 @@ class DatabaseAnalyzer
set_time_limit(intval($this->iTimeLimitPerOperation));
}
$aWrongRecords = CMDBSource::QueryToArray($sSelWrongRecs);
$aWrongRecords = CMDBSource::QueryToArray($sSelWrongRecs.' limit '.self::LIMIT);
if (count($aWrongRecords) > 0)
{
foreach($aWrongRecords as $aRes)

View File

@@ -207,9 +207,13 @@ function DisplayErrorList($aResults)
foreach ($aResults as $sClass => $aErrorList) {
foreach ($aErrorList as $sErrorLabel => $aError) {
$iCount = $aError['count'];
if ($iCount === DatabaseAnalyzer::LIMIT) {
$iCount = "$iCount(+)";
}
$aRows[] = [
'class' => MetaModel::GetName($sClass).' ('.$sClass.')',
'count' => $aError['count'],
'count' => $iCount,
'error' => $sErrorLabel,
];
}
@@ -227,10 +231,19 @@ function DisplayErrorDetails($aResults, $bVerbose)
foreach ($aResults as $sClass => $aErrorList) {
foreach ($aErrorList as $sErrorLabel => $aError) {
$sErrorTitle = Dict::Format('DBTools:DetailedErrorTitle', MetaModel::GetName($sClass).' ('.$sClass.')', $aError['count'], $sErrorLabel);
$iCount = $aError['count'];
if ($iCount === DatabaseAnalyzer::LIMIT) {
$iCount = "$iCount(+)";
}
$sErrorTitle = Dict::Format('DBTools:DetailedErrorTitle', MetaModel::GetName($sClass).' ('.$sClass.')', $iCount, $sErrorLabel);
$oCollapsible = CollapsibleSectionUIBlockFactory::MakeStandard($sErrorTitle);
$oBlock->AddSubBlock($oCollapsible);
if ($aError['count'] === DatabaseAnalyzer::LIMIT) {
$oHTML = new Combodo\iTop\Application\UI\Base\Component\Html\Html('<p>'.Dict::format('DBTools:DetailedErrorLimit', DatabaseAnalyzer::LIMIT).'</p>');
$oCollapsible->AddSubBlock($oHTML);
}
$oFieldSet = FieldSetUIBlockFactory::MakeStandard(Dict::S('DBTools:SQLquery'));
$oCollapsible->AddSubBlock($oFieldSet);

View File

@@ -49,6 +49,7 @@ Dict::Add('EN US', 'English', 'English', array(
'DBTools:Inconsistencies' => 'Database inconsistencies',
'DBTools:DetailedErrorTitle' => '%2$s error(s) in class %1$s: %3$s',
'DBTools:DetailedErrorLimit' => 'List limited to %1$s errors',
'DBAnalyzer-Integrity-OrphanRecord' => 'Orphan record in `%1$s`, it should have its counterpart in table `%2$s`',
'DBAnalyzer-Integrity-InvalidExtKey' => 'Invalid external key %1$s (column: `%2$s.%3$s`)',

View File

@@ -44,6 +44,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
'DBTools:Inconsistencies' => 'Incohérences de base de données',
'DBTools:DetailedErrorTitle' => '%2$s erreur(s) dans la classe %1$s : %3$s',
'DBTools:DetailedErrorLimit' => 'Liste limitée à %1$s erreurs',
'DBAnalyzer-Integrity-OrphanRecord' => 'Enregistrement orphelin dans `%1$s`, il devrait avoir son équivalent dans la table `%2$s`',
'DBAnalyzer-Integrity-InvalidExtKey' => 'Clé externe invalide %1$s (colonne: `%2$s.%3$s`)',

View File

@@ -24,7 +24,7 @@
/** @noinspection PhpUnhandledExceptionInspection */
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'combodo-db-tools/3.0.2',
'combodo-db-tools/3.0.3',
array(
// Identification
//

View File

@@ -8,6 +8,7 @@
namespace Combodo\iTop\DBTools\Service;
use CoreException;
use DatabaseAnalyzer;
use Dict;
use DictExceptionMissingString;
use MetaModel;
@@ -38,6 +39,9 @@ class DBAnalyzerUtils
fwrite($fReport, "\r\n-- \r\n");
fwrite($fReport, '-- Class: '.MetaModel::GetName($sClass).' ('.$sClass.")\r\n");
$iCount = $aError['count'];
if ($iCount === DatabaseAnalyzer::LIMIT) {
$iCount = "$iCount(+)";
}
fwrite($fReport, '-- Count: '.$iCount."\r\n");
fwrite($fReport, '-- Error: '.$sErrorLabel."\r\n");
if (array_key_exists('query', $aError)) {