Skip to content

Commit

Permalink
Item9715: lets make the laskListener code actually do what the docco …
Browse files Browse the repository at this point in the history
…says - that way they can get topic versions other than HEAD

git-svn-id: http://svn.foswiki.org/trunk@11542 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Apr 25, 2011
1 parent 18ab939 commit 233febd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
76 changes: 38 additions & 38 deletions core/lib/Foswiki/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,43 @@ Construct a Store module.

sub new {
my $class = shift;




my $this = bless( { }, $class );
my $this = bless( {}, $class );
$this->_LoadAndRegisterListeners();

return $this;
}

#extracted so we can re-jig the list while running (for eg, non-optionally load a listener from code.
sub _LoadAndRegisterListeners {
my $this= shift;
my $this = shift;

# Create and register store listeners. Store listeners are subclasses
# of Foswiki::Store::Interfaces::Listener

my @evl;
foreach my $key (
sort {
$Foswiki::cfg{Store}{Listeners}{$a} <=>
$Foswiki::cfg{Store}{Listeners}{$b} } keys(%{$Foswiki::cfg{Store}{Listeners}})
) {
if ($Foswiki::cfg{Store}{Listeners}{$key}) {
#print STDERR "loading $key\n";
eval "require $key";
die "Failed to load $key: $@" if $@;
push(@evl, $key->new());
} else {
#don't try (and thus potentially crash on disabled listener
delete $Foswiki::cfg{Store}{Listeners}{$key};
}
sort {
$Foswiki::cfg{Store}{Listeners}{$a} <=> $Foswiki::cfg{Store}
{Listeners}{$b}
} keys( %{ $Foswiki::cfg{Store}{Listeners} } )
)
{
if ( $Foswiki::cfg{Store}{Listeners}{$key} ) {

#print STDERR "loading $key\n";
eval "require $key";
die "Failed to load $key: $@" if $@;
push( @evl, $key->new() );
}
else {

#don't try (and thus potentially crash on disabled listener
delete $Foswiki::cfg{Store}{Listeners}{$key};
}

$this->{event_listeners} = \@evl;
}

$this->{event_listeners} = \@evl;
}

=begin TML
Expand All @@ -117,16 +119,14 @@ allows you to enable/disable (set priority to 0) a new Listener, or to change it
=cut

sub setListenerPriority {
my $this = shift;
my $this = shift;
my $classname = shift;
my $priority = shift;
my $priority = shift;

$Foswiki::cfg{Store}{Listeners}{$classname} = $priority;
$this->_LoadAndRegisterListeners();
}



=begin TML
---++ ObjectMethod finish()
Expand All @@ -152,11 +152,11 @@ to the listener.
=cut

sub tellListeners {
my $this = shift;
my %arg = @_;
my $this = shift;
my %arg = @_;
my $event = $arg{verb};
foreach my $el (@{$this->{event_listeners}}) {

foreach my $el ( @{ $this->{event_listeners} } ) {
next unless $el->can($event);
$el->$event(%arg);
}
Expand All @@ -175,15 +175,15 @@ will not be asked.
=cut

sub askListeners {
my ($this, $meta) = @_;
my ($gotRev, $isLatest);
my ( $this, $meta, $version ) = @_;
my ( $gotRev, $isLatest );

foreach my $el (@{$this->{event_listeners}}) {
next unless $el->can('loadTopic');
($gotRev, $isLatest) = $el->loadTopic($meta);
return ($gotRev, $isLatest) if $gotRev;
foreach my $el ( @{ $this->{event_listeners} } ) {
next unless $el->can('loadTopic');
( $gotRev, $isLatest ) = $el->loadTopic($meta, $version);
return ( $gotRev, $isLatest ) if $gotRev;
}
return (undef, undef);
return ( undef, undef );
}

=begin TML
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Store/VC/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sub getHandler {
sub readTopic {
my ( $this, $topicObject, $version ) = @_;

my ( $gotRev, $isLatest ) = $this->askListeners($topicObject);
my ( $gotRev, $isLatest ) = $this->askListeners($topicObject, $version);

if ( defined($gotRev) and ( $gotRev > 0 ) ) {
return ( $gotRev, $isLatest );
Expand Down

0 comments on commit 233febd

Please sign in to comment.