Skip to content

Commit

Permalink
Item13322: Defer the onSave call until after -set
Browse files Browse the repository at this point in the history
The onSave handler should only be called after all -set processing has
been applied to the configuration. Otherwise it has an incomplete view
of the configuration.
  • Loading branch information
gac410 committed Mar 26, 2015
1 parent 2b217cb commit e3156df
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions core/lib/Foswiki/Configure/Wizards/Save.pm
Expand Up @@ -232,18 +232,6 @@ sub save {
while ( my ( $k, $v ) = each %{ $this->param('set') } ) {
my $spec = $root->getValueObject($k);

# If ONSAVE checking is specified, call the checker's onSave()
# routine. This could provide "cleanup" processing for example,
# when a configuration value is saved. It can modify the value
# being saved, such as to hash a password, but never modify other
# values.
if ( $spec && $spec->{ONSAVE} ) {
my $checker = Foswiki::Configure::Checker::loadChecker($spec);
if ( $checker && $checker->can('onSave') ) {
$checker->onSave( $reporter, $k, $v );
}
}

if ( defined $v ) {
$v =~ m/^(.*)$/s;
$v = $1; # untaint
Expand Down Expand Up @@ -277,6 +265,24 @@ sub save {
}
ASSERT( !$@, $@ ) if DEBUG;
}

# Second pass after processing all the -set parameters
# To do the onsave, procesing
while ( my ( $k, $v ) = each %{ $this->param('set') } ) {
my $spec = $root->getValueObject($k);

# If ONSAVE checking is specified, call the checker's onSave()
# routine. This could provide "cleanup" processing for example,
# when a configuration value is saved. It can modify the value
# being saved, such as to hash a password, but never modify other
# values.
if ( $spec && $spec->{ONSAVE} ) {
my $checker = Foswiki::Configure::Checker::loadChecker($spec);
if ( $checker && $checker->can('onSave') ) {
$checker->onSave( $reporter, $k, $v );
}
}
}
}

delete $Foswiki::cfg{ConfigurationFinished};
Expand Down

0 comments on commit e3156df

Please sign in to comment.