lib/TWiki/Configure/UIs/UPDATE.pm
changeset 0 414e01d06fd5
equal deleted inserted replaced
-1:000000000000 0:414e01d06fd5
       
     1 #
       
     2 # TWiki Enterprise Collaboration Platform, http://TWiki.org/
       
     3 #
       
     4 # Copyright (C) 2000-2006 TWiki Contributors.
       
     5 #
       
     6 # This program is free software; you can redistribute it and/or
       
     7 # modify it under the terms of the GNU General Public License
       
     8 # as published by the Free Software Foundation; either version 2
       
     9 # of the License, or (at your option) any later version. For
       
    10 # more details read LICENSE in the root of this distribution.
       
    11 #
       
    12 # This program is distributed in the hope that it will be useful,
       
    13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
    15 #
       
    16 # As per the GPL, removal of this notice is prohibited.
       
    17 package TWiki::Configure::UIs::UPDATE;
       
    18 use base 'TWiki::Configure::UI';
       
    19 
       
    20 use strict;
       
    21 
       
    22 use TWiki::Configure::UI;
       
    23 use TWiki::Configure::TWikiCfg;
       
    24 
       
    25 sub ui {
       
    26     my ($this, $root, $valuer, $updated) = @_;
       
    27 
       
    28     $this->{changed} = 0;
       
    29     $this->{updated} = $updated;
       
    30 
       
    31     $this->{output} = CGI::h2('Updating configuration');
       
    32 
       
    33     my $logfile;
       
    34     $this->{log} = '';
       
    35     $this->{user} = '';
       
    36     if (defined $TWiki::query) {
       
    37         $this->{user} = $TWiki::query->remote_user() || '';
       
    38     }
       
    39 
       
    40     TWiki::Configure::TWikiCfg::save($root, $valuer, $this);
       
    41 
       
    42     if( $this->{log} &&
       
    43           defined( $TWiki::cfg{ConfigurationLogName} ) &&
       
    44             open(F, '>>'.$TWiki::cfg{ConfigurationLogName} )) {
       
    45         print F $this->{log};
       
    46         close(F);
       
    47     }
       
    48 
       
    49     # Put in a link to the front page of the TWiki
       
    50     my $url = "$TWiki::cfg{DefaultUrlHost}$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/";
       
    51     return $this->{output}.CGI::p().CGI::strong(
       
    52         'Setting ' . $this->{changed}.
       
    53           ' configuration item' . (($this->{changed} == 1) ? '' : 's').'.').
       
    54             CGI::p().
       
    55                 CGI::a({ href => $url}, "Go to the TWiki front page")." or ";
       
    56 }
       
    57 
       
    58 # Listener for when a saved configuration item is changed.
       
    59 sub logChange {
       
    60     my ($this, $keys, $value) = @_;
       
    61 
       
    62     if ($this->{updated}->{$keys}) {
       
    63         $this->{output} .= CGI::h3($keys).CGI::code($value);
       
    64         $this->{changed}++;
       
    65         $this->{log} .= '| '.gmtime().' | '.$this->{user}.' | '.$keys.' | '.
       
    66           $value," |\n";
       
    67     }
       
    68 }
       
    69 
       
    70 1;