From 893764af619a416cef73ca0265dc24bacc591493 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 12 Jan 2017 12:43:19 +0100 Subject: [PATCH] Bug 17273: Add records to modify via shelf or search Content-Type: text/plain; charset=utf-8 This patch adds two new ways to add records via two new URL parameters: [1] from_shelf allows you to pass a list number, [2] from_search allows you to pass a search expression. They are added now in the same way as bib_list was done earlier. A future report should incorporate them into the interface. Adding a new method to Virtualshelf along the way. Unit test in followup. Note: I copied the sub _extract_biblionumbers from a new report still in progress. I will move the sub to a module on a new report. Test plan: [1] Pick a list number (you should be allowed to see). And try this URL: /cgi-bin/koha/tools/batch_record_modification.pl?op=list&from_shelf=XX where XX obviously is your list number. [2] Pick a search expression that does not generate too much records. And similarly try: /cgi-bin/koha/tools/batch_record_modification.pl?op=list&from_search=XX Signed-off-by: Marcel de Rooy --- Koha/Virtualshelf.pm | 18 ++++++++++++++++++ tools/batch_record_modification.pl | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index 4e45c31..805870d 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -276,6 +276,24 @@ sub can_biblios_be_removed { return 0; } + +=head3 list_biblionumbers + +Returns an arrayref of all biblionumbers on this list. +Note: Caller should still check view permissions, if needed. + +=cut + +sub list_biblionumbers { + my ( $self ) = @_; + my $result = []; + my $contents = $self->get_contents; + while( my $rec = $contents->next ) { + push @$result, $rec->biblionumber; + } + return $result; +} + sub _type { return 'Virtualshelve'; } diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 6ea0317..981e2b9 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -27,9 +27,11 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::AuthoritiesMarc qw( BuildSummary ModAuthority ); use C4::BackgroundJob; -use C4::Biblio qw( GetMarcBiblio ModBiblio ); +use C4::Biblio qw( GetMarcBiblio ModBiblio GetMarcFromKohaField ); use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate ); use Koha::MetadataRecord::Authority; +use Koha::SearchEngine; +use Koha::Virtualshelves; my $input = new CGI; our $dbh = C4::Context->dbh; @@ -98,9 +100,23 @@ if ( $op eq 'form' ) { # List all records to process my ( @records, @record_ids ); if ( my $bib_list = $input->param('bib_list') ) { + # TODO Undocumented feature; should be added to interface # Come from the basket @record_ids = split /\//, $bib_list; $recordtype = 'biblio'; + } elsif( my $shelfno = $input->param('from_shelf') ) { + # TODO Undocumented feature; should be added to interface + my $shelf = Koha::Virtualshelves->find($shelfno); + @record_ids = $shelf && $shelf->can_be_viewed( $loggedinuser ) + ? @{ $shelf->list_biblionumbers } + : (); + $recordtype = 'biblio'; + } elsif( my $expr = $input->param('from_search') ) { + # TODO Undocumented feature; should be added to interface + my $engine = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ( $err, $results, $count ) = $engine->simple_search_compat( $expr ); + @record_ids = @{ _extract_biblionumbers( $results ) }; + $recordtype = 'biblio'; } elsif ( my $uploadfile = $input->param('uploadfile') ) { # A file of id is given while ( my $content = <$uploadfile> ) { @@ -261,3 +277,19 @@ $template->param( ); output_html_with_http_headers $input, $cookie, $template->output; + +sub _extract_biblionumbers { + my ( $results ) = @_; + my ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", '' ); + my @biblios; + foreach my $rec ( @$results ) { + my $marcrecordzebra = C4::Search::new_record_from_zebra( 'biblioserver', $rec ); + next if ref( $marcrecordzebra ) ne 'MARC::Record'; + + my $bibno = ( $biblionumbertagfield < 10 ) + ? $marcrecordzebra->field( $biblionumbertagfield )->data + : $marcrecordzebra->subfield( $biblionumbertagfield, $biblionumbertagsubfield ); + push @biblios, $bibno if $bibno; + } + return \@biblios; +} -- 2.1.4