#!/usr/bin/perl -w

BEGIN {
    sub print_help {
    print <<_STR_;
NAME:
    .
SYNOPSIS:
    PERL5LIB=/www/opals/module OPALS_CONF=/etc/opals/conf/\$SITECODE \\
        $0 [param1] [param2] [...]
DESCRIPTION:
    -param1  description 1...
_STR_
    }

    if (!$ENV{'PERL5LIB'} || !$ENV{'OPALS_CONF'}) {
        print_help();
        exit 1;
    }
}

#use Getopt::Std;
#
#my %options = ();
#getopts("c:",\%options);
#my $configFile = $options{c};

use Opals::Context;

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

$| = 1;
# Codes start...

my $sth_import = $dbh->prepare(<<_SQL_);
select  *
from    opl_marcImport
where   dateUpload >= '2010-07-29 00:00:00'
_SQL_

my $sth_pending = $dbh->prepare(<<_SQL_);
delete
from    opl_marcDuplicate
where   iid = ?
_SQL_

my $sth_resetImport = $dbh->prepare(<<_SQL_);
update  opl_marcImport
set     countImported = 0,
        countMerged = 0,
        countMergedHolding = 0,
        countProcessed = 0,
        status = 'accepted'
where   iid = ?
_SQL_

$sth_import->execute();
while (my $import = $sth_import->fetchrow_hashref()) {
    $sth_pending->execute($import->{'iid'});
    $sth_resetImport->execute($import->{'iid'});
}

$sth_resetImport->finish;
$sth_pending->finish;
$sth_import->finish;

# Codes end.

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


#sub {
#}
############################################################
