From ae000be2bc147d717c92dcb5e56d1ca6fd1ec570 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 26 Feb 2019 15:13:47 -0700 Subject: [PATCH] Instead of new and old values, store unified diff in database for multiline strings --- api/src/Storage/Tracking.php | 15 +++++++++++++++ composer.json | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/Storage/Tracking.php b/api/src/Storage/Tracking.php index 3ca3aa97ec..f539eaf951 100644 --- a/api/src/Storage/Tracking.php +++ b/api/src/Storage/Tracking.php @@ -18,6 +18,8 @@ use EGroupware\Api; // explicitly reference classes still in phpgwapi or otherwise outside api use notifications; +use Text_Diff_Renderer_unified; + /** * Abstract base class for trackering: * - logging all modifications of an entry @@ -451,6 +453,19 @@ abstract class Tracking $this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]); } } + else if (is_string($data[$name]) && is_string($old[$name]) && ( + strpos($data[$name], PHP_EOL) !== FALSE || strpos($old[$name], PHP_EOL) !== FALSE)) + { + // Multiline string, just store diff + $diff = new \Text_Diff('auto', array(explode("\n",$data[$name]), explode("\n",$old[$name]))); + $renderer = new \Text_Diff_Renderer_unified(); + $this->historylog->add( + $status, + $data[$this->id_field], + $renderer->render($diff), + '***diff***' + ); + } else { //error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]); diff --git a/composer.json b/composer.json index 2f46c925d4..fdf33590f6 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,8 @@ "egroupware/tracker": "self.version", "egroupware/z-push-dev": "self.version", "egroupware/activesync": "self.version", - "egroupware/adodb-php": "self.version" + "egroupware/adodb-php": "self.version", + "pear-pear.horde.org/Horde_Text_Diff": "^2.2" }, "require-dev": { },