Changeset 13773


Ignore:
Timestamp:
01/21/12 01:49:56 (4 months ago)
Author:
GeorgeClark
Message:

Item9563: Refresh prefs cache b4 call afterSave

Prefs are cached, so any attempt to read changed topic preferences in
the afterSaveHandler fails because the cached values from before the
save are returned.

The simple fix appears to be to delete the preferences cache for the
object before dispatching the afterSaveHandler.

Updated unit tests to verify the issue.

There is stil some issue remaining - Foswiki::Func returns null
parameters when called in the afterSaveHandler.

Location:
branches/Release01x01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/UnitTestContrib/test/unit/PluginHandlerTests.pm

    r13729 r13773  
    152152    $Foswiki::cfg{Plugins}{ $this->{plugin_name} }{Module} = 
    153153      "Foswiki::Plugins::$this->{plugin_name}"; 
    154     $this->{session}->finish(); 
    155     $this->{session} = new Foswiki();    # default user 
     154    $this->createNewFoswikiSession(); 
    156155    eval "\$Foswiki::Plugins::$this->{plugin_name}::tester = \$this;"; 
    157156    $this->checkCalls( 1, 'initPlugin' ); 
     
    190189 
    191190    my $q = Foswiki::Func::getRequestObject(); 
    192     $this->{session}->finish(); 
    193     $this->{session} = new Foswiki( $Foswiki::cfg{GuestUserLogin}, $q ); 
     191    $this->createNewFoswikiSession( $Foswiki::cfg{GuestUserLogin}, $q ); 
    194192 
    195193    $this->makePlugin( 'saveHandlers', <<'HERE'); 
     
    216214    $tester->assert_str_equals('Wibble', $_[4]->get('WIBBLE')->{wibble}); 
    217215    $tester->assert_matches( qr/B4SAVE/, $_[0]); 
    218     Foswiki::Func::pushTopicContext( $this->{test_web}, 'Tropic' ); 
    219  
    220     #SMELL:  This fails due to cached preferences 
    221     #$tester->assert_str_equals( "AFTER", 
    222     #        $_[4]->getPreference("BLAH")); 
     216 
     217    $tester->assert_str_equals( "AFTER", 
     218            $_[4]->getPreference("BLAH")); 
    223219 
    224220    #SMELL:  And for some reason this returns null instead of either BEFORE or AFTER 
    225             #Foswiki::Func::getPreferencesValue("BLAH") ); 
     221    # Foswiki::Func::pushTopicContext( $this->{test_web}, 'Tropic' ); 
     222    # $tester->assert_str_equals( "AFTER", 
     223    #  Foswiki::Func::getPreferencesValue("BLAH") ); 
     224 
    226225    $called->{afterSaveHandler}++; 
    227226} 
     
    237236    $this->checkCalls( 1, 'afterSaveHandler' ); 
    238237 
     238    $this->createNewFoswikiSession(); # undef, $topicquery ); 
     239    Foswiki::Func::pushTopicContext( $this->{test_web}, 'Tropic' ); 
     240 
    239241    my $newMeta = 
    240242      Foswiki::Meta->load( $this->{session}, $this->{test_web}, "Tropic" ); 
     
    243245    $this->assert_str_equals( "AFTER",  $newMeta->getPreference("BLAH") ); 
    244246 
    245     #SMELL: Without this call, getPreferences returns BEFORE 
    246     Foswiki::Func::pushTopicContext( $this->{test_web}, 'Tropic' ); 
    247247    $this->assert_str_equals( "AFTER", 
    248248        Foswiki::Func::getPreferencesValue("BLAH") ); 
     
    687687HERE 
    688688 
    689     $this->{session}->finish(); 
     689    $this->createNewFoswikiSession(); 
    690690    $this->checkCalls( 1, 'finishPlugin' ); 
    691     $this->{session} = new Foswiki(); 
    692691} 
    693692 
  • branches/Release01x01/core/lib/Foswiki/Meta.pm

    r13769 r13773  
    19391939    if ( $plugins->haveHandlerFor('afterSaveHandler') ) { 
    19401940        my $text = $this->getEmbeddedStoreForm(); 
     1941        delete $this->{_preferences};  # Make sure handler has changed prefs 
    19411942        my $error = $signal ? $signal->{-text} : undef; 
    19421943        $plugins->dispatch( 'afterSaveHandler', $text, $this->{_topic}, 
Note: See TracChangeset for help on using the changeset viewer.