#!/usr/bin/perl -w

use strict;
use Getopt::Std;

use lib "/www/opals/module";
use Opals::Context("/etc/opals/conf/_SITECODE_");
use Opals::MarcXml qw(
    mxml_delete
);

my %options = ();
getopts("s:e:",\%options);
my $start = $options{s};
my $end = $options{e};
if (!$start || !$end) {
    print "Usage: $0 -s START_DATETIME -e END_DATETIME\n";
    exit 1;
}

my $dbh = Opals::Context->dbh();;
END {
    if ($dbh) {
        $dbh->disconnect();
    }
}

$| = 1;
# Codes start...

my $sth = $dbh->prepare(<<_SQL_);
select  rid
from    opl_item
where   dateImport >= ?
     && dateImport <= ?
     && dateImport  = modDate
order by dateImport asc, barcode asc
_SQL_

$sth->execute($start, $end);
while (my $rec = $sth->fetchrow_hashref) {
    print 'Deleting RID: ', $rec->{'rid'}, "...";
    mxml_delete($dbh, $rec->{'rid'});
    print " done.\n";
}
$sth->finish;

# Codes end.

exit 0;
################################################################################

=item
sub blahblahblah {
}
=cut
############################################################
