X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=tools%2Fbatch_record_modification.pl;h=1a82c476c308b3d7503f276273eb4aa2b203c840;hb=refs%2Fheads%2Fkoha_ffzg;hp=3aec4f70f2c25efd84d2c08fb2c475647e04058a;hpb=c1aeaf62b9c08d35449aa9822504de8ce79fec62;p=koha.git diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 3aec4f70f2..1a82c476c3 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -25,11 +25,14 @@ use List::MoreUtils qw( uniq ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); -use C4::AuthoritiesMarc qw( BuildSummary GetAuthTypeCode ModAuthority ); +use C4::AuthoritiesMarc qw( BuildSummary ModAuthority ); use C4::BackgroundJob; use C4::Biblio qw( GetMarcBiblio ModBiblio ); use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate ); -use Koha::Authority; + +use Koha::Biblios; +use Koha::MetadataRecord::Authority; +use Koha::Virtualshelves; my $input = new CGI; our $dbh = C4::Context->dbh; @@ -44,7 +47,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { tools => 'biblio_batchmod' }, + flagsrequired => { tools => 'records_batchmod' }, }); @@ -66,6 +69,8 @@ if ( $completedJobID ) { exit; } +$template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) ); + my @templates = GetModificationTemplates( $mmtid ); unless ( @templates ) { $op = 'error'; @@ -103,11 +108,19 @@ if ( $op eq 'form' ) { $recordtype = 'biblio'; } elsif ( my $uploadfile = $input->param('uploadfile') ) { # A file of id is given + binmode $uploadfile, ':encoding(UTF-8)'; while ( my $content = <$uploadfile> ) { next unless $content; $content =~ s/[\r\n]*$//; push @record_ids, $content if $content; } + } elsif ( my $shelf_number = $input->param('shelf_number') ) { + my $shelf = Koha::Virtualshelves->find($shelf_number); + my $contents = $shelf->get_contents; + while ( my $content = $contents->next ) { + my $biblionumber = $content->biblionumber; + push @record_ids, $biblionumber; + } } else { # The user enters manually the list of id push @record_ids, split( /\s\n/, $input->param('recordnumber_list') ); @@ -116,7 +129,7 @@ if ( $op eq 'form' ) { 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', @@ -128,7 +141,7 @@ if ( $op eq 'form' ) { push @records, $biblio; } else { # Retrieve authority information - my $authority = Koha::Authority->get_from_authid( $record_id ); + my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id ); unless ( $authority ) { push @messages, { type => 'warning', @@ -151,7 +164,7 @@ if ( $op eq 'form' ) { ); } elsif ( $op eq 'modify' ) { # We want to modify selected records! - my @record_ids = $input->param('record_id'); + my @record_ids = $input->multi_param('record_id'); my ( $job ); if ( $runinbackground ) { @@ -167,7 +180,6 @@ if ( $op eq 'form' ) { exit 0; } elsif (defined $pid) { close STDOUT; - close STDERR; } else { warn "fork failed while attempting to run tools/batch_record_modification.pl as a background job"; exit 0; @@ -190,7 +202,7 @@ if ( $op eq 'form' ) { # Finally, modify the biblio my $error = eval { - my $record = GetMarcBiblio( $biblionumber ); + my $record = GetMarcBiblio({ biblionumber => $biblionumber }); ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); ModBiblio( $record, $biblionumber, $frameworkcode ); @@ -214,10 +226,10 @@ if ( $op eq 'form' ) { # Authorities my $authid = $record_id; my $error = eval { - my $authority = Koha::Authority->get_from_authid( $authid ); + my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid ); my $record = $authority->record; ModifyRecordWithTemplate( $mmtid, $record ); - ModAuthority( $authid, $record, GetAuthTypeCode( $authid ) ); + ModAuthority( $authid, $record, $authority->authtypecode ); }; if ( $error and $error != $authid or $@ ) { push @messages, {