Question
I would like to update the
DBIQueryPlugin for use in version 4.2 (the original author has stated that he does not have time to do this).
It is making some method calls which appear to be redundant in the latest version (E.g. 'findUser' method on the 'Users' object).
I have spent a couple of hours searching through the Plugins, Codev and TWiki webs to see if I can find guidelines about what is required to update a Plugins for the new version, but I've come up blank. The best I could find was the
Release Notes for version 4.2, but this still did not mention this specific problem (see
DBIQueryPluginDev).
I'm obviously searching for the wrong thing, so I'm hoping someone can point me to a relevant topic which discusses what's required.
Cheers.
Environment
--
DuncanKinnear - 18 Mar 2008
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
OK, I've done a bit more analysis of the
DBIQueryPlugin source code, and the only problem seems to be with a sub-routine for testing if a specified user is in a specified group. Here's the code snippet:
my $userObj = $TWiki::Plugins::SESSION->{users}->findUser($user);
return 0 unless defined $userObj;
return $userObj->isInList($group);
Where
$user
and
$group
are passed into the sub-routine.
Is there an easy way to do this with standard API methods? I could not see anything in
TWikiFuncDotPm that could do this.
--
DuncanKinnear - 18 Mar 2008
You can use
isGroupMember()
of
TWikiFuncDotPm, available since TWiki plugin API version 1.2.
It is good practice to use conditional code so that the plugin works on older and newer versions of TWiki. Untested example:
if( TWiki::Plugins::VERSION >= 1.2 ) {
return TWiki::Func::isGroupMember( $group );
} else {
my $userObj = $TWiki::Plugins::SESSION->{users}->findUser($user);
return 0 unless defined $userObj;
return $userObj->isInList($group);
}
--
PeterThoeny - 25 Apr 2008