Tags:
create new tag
, view all tags

Question

I am developing a plugin. Started on TWiki 4x0x2. Got it to work. See: SoYouWantToWriteAPlugin.

Upgraded to TWiki 4x1x2 and now it fails.

Sample code:

     # SMELL: need a new prefs object for each topic
      my $wikiName = 'TWikiGuest';
    my $twiki = $TWiki::Plugins::SESSION;
    $twiki->{prefs} = new TWiki::Prefs($twiki);
    $twiki->{prefs}->pushGlobalPreferences();
    $twiki->{prefs}->pushPreferences($TWiki::cfg{UsersWebName}, $wikiName, 'USER '.$wikiName);
    $twiki->{prefs}->pushWebPreferences($prefs{'web'});
    $twiki->{prefs}->pushPreferences($prefs{'web'}, $prefs{'topic'}, 'TOPIC');
    $twiki->{prefs}->pushPreferenceValues('SESSION', $twiki->{client}->getSessionValues());
#BvO  I think it fails here                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
  $page = TWiki::Func::expandCommonVariables($page, $topic, $prefs{'web'});
  $page = TWiki::Func::renderText($page, $prefs{'web'});

Error reported is:

Can't call method "getSessionValues" on an undefined value...

I don't understand what value is undefined, let alone how to define it or work around.

Since I don't understand what this code does, and I believe it wil be superceeded in release 4.2. should I just give up and go back to TWiki 4x0x2. Or is there a way to fix this.

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: debian(Unix) Debian GNU/Linux
Web server: Apache/1.3.27
Perl version: 5.008004 (linux)
Client OS: Windows Xp
Web Browser: Firefox 1.5
Categories: Fatal error, Plugins

-- BramVanOosterhout - 01 Jul 2007

Answer

ALERT! 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.

I reread my notes in SoYouWantToWriteAPlugin and saw that I had noted a change in PublishContrib. I did not understand what it did. But "desperate times ask for desperate measures". So I used SvenDowideit 's code slightly modified.

######### Replace this lot by the latest implementation in PublishContrib  
#     # SMELL: need a new prefs object for each topic
#      my $wikiName = 'TWikiGuest';
#    my $twiki = $TWiki::Plugins::SESSION;
#    $twiki->{prefs} = new TWiki::Prefs($twiki);
#    $twiki->{prefs}->pushGlobalPreferences();
#    $twiki->{prefs}->pushPreferences($TWiki::cfg{UsersWebName}, $wikiName, 'USER '.$wikiName);
#    $twiki->{prefs}->pushWebPreferences($prefs{'web'});
#    $twiki->{prefs}->pushPreferences($prefs{'web'}, $prefs{'topic'}, 'TOPIC');
#    $twiki->{prefs}->pushPreferenceValues('SESSION', $twiki->{client}->getSessionValues());
#---------------------------------------------------
    # clone the current session
    my $oldTWiki = $TWiki::Plugins::SESSION;

    # Create a new TWiki so that the contexts are correct. This is really,
    # really inefficient, but is essential at the moment to maintain correct
    # prefs
    my $query = $oldTWiki->{cgiQuery};
    $query->param('topic', "$prefs{'web'}.$topic");
    my $twiki = new TWiki('TWikiGuest', $query);
    $TWiki::Plugins::SESSION = $twiki;
##########   end replace
##########   note the restore twiki object four lines down  


  $page = TWiki::Func::expandCommonVariables($page, $topic, $prefs{'web'});
  $page = TWiki::Func::renderText($page, $prefs{'web'});
# do it twice, in case the rendering defines more variables
  $page = TWiki::Func::expandCommonVariables($page, $topic, $prefs{'web'});
  $page = TWiki::Func::renderText($page, $prefs{'web'});
  
  $TWiki::Plugins::SESSION = $oldTWiki; # restore twiki object
And now the script works again. As Sven notes, the solution is not fast: 4 minutes to render 800 pages (0.3 second per page). It was under .1s/page in 4.0.2. But it works. And, I have achieved my objective to eliminate all dependencies on undocumented API calls.

Thanks to SvenDowideit , for putting the solution together.

If there are no simple suggestions to improve the performance, you may close this question. I will also update my comments in SoYouWantToWriteAPlugin.

-- BramVanOosterhout - 03 Jul 2007

Seems to be answered. On performance see other Tag:performance topics. The VarCachePlugin might help.

-- PeterThoeny - 12 Aug 2007

 
Change status to:
Topic revision: r3 - 2007-08-12 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.