Skip to content

Commit

Permalink
Item9403: Don't preserve LocalSite.cfg if it's not usable. Save of an
Browse files Browse the repository at this point in the history
"insane" LocalSite.cfg will write a new file instead of merging the
changes into a bad file.  If the admin wants to recover the bad file,
edit it offline and then re-visit configure.

git-svn-id: http://svn.foswiki.org/trunk@8380 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jul 31, 2010
1 parent 71e6766 commit 5357acf
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 33 deletions.
17 changes: 10 additions & 7 deletions core/bin/configure
Expand Up @@ -575,6 +575,7 @@ sub _screenFeedback {
my $ui = _checkLoadUI( 'UPDATE', $root );
return '' unless $ui;

$ui->setInsane() if $insane;
$ui->commitChanges( $root, $valuer, \%updated );

undef $ui;
Expand Down Expand Up @@ -604,20 +605,22 @@ sub _screenFeedback {

# If this pass created the LocalSite.cfg, need to rerun the sanity check
# to re-establish that the configuration is valid
my $sanityStatement = '';
if ($badLSC) {
my $stub = new Foswiki::Configure::Item();

# This call will define $Foswiki::defaultCfg by loading .spec files
my $sanityUI =
Foswiki::Configure::UI::loadChecker( 'BasicSanity', $stub );

my $sanityStatement = $sanityUI->check();
$sanityStatement = $sanityUI->check();
$badLSC = $sanityUI->lscIsBad();
$insane = $sanityUI->insane();
}

# Pass control to the mainline configure screen, passing along the
# results of the save
_actionConfigure($contentTemplate);
_actionConfigure($sanityStatement . $contentTemplate);
}

# Invoked by "find more extensions" button in the Extensions section
Expand Down Expand Up @@ -713,15 +716,15 @@ sub _actionManageExtensions {
# This is the default screen
sub _actionConfigure {

my $saveMsgs;
my $messages;
# If coming from the save action, or insane, pick up the messages
if ($insane) {
$saveMsgs = "<h1>INTERNAL ERROR - PROCEED WITH CAUTION</h1>";
$messages = "<h1>INTERNAL ERROR - PROCEED WITH CAUTION</h1>";
}
$saveMsgs .= shift;
$messages .= shift;

my $contents = '';
my $isFirstTime = $badLSC && !$insane;
my $isFirstTime = $badLSC;

#allow debugging of checker's guesses by showing the entire UI
$isFirstTime = 0 if ( $query->param('DEBUG') );
Expand Down Expand Up @@ -777,7 +780,7 @@ sub _actionConfigure {
return '' unless $ui;

# Set the save messages into the introduction panel if any.
$ui->lastSave($saveMsgs) if ($saveMsgs);
$ui->messages($messages) if ($messages);

# Visit the model and generate
$ui->{controls} = new Foswiki::Configure::GlobalControls();
Expand Down
15 changes: 7 additions & 8 deletions core/lib/Foswiki/Configure/Checkers/BasicSanity.pm
Expand Up @@ -94,7 +94,9 @@ Existing configuration file has a problem
that is causing a Perl error - the following message(s) was generated:
<pre>$@</pre>
You can continue, but configure will not pick up any of the existing
settings from this file unless you correct the perl error.
settings from this file and your previous configuration will be lost.
Manually edit and correct your <tt>$this->{LocalSiteDotCfg}</tt> file if you
wish to preserve your prior configuration.
HERE
$this->{badLSC} = 1;
}
Expand All @@ -114,8 +116,10 @@ The existing configuration file
$this->{LocalSiteDotCfg} doesn't seem to contain a good configuration
for Foswiki. The following problems were found:<br>
$mess
You are recommended to repair these problems manually, or delete
$this->{LocalSiteDotCfg} and start the configuration process again.
You can continue, but configure will not pick up any of the existing
settings from this file and your previous configuration will be lost.
Manually edit and correct your <tt>$this->{LocalSiteDotCfg}</tt> file if you
wish to preserve your prior configuration.
HERE
}

Expand All @@ -138,11 +142,6 @@ HERE
else {
$result .= <<HERE;
Could not find existing configuration file <code>$this->{LocalSiteDotCfg}</code>.
<h3>Are you running configure for the first time?</h3>
Please fill in the required paths in the
'General path settings' section and click 'Save changes' to save before returning to configure to complete configuration.
<h3>Did you save the configuration before?</h3>
Please check for the existence of <code>lib/LocalSite.cfg</code>, and make sure the webserver user can read it.
HERE
$this->{badLSC} = 1;
}
Expand Down
8 changes: 5 additions & 3 deletions core/lib/Foswiki/Configure/FoswikiCfg.pm
Expand Up @@ -320,18 +320,19 @@ sub _pusht {

=begin TML
---++ StaticMethod save($root, $valuer, $logger)
---++ StaticMethod save($root, $valuer, $logger, $insane)
* $root is a Foswiki::Configure::Root
* $valuer is a Foswiki::Configure::Valuer
* $logger an object that implements a logChange($keys,$value) method,
called to record the changes.
* $insane set to true if existing LocalSite.cfg should be overwritten
Generate .cfg file format output
=cut

sub save {
my ( $root, $valuer, $logger ) = @_;
my ( $root, $valuer, $logger, $insane ) = @_;

# Object used to act as a visitor to hold the output
my $this = new Foswiki::Configure::FoswikiCfg();
Expand All @@ -348,7 +349,8 @@ sub save {
$lsc =~ s/Foswiki\.spec/LocalSite.cfg/;
}

if ( open( F, '<', $lsc ) ) {
if ( !$insane && -f $lsc ) {
open( F, '<', $lsc );
local $/ = undef;
$this->{content} = <F>;
close(F);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/UIs/Introduction.pm
Expand Up @@ -21,7 +21,7 @@ our @ISA = ('Foswiki::Configure::UIs::Section');
sub renderHtml {
my ( $this, $section, $root ) = @_;

my $saveMsgs = $root->lastSave();
my $messages = $root->messages();
my $parser = Foswiki::Configure::TemplateParser->new;
my $contents = $parser->getResource(
'intro.html',
Expand All @@ -30,7 +30,7 @@ sub renderHtml {
SCRIPTURLPATH => $Foswiki::cfg{ScriptUrlPath},
SCRIPTSUFFIX => $Foswiki::cfg{ScriptSuffix},
ADMINGROUP => $Foswiki::cfg{SuperAdminGroup},
LASTSAVE => $saveMsgs
MESSAGES => $messages
);

# do not simply return the contents as we want to have
Expand Down
18 changes: 9 additions & 9 deletions core/lib/Foswiki/Configure/UIs/Root.pm
Expand Up @@ -32,28 +32,28 @@ sub new {

my $this = $class->SUPER::new(@_);
$this->{tabs} = [];
$this->{lastsave} =
''; # Set to contain the results of the prior save, for display on next iteration
$this->{message} =
''; # Set to contain the results of the prior save, or other messages to display on next iteration

return $this;
}

=begin TML
---++ ObjectMethod lastSave($msg)
---++ ObjectMethod messages($message)
Set and retrieve the save results from the previous save operation.
Set and retrieve the messages from the previous operation. Also passes through sanity errors.
If called with a message, sets and returns the message, otherwise just returns the message
=cut

sub lastSave {
my ( $this, $savemsg ) = @_;
if (defined $savemsg && $savemsg ) {
$this->{lastsave} = $savemsg;
sub messages {
my ( $this, $message ) = @_;
if (defined $message && $message ) {
$this->{message} = $message;
}
return $this->{lastsave};
return $this->{message};
}

=begin TML
Expand Down
16 changes: 15 additions & 1 deletion core/lib/Foswiki/Configure/UIs/UPDATE.pm
Expand Up @@ -19,6 +19,20 @@ our @ISA = ('Foswiki::Configure::UI');

use Foswiki::Configure::FoswikiCfg ();

my $insane; # Set if existing config is not usable.

=begin TML
---++ ObjectMethod setInsane()
Set status to insane if existing configuration is not usable
=cut

sub setInsane {
$insane = 1;
}

=begin TML
---++ ObjectMethod commitChanges()
Expand All @@ -42,7 +56,7 @@ sub commitChanges {
$this->{addr} = $Foswiki::query->remote_addr() || $ENV{REMOTE_ADDR} || '';

# Pass ourselves as log listener
Foswiki::Configure::FoswikiCfg::save( $root, $valuer, $this );
Foswiki::Configure::FoswikiCfg::save( $root, $valuer, $this, $insane );

if ( $this->{log} && defined( $Foswiki::cfg{Log}{Dir} ) ) {

Expand Down
4 changes: 3 additions & 1 deletion core/lib/Foswiki/Configure/UIs/Welcome.pm
Expand Up @@ -21,14 +21,16 @@ our @ISA = ('Foswiki::Configure::UIs::Section');
sub renderHtml {
my ( $this, $section, $root ) = @_;

my $messages = $root->messages();
my $parser = Foswiki::Configure::TemplateParser->new;
my $contents = $parser->getResource(
'welcome.html',
SYSTEMWEB => $Foswiki::cfg{SystemWebName},
USERSWEB => $Foswiki::cfg{UsersWebName},
SCRIPTURLPATH => $Foswiki::cfg{ScriptUrlPath},
SCRIPTSUFFIX => $Foswiki::cfg{ScriptSuffix},
ADMINGROUP => $Foswiki::cfg{SuperAdminGroup}
ADMINGROUP => $Foswiki::cfg{SuperAdminGroup},
MESSAGES => $messages
);

# do not simply return the contents as we want to have
Expand Down
3 changes: 1 addition & 2 deletions core/lib/Foswiki/Configure/resources/intro.html
@@ -1,5 +1,4 @@
%LASTSAVE%

%MESSAGES%
%INCLUDE{legend.html}%

<h3>If your Foswiki site is already working</h3>
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Configure/resources/welcome.html
@@ -1,3 +1,4 @@
%MESSAGES%
%INCLUDE{legend.html}%

<h3>Is this your first visit to Configure?</h3>
Expand Down

0 comments on commit 5357acf

Please sign in to comment.