Parcourir la source

N.755 (reduces the impact) Core API: Fixed the merging of several entries into a case log (calling several times DBObject::Set for a case log). The previous implementation did not work at all, leaving the data structure inconsistent. Moreover, the last text given is now inserted AFTER the text it is merged with (not on top of it) like in a normal text stream.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4657 a333f486-631f-4898-b8df-5754b55c2be0
romainq il y a 8 ans
Parent
commit
429054bf3a
1 fichiers modifiés avec 21 ajouts et 40 suppressions
  1. 21 40
      core/ormcaselog.class.inc.php

+ 21 - 40
core/ormcaselog.class.inc.php

@@ -519,49 +519,30 @@ class ormCaseLog {
 		if ($this->m_bModified)
 		{
 			$aLatestEntry = end($this->m_aIndex);
-			if ($aLatestEntry['user_name'] != $sOnBehalfOf)
+			if ($aLatestEntry['user_name'] == $sOnBehalfOf)
 			{
-				$bMergeEntries = false;
-			}
-			else
-			{
-				$bMergeEntries = true;
+				// Append the new text to the previous one
+				$sPreviousText = substr($this->m_sLog, $aLatestEntry['separator_length'], $aLatestEntry['text_length']);
+				$sText = $sPreviousText."\n".$sText;
+
+				// Cleanup the previous entry
+				array_pop($this->m_aIndex);
+				$this->m_sLog = substr($this->m_sLog, $aLatestEntry['separator_length'] + $aLatestEntry['text_length']);
 			}
 		}
-		
-		if ($bMergeEntries)
-		{
-			$aLatestEntry = end($this->m_aIndex);
-			$this->m_sLog = substr($this->m_sLog, $aLatestEntry['separator_length']);
-			$sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
-			$iSepLength = strlen($sSeparator);
-			$iTextlength = strlen($sText."\n");
-			$this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
-			$this->m_aIndex[] = array(
-				'user_name' => $sOnBehalfOf,	
-				'user_id' => $iUserId,	
-				'date' => time(),	
-				'text_length' => $aLatestEntry['text_length'] + $iTextlength,	
-				'separator_length' => $iSepLength,
-				'format' => 'html',	
-			);
-			
-		}
-		else
-		{
-			$sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
-			$iSepLength = strlen($sSeparator);
-			$iTextlength = strlen($sText);
-			$this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
-			$this->m_aIndex[] = array(
-				'user_name' => $sOnBehalfOf,	
-				'user_id' => $iUserId,	
-				'date' => time(),	
-				'text_length' => $iTextlength,	
-				'separator_length' => $iSepLength,	
-				'format' => 'html',	
-			);
-		}
+
+		$sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
+		$iSepLength = strlen($sSeparator);
+		$iTextlength = strlen($sText);
+		$this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
+		$this->m_aIndex[] = array(
+			'user_name' => $sOnBehalfOf,
+			'user_id' => $iUserId,
+			'date' => time(),
+			'text_length' => $iTextlength,
+			'separator_length' => $iSepLength,
+			'format' => 'html',
+		);
 		$this->m_bModified = true;
 	}