Item14661: add newline parameter for compatibility with SEARCH

pencil
Priority: Enhancement
Current State: Closed
Released In: n/a
Target Release:
Applies To: Extension
Component: DBCachePlugin
Branches: master
Reported By: MichaelDaum
Waiting For:
Last Change By: MichaelDaum
By default %SEARCH translates any newline in a formfield to <br />. %DBQUERY does not so by default. The philosophy here is to return the data as is, not postprocessed automatically, as you may not want this in other cases. Problem is that %DBQUERY does not format multiline text formfields nicely in TML tables. An new parameter to %DBQUERY{ ... newline="<br />" } would solve this ... and ease converting %SEARCH to %DBQUERY considerably.

Hotfix:

diff --git a/lib/Foswiki/Plugins/DBCachePlugin/Core.pm b/lib/Foswiki/Plugins/DBCachePlugin/Core.pm
index 3183fe3..3dfe2c3 100644
--- a/lib/Foswiki/Plugins/DBCachePlugin/Core.pm
+++ b/lib/Foswiki/Plugins/DBCachePlugin/Core.pm
@@ -1,6 +1,6 @@
 # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 #
-# Copyright (C) 2005-2017 Michael Daum http://michaeldaumconsulting.com
+# Copyright (C) 2005-2018 Michael Daum http://michaeldaumconsulting.com
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -326,6 +326,7 @@ sub handleDBQUERY {
   my $theSkip = $params->{skip} || 0;
   my $theHideNull = Foswiki::Func::isTrue($params->{hidenull}, 0);
   my $theRemote = Foswiki::Func::isTrue($params->remove('remote'), 0);
+  my $theNewline = $params->{newline};
   my $doWarnings = Foswiki::Func::isTrue($params->{warn}, 1);
 
   $theFormat = '$topic' unless defined $theFormat;
@@ -431,19 +432,20 @@ sub handleDBQUERY {
       $line =~ s/\$formfield\((.*?)\)/
         my $temp = $theDB->getFormField($topicName, $1);
         $temp =~ s#\)#${TranslationToken}#g;
-      $temp/geo;
+        $temp =~ s#\r?\n#$theNewline#gs if defined $theNewline;
+        $temp/geo;

-- MichaelDaum - 15 Mar 2018

Thanks. I tested it successfully in our environment.

I found another section in the code in formatRecursive() which should perhaps be adapted as well for completeness. I don't know for sure, though:

   1135     # SMELL: copied from DBQUERY
   1136     $text =~ s/\$formfield\((.*?)\)/
   1137       my $temp = $theDB->getFormField($topicName, $1);
   1138       $temp =~ s#\)#${TranslationToken}#g;
   1139       $temp/geo;
   1140     $text =~ s/\$expand\((.*?)\)/
   1141       my $temp = $theDB->expandPath($topicObj, $1);
   1142       $temp =~ s#\)#${TranslationToken}#g;
   1143       $temp/geo;
   1144     $text =~ s/\$formatTime\((.*?)(?:,\s*'([^']*?)')?\)/_formatTime($theDB->expandPath($topicObj, $1), $2)/geo; # single quoted

-- TestUser333 - 15 Mar 2018
 
Topic revision: r3 - 28 May 2018, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy