use C4::AuthoritiesMarc;
use C4::Biblio;
+use Koha::Authorities;
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';
}
my $holds_count = $biblio->holds->count;
$biblio = $biblio->unblessed;
- my $record = &GetMarcBiblio( $record_id );
+ my $record = &GetMarcBiblio({ biblionumber => $record_id });
$biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
$biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
$biblio->{holds_count} = $holds_count;
$authority = {
authid => $record_id,
summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ),
- count_usage => C4::AuthoritiesMarc::CountUsage( $record_id ),
+ count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }),
};
push @records, $authority;
}
} elsif ( $op eq 'delete' ) {
# We want to delete selected records!
my @record_ids = $input->multi_param('record_id');
- my $dbh = C4::Context->dbh;
- $dbh->{AutoCommit} = 0;
- $dbh->{RaiseError} = 1;
+ 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;
code => 'item_issued',
biblionumber => $biblionumber,
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next;
}
my $holds = $biblio->holds;
while ( my $hold = $holds->next ) {
eval{
- C4::Reserves::CancelReserve( { reserve_id => $hold->reserve_id } );
+ $hold->cancel;
};
if ( $@ ) {
push @messages, {
reserve_id => $hold->reserve_id,
error => $@,
};
- $dbh->rollback;
+ $schema->storage->txn_rollback;
next RECORD_IDS;
}
}
itemnumber => $itemnumber,
error => ($@ ? $@ : $error),
};
- $dbh->rollback;
+ $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;
- eval { C4::AuthoritiesMarc::DelAuthority( $authid ) };
+ eval { C4::AuthoritiesMarc::DelAuthority({ authid => $authid }) };
if ( $@ ) {
push @messages, {
type => 'error',
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;
}
}
}