Question
I have problem with saving of topics in my perl script.
reading of topics (no problem...) :
$text = TWiki::Func::ReadTopicText($web,$topic);
$text modified somehow...
and saving :
TWiki::Func::saveTopicText($web,$topic,$text,'1');
> Access to CHANGE ... for TwikiGuest ... is Denied
1) How twiki functions find out the name of user which operate with Twiki::func functions ? I anticipate that $session variable do this but i would like to see some pieces of code... how initialize $session in perl script ?
alternative -
2) Is possible use some Twiki function which is able to save topics and ignore permission settings (and using
RCS system) ?
This script will start every night and actualize some topics (user topics&groups - ldap synchronize, and topics on the Project web - synchronize some data from database etc..).
thank you
Environment
--
MartinVich - 30 Jan 2007
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.
If you can, then use the TWiki::Func API from the context of a plugin, which sets up the session for you.
If you are writing a stand-alone script, you can take inspiration from a range of Contribs that build sessions (such as
MailInContrib,
PublishContrib etc) or simply review the code of tick_twiki.pl in the
tools directory. The API of the Store module provides methods for reading and writing topics. However i strongly recommend you do not use internal APIs, as they are subject to change.
If you want to use TWiki::Func methods from a perl script, then you have to fool TWiki into thinking you are callling them from a Plugin. You can so this by setting $TWiki::Plugins::SESSION to point to the TWiki object, e.g.
my $session = new TWiki();
$TWiki::Plugins::SESSION = $session;
... can now call TWiki::Func methods ...
--
CrawfordCurrie - 21 Feb 2007
I got the same problem but for Twiki03. But can't do
my $session = new TWiki(); what tips do you have for me?
--
JonathanDorling - 22 Nov 2007
How about "upgrade to TWiki 4.0" (bet you saw that one coming

)
--
CrawfordCurrie - 24 Nov 2007
Closing this support question after more than 30 days of inactivity. Please feel free to re-open if needed.
--
PeterThoeny - 01 Jan 2008
If you want your external script to execute as if it was run by the authorized user you can initialize your session like this:
my $session = new TWiki( "TWikiName");
$TWiki::Plugins::SESSION = $session;
... can now call TWiki::Func methods ...
--
AndrewTutolmin - 24 Jan 2008