lib/TWiki/Configure/UIs/UPDATE.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Configure/UIs/UPDATE.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +#
     1.5 +# TWiki Enterprise Collaboration Platform, http://TWiki.org/
     1.6 +#
     1.7 +# Copyright (C) 2000-2006 TWiki Contributors.
     1.8 +#
     1.9 +# This program is free software; you can redistribute it and/or
    1.10 +# modify it under the terms of the GNU General Public License
    1.11 +# as published by the Free Software Foundation; either version 2
    1.12 +# of the License, or (at your option) any later version. For
    1.13 +# more details read LICENSE in the root of this distribution.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.18 +#
    1.19 +# As per the GPL, removal of this notice is prohibited.
    1.20 +package TWiki::Configure::UIs::UPDATE;
    1.21 +use base 'TWiki::Configure::UI';
    1.22 +
    1.23 +use strict;
    1.24 +
    1.25 +use TWiki::Configure::UI;
    1.26 +use TWiki::Configure::TWikiCfg;
    1.27 +
    1.28 +sub ui {
    1.29 +    my ($this, $root, $valuer, $updated) = @_;
    1.30 +
    1.31 +    $this->{changed} = 0;
    1.32 +    $this->{updated} = $updated;
    1.33 +
    1.34 +    $this->{output} = CGI::h2('Updating configuration');
    1.35 +
    1.36 +    my $logfile;
    1.37 +    $this->{log} = '';
    1.38 +    $this->{user} = '';
    1.39 +    if (defined $TWiki::query) {
    1.40 +        $this->{user} = $TWiki::query->remote_user() || '';
    1.41 +    }
    1.42 +
    1.43 +    TWiki::Configure::TWikiCfg::save($root, $valuer, $this);
    1.44 +
    1.45 +    if( $this->{log} &&
    1.46 +          defined( $TWiki::cfg{ConfigurationLogName} ) &&
    1.47 +            open(F, '>>'.$TWiki::cfg{ConfigurationLogName} )) {
    1.48 +        print F $this->{log};
    1.49 +        close(F);
    1.50 +    }
    1.51 +
    1.52 +    # Put in a link to the front page of the TWiki
    1.53 +    my $url = "$TWiki::cfg{DefaultUrlHost}$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/";
    1.54 +    return $this->{output}.CGI::p().CGI::strong(
    1.55 +        'Setting ' . $this->{changed}.
    1.56 +          ' configuration item' . (($this->{changed} == 1) ? '' : 's').'.').
    1.57 +            CGI::p().
    1.58 +                CGI::a({ href => $url}, "Go to the TWiki front page")." or ";
    1.59 +}
    1.60 +
    1.61 +# Listener for when a saved configuration item is changed.
    1.62 +sub logChange {
    1.63 +    my ($this, $keys, $value) = @_;
    1.64 +
    1.65 +    if ($this->{updated}->{$keys}) {
    1.66 +        $this->{output} .= CGI::h3($keys).CGI::code($value);
    1.67 +        $this->{changed}++;
    1.68 +        $this->{log} .= '| '.gmtime().' | '.$this->{user}.' | '.$keys.' | '.
    1.69 +          $value," |\n";
    1.70 +    }
    1.71 +}
    1.72 +
    1.73 +1;