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