Item14823: Support expansion of arbitrary metadata in DBQUERY

pencil
Priority: Enhancement
Current State: No Action Required
Released In: n/a
Target Release:
Applies To: Extension
Component: DBCachePlugin
Branches:
Reported By: CrawfordCurrie
Waiting For: CrawfordCurrie
Last Change By: MichaelDaum
Plugins and contribs can register arbitrary metadata using Foswiki::Meta::registerMETA and this is then loaded by the DBCacheContrib. However there is currently no way to expand this metadata in the output of a DBQUERY. It would be fairly easy to extend $expand to support this e.g. %DBQUERY{"topic=~'DCS'" format="| $topic | $expand(META:WORKFLOW.name) |"}% This would then work with any registered third-party metadata.

The patch is straightforward:
diff --git a/data/System/DBCachePlugin.txt b/data/System/DBCachePlugin.txt
index 27f3020..c11cc3d 100644
--- a/data/System/DBCachePlugin.txt
+++ b/data/System/DBCachePlugin.txt
@@ -144,12 +144,13 @@ In its most basic form =$expand(Ref)= is identical to =$formfield(Ref)=. In addi
 =$expand()= can be used to refer to topic properties of related topics that can be reached from the current one using the '@' symbol. For example, if a topic A uses a form that contains a field named "Ref" and specifies a reference to 
 another topic B (by using its name) you can access the "Headline" in B from A using =$expand(@Ref.Headline)=.
 
-A formfield accessor can be a composed one using 'or' and 'and'. Example: =$expand(Name or Author)=
+A formfield accessor can be composed using 'or' and 'and'. Example: =$expand(Name or Author)=
 will expand to the value of the formfield "Name" if it exists and is non-empty and to the value 
 of the formfield "Author" otherwise. More valid examples:
    * =$expand(@Ref.Headline)=: headline of the referred topic
    * =$expand(Nr and '.')=: append a dot to the formfield value "Nr" if it exists
    * =$expand(Name or Author)=: expand to "Name" or "Author"
+   * =$expand(META:WORKFLOW.name)=: expand to the value of an attribute of non-standard metadata, in this case the workflow name. Works for all =META:= types except =TOPICINFO=, =CREATEINFO=, =TOPICMOVED=, =TOPICPARENT=, =FILEATTACHMENT=, =FORM=, =FIELD=, =PREFERENCE=, =VERSIONS=, and =COMMENT=
 
 A formfield accessor can be computed using <nop>TopicMarkup. If the string starts with '%',
 it is expanded and its result is taken as the real formfield accessor. This is useful when the 
diff --git a/lib/Foswiki/Plugins/DBCachePlugin/WebDB.pm b/lib/Foswiki/Plugins/DBCachePlugin/WebDB.pm
index 7c10570..449b26c 100644
--- a/lib/Foswiki/Plugins/DBCachePlugin/WebDB.pm
+++ b/lib/Foswiki/Plugins/DBCachePlugin/WebDB.pm
@@ -408,6 +408,11 @@ sub expandPath {
     return $result if (defined $result && $result ne '');
     return $this->expandPath($theRoot, $tail);
   }
+  if ($thePath =~ /^META:(\w+)\.(\w+)$/) {
+      my $data = $theRoot->fastget(lc($1));
+      return "" unless defined $data;
+      return $data->{keys}->{$2};
+  }
   if ($thePath =~ m/^(\w+)(.*)$/o) {
     my $first = $1;
     my $tail = $2;

Michael, let me know if you are OK with this. If so I will create a branch and commit it.

-- CrawfordCurrie - 19 Feb 2019

Actually these can already be accessed using

$expand(workflow.name)

-- MichaelDaum - 19 Feb 2019

I tried that, and it didn't work... hmmm. Will investigate further.

-- CrawfordCurrie - 19 Feb 2019

Right you are - I must have screwed up my test somwehere. Does that work for arbitrary META? If so, I'll just document it.

-- Main.CrawfordCurrie - 19 Feb 2019 - 10:11

Yes I think so. I some times use a ?cover=dbdump to check out what is currently cached as I forget it myself as well.

view.dbdump.tmpl:

%TMPL:INCLUDE{"viewplain"}%
%TMPL:DEF{"content"}%%DBDUMP%%TMPL:END%

-- MichaelDaum - 19 Feb 2019
 

ItemTemplate edit

Summary Support expansion of arbitrary metadata in DBQUERY
ReportedBy CrawfordCurrie
Codebase
SVN Range
AppliesTo Extension
Component DBCachePlugin
Priority Enhancement
CurrentState No Action Required
WaitingFor CrawfordCurrie
Checkins
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
masterCheckins
ItemBranchCheckins
Release02x01Checkins
Release02x00Checkins
Release01x01Checkins
Topic revision: r5 - 16 Apr 2019, 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