Just send unified diff to client, not full old & new value

This commit is contained in:
nathangray 2019-02-27 09:03:28 -07:00
parent ae000be2bc
commit 39e7820520

View File

@ -260,6 +260,17 @@ class History
$row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]);
}
}
if ($row['history_old_value'] !== Tracking::DIFF_MARKER && (
$this->needs_diff($row['history_status'], $row['history_old_value']) ||
$this->needs_diff($row['history_status'], $row['history_old_value'])
))
{
// Larger text stored with full old / new value - calculate diff and just send that
$diff = new \Text_Diff('auto', array(explode("\n",$row['history_new_value']), explode("\n",$row['history_old_value'])));
$renderer = new \Text_Diff_Renderer_unified();
$row['history_new_value'] = $renderer->render($diff);
$row['history_old_value'] = Tracking::DIFF_MARKER;
}
// Get information needed for proper display
if($row['history_appname'] == 'filemanager')
{
@ -297,4 +308,10 @@ class History
return $total;
}
protected function needs_diff($name, $value)
{
return $name == 'note' || $name == 'description' ||
($value && (strlen($value) > 50 || strstr($value, "\n") !== FALSE));
}
}