Skip to content

Commit

Permalink
Item14237: Replaced initStage attribute with appStage context
Browse files Browse the repository at this point in the history
The context was previously initialized by it's prepapre method and was
referring cfg and _dispatcherAttrs attributes causing deep recursion if
used prior to completion of these objects.
  • Loading branch information
vrurg committed Jun 15, 2017
1 parent 4ecc404 commit c65ffff
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions core/lib/Foswiki/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,15 @@ has inUnitTestMode => (
},
);

# App init stage.
has initStage => ( is => 'rw', );
=begin TML
---++ Methods
=cut

=begin TML
---++ ClassMethod new([%parameters])
---+++ ClassMethod new([%parameters])
The following keys could be defined in =%parameters= hash:
Expand All @@ -353,19 +356,20 @@ sub BUILD {

for my $stNum ( 1 .. 2 ) {
$this->clear_cfg;
$this->initStage( 'readConfig' . $stNum );
$this->enterContext( appStage => 'readConfig' . $stNum );
unless ( $this->cfg->data->{isVALID} ) {
$this->cfg->bootstrapSystemSettings;
}
$this->initStage( 'loadExtensions' . $stNum );

$this->enterContext( appStage => 'loadExtensions' . $stNum );

# Reload extensions based on the configuration information.
$this->clear_extMgr;

$this->extMgr->initialize;
}

$this->initStage('postConfig');
$this->enterContext( appStage => 'postConfig' );

$this->callback('postConfig');

Expand Down Expand Up @@ -428,6 +432,21 @@ sub BUILD {
$this->_prepareDispatcher;
$this->_checkBootstrapStage2;

# Setup initial context.
my %context =
( %{ $this->_dispatcherAttrs->{context} // {} }, features2Context );

while ( my ( $ctx, $val ) = each %context ) {
$this->enterContext( $ctx, $val );
}

if ( $cfgData->{Password} ) {
$this->enterContext('admin_available');
}
if ( $this->engine->isa('Foswiki::Engine::CLI') ) {
$this->enterContext('command_line');
}

# Override user to be admin if no configuration exists.
# Do this really early, so that later changes in isBOOTSTRAPPING can't
# change Foswiki's behavior.
Expand Down Expand Up @@ -1443,17 +1462,7 @@ BOGUS

sub prepareContext {
my $this = shift;

my %context =
( %{ $this->_dispatcherAttrs->{context} // {} }, features2Context );

if ( $this->cfg->data->{Password} ) {
$context{admin_available} = 1;
}
if ( $this->engine->isa('Foswiki::Engine::CLI') ) {
$context{command_line} = 1;
}
return \%context;
return {};
}

sub prepareEngine {
Expand Down

0 comments on commit c65ffff

Please sign in to comment.