Question
I'm writing a script (for TWiki 3.x) which will be run each month to generate some reports on user groups.
The first step in the process is to compile a list of all the Groups. I'm trying to use only the Func module, here's what I've got so far:
#!/usr/bin/perl
use TWiki;
print ".\n";
print &getListOfGroups;
sub getListOfGroups
{
my $text = &TWiki::Func::expandCommonVariables('%SEARCH{"GROUP" topic="*Group" casesensitive="on" nosummary="on" nosearch="on" nonoise="on" noheader="on" nototal="on" format="\$web.\$topic"}%');
my ( @list ) = split ( /\n/, $text );
return @list;
}
However, when I run this script, I receive the following error:
Can't call method "replacePreferencesTags" on an undefined value at TWiki/Prefs.pm line 672.
I tried adding
$TWiki::Plugins::SESSION = new TWiki();
which gives me
Can't locate object method "new" via package "TWiki" at ./UserVerificationEmailer.pl line 3.
Any ideas?
Thanks,
Brendan.
Environment
--
BrendanMarshall - 15 May 2007
Answer
If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.
You need the proper initialization. Look for example at the
bin/mailnotify script. Relevant part of Sep 2004 release:
BEGIN {
# Set library paths in @INC at compile time
unshift @INC, '.';
require 'setlib.cfg';
}
use TWiki;
TWiki::basicInitialize();
--
PeterThoeny - 15 May 2007
Thanks for the quick response Peter.
After adding the appropriate initialization, I unfortunately still have the same error. The code is now:
#!/usr/bin/perl
BEGIN {
# Set library paths in @INC at compile time
unshift @INC, '.';
require 'setlib.cfg';
}
use TWiki;
&TWiki::basicInitialize();
print &getListOfGroups;
sub getListOfGroups
{
my $text = &TWiki::Func::expandCommonVariables('%SEARCH{"GROUP" topic="*Group" casesensitive="on" nosummary="on" nosearch="on" nonoise="on" noheader="on" nototal="on" format="\$web.\$topic"}%');
my ( @list ) = split ( /\n/, $text );
return @list;
}
Error returned is:
Can't call method "replacePreferencesTags" on an undefined value at /var/www/html/twiki/lib/TWiki/Prefs.pm line 672.
--
BrendanMarshall - 16 May 2007
You might need to initialize it further. Again from
mailnotify:
my ( $topic, $webName, $dummy, $userName, $dataDir ) =
TWiki::initialize( "/Main", "nobody" );
--
PeterThoeny - 16 May 2007
Ah excellent it works now. Thanks for your help
--
BrendanMarshall - 16 May 2007