#!/usr/bin/perl

use Modern::Perl;

use Pod::Usage;
use Getopt::Long;

use C4::Members;
use C4::VirtualShelves;
use Koha::DateUtils;

my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 0;

$dbh->{AutoCommit} = 0;

my $borrowernumber = 999999999999;

eval {
    C4::Members::MoveMemberToDeleted( $borrowernumber )
};
if ($@) {
    say "Failed to delete patron $borrowernumber, cannot move it: ($@) ROLLBACK";
    exit;

}
eval {
    C4::VirtualShelves::HandleDelBorrower( $borrowernumber )
};
if ($@) {
    say "Failed to delete patron $borrowernumber, error handling its lists: ($@) ROLLBACK";
    $dbh->rollback;
    exit;
}
eval { C4::Members::DelMember( $borrowernumber )};
if ($@) {
    say "Failed to delete patron $borrowernumber: $@) ROLLBACK";
    $dbh->rollback;
    exit;
}
$dbh->commit;
say "No error!";
