#!/usr/bin/perl -wT
#
# TWiki Collaboration Platform, http://TWiki.org/
#
# Copyright (C) 1999-2003 Peter Thoeny, peter@thoeny.com
#
# For licensing info read license.txt file in the TWiki root.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details, published at 
# http://www.gnu.org/copyleft/gpl.html

BEGIN {
    # Set library paths in @INC at compile time
    unshift @INC, '.';
    require 'setlib.cfg';
}

use TWiki;
use TWiki::Store;

my $debug;
if( $ENV{'DOCUMENT_ROOT'} ) {
    # Called from browser.
    # CODE_SMELL: Is this really a reliable way of detecting
    # a browser environment?
    use CGI;
    $query = new CGI;
    $debug = $query->param( 'debug' );
    print "Content-type: text/plain\n\n";
} else {
    $debug= ( @ARGV && $ARGV[0] eq "-d" );
}

main();

sub main
{
    TWiki::basicInitialize();

    print "Remove obsolete locks\n" if $debug;
    foreach $web ( TWiki::Store::getAllWebs() ) {
        if( TWiki::isWebName($web) ) {
            print "Process $web\n" if $debug;
            TWiki::Store::removeObsoleteTopicLocks( $web );
        }
    }
    print "Done\n" if $debug;
}
