#!/usr/bin/perl -w

use strict;
use Getopt::Long;

my ($MT_DIR);

BEGIN {
	$MT_DIR = '../../';
    unshift @INC, $MT_DIR . 'lib';
    unshift @INC, $MT_DIR . 'extlib';
}

use MT;

my $mt = MT->new( Config    => $MT_DIR . 'mt-config.cgi',
                  Directory => $MT_DIR )
  || die MT->errstr;

my $help_msg = <<HELP_MSG
Usage:  RebuildCatArchives -blog_id=0 -archive_type="Category-(Daily|Weekly|Monthlty)"
HELP_MSG
  ;

my ( $blog_id, $at  )
  ;    #text and integer arguements

# assign command line arguements to variables.
GetOptions(
            'blog_id=i'          => \$blog_id,
            'archive_type=s'     => \$at,
);

if ( !defined($blog_id) || !defined($at) ) {
	die $help_msg;
}


require RebuildMore::RebuildDispatch;

my $app = $mt;

my ($cat, $entry);

$cat = MT::Category->load({ blog_id => $blog_id}, 
	{
		limit => 1,
		'sort' => 'id',
		direction => 'desc',
	});

$entry = RebuildMore::Util::get_first_entry($cat);

# rebuild everything for this archive type.
# If you've got more than a trillion pages to build, you're out of luck.
RebuildMore::RebuildDispatch::rebuild_pages( $app, $cat, $entry, $at, 1000000000 ); 
