This question about Developing extensions (plugins skins etc.): Asked
Bram van Oosterhout
Item14848: fix invalid use of store api
Contained an extensive update of
TopicAgent including the following:
41 - $this->{dst} = $request->param('destination') || $this->{src};
42 - ($this->{dstWeb}, $this->{dstTopic}) = Foswiki::Func::normalizeWebTopicName($this->{baseWeb}, $this->{dst})
43 - unless defined $this->{dstWeb} && defined $this->{dstTopic};
37 + $this->{dstWeb} = $request->param("dstWeb") || $this->{baseWeb};
38 + $this->{dstTopic} = $request->param('destination') || $request->param("dstTopic") || $this->{src};
39 + ($this->{dstWeb}, $this->{dstTopic}) = Foswiki::Func::normalizeWebTopicName($this->{dstWeb}, $this->{dstTopic});
The old version
unless (line 43) is missing. This could be deliberate, but I suspect it is a oversight.
The omission causes unexpected results when
TopicAgent is invoked from another module with:
my $agent = new Foswiki::Contrib::CopyContrib::TopicAgent(
$this->{session},
srcWeb => $item->{web},
srcTopic => $item->{topic},
dstWeb => $this->{dstWeb},
dstTopic => $item->{target},
doClear => $this->{doClear},
dry => $this->{dry},
debug => $this->{debug},
);
The dstWeb and dstTopic parameters are ignored and replaced by their defaults.
I have patched my copy of
TopicAgent with:
diff --git a/lib/Foswiki/Contrib/CopyContrib/TopicAgent.pm b/lib/Foswiki/Contrib/CopyContrib/TopicAgent.pm
index 7b10c57..d26f309 100644
--- a/lib/Foswiki/Contrib/CopyContrib/TopicAgent.pm
+++ b/lib/Foswiki/Contrib/CopyContrib/TopicAgent.pm
@@ -34,8 +34,10 @@ sub parseRequestObject {
($this->{srcWeb}, $this->{srcTopic}) = Foswiki::Func::normalizeWebTopicName($this->{baseWeb}, $this->{src})
unless defined $this->{srcWeb} && defined $this->{srcTopic};
- $this->{dstWeb} = $request->param("dstWeb") || $this->{baseWeb};
- $this->{dstTopic} = $request->param('destination') || $request->param("dstTopic") || $this->{src};
+ $this->{dstWeb} = $request->param("dstWeb") || $this->{baseWeb}
+ unless defined $this->{dstWeb};
+ $this->{dstTopic} = $request->param('destination') || $request->param("dstTopic") || $this->{src}
+ unless defined $this->{dstTopic};
($this->{dstWeb}, $this->{dstTopic}) = Foswiki::Func::normalizeWebTopicName($this->{dstWeb}, $this->{dstTopic});
throw Error::Simple("invalid topic name")
And this restores the previous behaviour. If this has undesirable side effects, please let me know which ones. Otherwise, I can create a task and push the change.
--
BramVanOosterhout - 29 Aug 2020