use C4::AuthoritiesMarc;
use C4::Biblio;
+use Koha::Biblios;
+
my $input = new CGI;
-my $dbh = C4::Context->dbh;
my $op = $input->param('op') // q|form|;
my $recordtype = $input->param('recordtype') // 'biblio';
for my $record_id ( uniq @record_ids ) {
if ( $recordtype eq 'biblio' ) {
# Retrieve biblio information
- my $biblio = C4::Biblio::GetBiblio( $record_id );
+ my $biblio = Koha::Biblios->find( $record_id );
unless ( $biblio ) {
push @messages, {
type => 'warning',
};
next;
}
+ my $holds_count = $biblio->holds->count;
+ $biblio = $biblio->unblessed;
+ my $record = &GetMarcBiblio({ biblionumber => $record_id });
+ $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
$biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
- $biblio->{reserves} = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $record_id });
+ $biblio->{holds_count} = $holds_count;
$biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
push @records, $biblio;
} else {
);
} elsif ( $op eq 'delete' ) {
# We want to delete selected records!
- my @record_ids = $input->param('record_id');
- my $dbh = C4::Context->dbh;
- $dbh->{AutoCommit} = 0;
- $dbh->{RaiseError} = 1;
+ my @record_ids = $input->multi_param('record_id');
+ my $schema = Koha::Database->new->schema;
my $error;
my $report = {
RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
$report->{total_records}++;
next unless $record_id;
+ $schema->storage->txn_begin;
+
if ( $recordtype eq 'biblio' ) {
# Biblios
my $biblionumber = $record_id;
# First, checking if issues exist.
# If yes, nothing to do
+ my $biblio = Koha::Biblios->find( $biblionumber );
+
+ # TODO Replace with $biblio->get_issues->count
if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) {
push @messages, {
type => 'warning',
code => 'item_issued',
biblionumber => $biblionumber,
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next;
}
# Cancel reserves
- my $reserves = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber });
- for my $reserve ( @$reserves ) {
+ my $holds = $biblio->holds;
+ while ( my $hold = $holds->next ) {
eval{
- C4::Reserves::CancelReserve( { reserve_id => $reserve->{reserve_id} } );
+ C4::Reserves::CancelReserve( { reserve_id => $hold->reserve_id } );
};
if ( $@ ) {
push @messages, {
type => 'error',
code => 'reserve_not_cancelled',
biblionumber => $biblionumber,
- reserve_id => $reserve->{reserve_id},
+ reserve_id => $hold->reserve_id,
error => $@,
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next RECORD_IDS;
}
}
# Delete items
my @itemnumbers = @{ C4::Items::GetItemnumbersForBiblio( $biblionumber ) };
ITEMNUMBER: for my $itemnumber ( @itemnumbers ) {
- my $error = eval { C4::Items::DelItemCheck( $dbh, $biblionumber, $itemnumber ) };
+ my $error = eval { C4::Items::DelItemCheck( $biblionumber, $itemnumber ) };
if ( $error != 1 or $@ ) {
push @messages, {
type => 'error',
itemnumber => $itemnumber,
error => ($@ ? $@ : $error),
};
- $dbh->rollback;
- next BIBLIONUMBER;
+ $schema->storage->txn_rollback;
+ next RECORD_IDS;
}
}
biblionumber => $biblionumber,
error => ($@ ? $@ : $error),
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next;
}
biblionumber => $biblionumber,
};
$report->{total_success}++;
- $dbh->commit;
+ $schema->storage->txn_commit;
} else {
# Authorities
my $authid = $record_id;
- my $r = eval { C4::AuthoritiesMarc::DelAuthority( $authid ) };
- if ( $r eq '0E0' or $@ ) {
+ eval { C4::AuthoritiesMarc::DelAuthority({ authid => $authid }) };
+ if ( $@ ) {
push @messages, {
type => 'error',
code => 'authority_not_deleted',
authid => $authid,
error => ($@ ? $@ : 0),
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next;
} else {
push @messages, {
authid => $authid,
};
$report->{total_success}++;
- $dbh->commit;
+ $schema->storage->txn_commit;
}
}
}