#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2005 by Open Source Technology Group. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$

use strict;
use File::Basename;
use Getopt::Std;
use Slash;
use Slash::Utility;
use Benchmark;

use vars qw( $slashdb $constants $junk );

(my $VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
my $PROGNAME = basename($0);

my %opts;
# Remember to doublecheck these match usage()!
usage('Options used incorrectly') unless getopts('hu:v', \%opts);
usage() if $opts{'h'};
version() if $opts{'v'};
$opts{'u'} ||= 'slash';

createEnvironment($opts{u});
$slashdb = getCurrentDB();
$constants = getCurrentStatic();


main();

sub main {
	my $sids = $slashdb->sqlSelectColArrayref('sid', 'stories');
	Slash::Utility::Anchor::getSkinColors();

	print "Updating " .  scalar(@$sids) ." \n";
	for my $sid (@$sids) {
		$slashdb->setStory($sid, { rendered => displayStory($sid,'', { force_cache_freshen => 1})});
	}
}


sub usage {
	print "*** $_[0]\n" if $_[0];
	# Remember to doublecheck these match getopts()!
	print <<EOT;

Usage: $PROGNAME [OPTIONS]

This utility rebuilds all of the rendered stories. If you change all of your template designs for your index you will probably want to run this.

Main options:
	-h	Help (this message)
	-v	Version
	-u	Virtual user (default is "slash")

EOT
	exit;
}


sub version {
	print <<EOT;

$PROGNAME $VERSION

This code is a part of Slash, and is released under the GPL.
Copyright 1997-2005 by Open Source Technology Group. See README
and COPYING for more information, or see http://slashcode.com/.

EOT
	exit;
}

__END__
