N°3712 - Activity panel: Fix origin icon for log entries

This commit is contained in:
Molkobain
2021-08-27 17:18:13 +02:00
parent cf556de76e
commit 6700de097a

View File

@@ -78,12 +78,42 @@ class ActivityPanelFactory
$oActivityPanel->SetCaseLogTabEntryForm($sCaseLogAttCode, CaseLogEntryFormFactory::MakeForCaselogTab($oObject, $sCaseLogAttCode, $sMode));
}
// Retrieve case logs entries
// Retrieve CMDBChange of the log entries to find their origins
//
// IMPORTANT: We don't have an easy way to find a log entry's origin, so we have to cross it with the corresponding CMDBChange
// The following code is an attempt to do so, but it might not be bulletproof against missing CMDBChanges or future code evolutions
$oCaseLogEntriesOriginsSearch = DBObjectSearch::FromOQL('SELECT C, CO FROM CMDBChange AS C JOIN CMDBChangeOpSetAttributeCaseLog AS CO ON CO.change = C.id WHERE CO.objclass = :objclass AND CO.objkey = :objkey AND CO.attcode = :attcode');
$oCaseLogEntriesOriginsSearch->SetInternalParams([
'objclass' => $sObjClass,
'objkey' => $sObjId,
'attcode' => $sCaseLogAttCode,
]);
// - Results must be in the same order as the entries in the ormCaseLog (otherwise we would need to loop over the set to find the matching index, which would not be efficient)
$oCaseLogEntriesOriginsSet = new DBObjectSet($oCaseLogEntriesOriginsSearch, ['date' => false]);
$oCaseLogEntriesOriginsSet->OptimizeColumnLoad(['C' => ['origin'], 'CO' => ['lastentry']]);
// Retrieve log entries
/** @var \ormCaseLog $oCaseLog */
$oCaseLog = $oObject->Get($sCaseLogAttCode);
// Debug message to help understand why there could be anomalies on the log entries origins
if ($oCaseLog->GetEntryCount() !== $oCaseLogEntriesOriginsSet->Count()) {
IssueLog::Debug(static::class.": Number of log entries ({$oCaseLog->GetEntryCount()}) don't match number of corresponding CMDBChanges ({$oCaseLogEntriesOriginsSet->Count()}) for object {$sObjClass}::{$sObjId} / attribute {$sCaseLogAttCode}");
}
$iCurrentEntryIndex = $oCaseLog->GetLatestEntryIndex();
foreach ($oCaseLog->GetAsArray() as $aOrmEntry) {
$oCaseLogEntry = ActivityEntryFactory::MakeFromCaseLogEntryArray($sCaseLogAttCode, $aOrmEntry);
// Try to set the origin, only if we have the corresponding data
$aChangeRow = $oCaseLogEntriesOriginsSet->FetchAssoc();
if (($aChangeRow !== null) && ($aChangeRow['CO']->Get('lastentry') === $iCurrentEntryIndex)) {
$oCaseLogEntry->SetOrigin($aChangeRow['C']->Get('origin'));
}
$oActivityPanel->AddEntry($oCaseLogEntry);
$iCurrentEntryIndex--;
}
}