mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 13:08:45 +02:00
N°3712 - Activity panel: Fix origin icon for log entries
This commit is contained in:
@@ -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--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user