From 994eb9f572a4691e41da04ce646d20f1655ef5a4 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> Date: Wed, 30 Aug 2023 13:16:28 +0000 Subject: [PATCH] Bug 19316: Add sort1 and sort2 fields to interface and allow editing This patch adds the new sort1 and sort2 fields to the interface so that they can be viewed and edited Test plan: 1) Apply patch and reset_all 2) In the catalog, search for a record with at least one item 3) In the Holdings table, click on the barcode for an item. You should now be on /cgi-bin/koha/catalogue/moredetail.pl 4) Scroll down and observe that there is now a section called "Sort fields" with two fields, Sort 1 and Sort 2. 5) Enter some text in the textarea for Sort 1 (max 50 characters) and click Update 6) The page will refresh and your text should still be visible. Check that item in the database and the text should be stored in the sort1 column. 7) Repeat steps 5-6 for Sort 2. 8) Copy the barcode and navigate to Cataloging > Batch item modification 9) Enter the barcode in the textarea under "Or scan items one by one" (You can add multiple bar codes here if you wish) 10) Fill in the Required values (Home library, Current library, Koha item type) 11) In "Other attributes" there should be two fields, Sort 1 and Sort 2 12) Enter some text into both these fields 13) Click save and a job will be enqueued 14) Click "view detail of the enqueued job" 15) A message should be shown on completion that says "X item(s) modified (with Y field(s) modified)." X should match the number of barcodes that you entered into the batch mod and Y should equal X x 2 16) Check the item either in the interface or the database and the text you entered should now be stored and visible 17) Repeat steps 8 - 14 but this time only fill in Sort 1 18) This time X should equal the number of barcodes that you entered into the batch mod but Y should equal X as only one field was filled in. 19) Again, the text you entered should now be stored on the item record --- Koha/BackgroundJob/BatchUpdateItem.pm | 34 +++++++++---------- Koha/Items.pm | 26 +++++++++----- catalogue/updateitem.pl | 26 ++++++++------ .../prog/en/modules/catalogue/moredetail.tt | 32 +++++++++++++++++ .../prog/en/modules/tools/batchMod-edit.tt | 12 +++++++ tools/batchMod.pl | 27 ++++++++------- 6 files changed, 110 insertions(+), 47 deletions(-) diff --git a/Koha/BackgroundJob/BatchUpdateItem.pm b/Koha/BackgroundJob/BatchUpdateItem.pm index 63f6f71d40..a140249d79 100644 --- a/Koha/BackgroundJob/BatchUpdateItem.pm +++ b/Koha/BackgroundJob/BatchUpdateItem.pm @@ -92,41 +92,43 @@ sub process { $self->start; - my @record_ids = @{ $args->{record_ids} }; - my $regex_mod = $args->{regex_mod}; - my $new_values = $args->{new_values}; - my $exclude_from_local_holds_priority = - $args->{exclude_from_local_holds_priority}; - my $mark_items_returned = - $args->{mark_items_returned}; + my @record_ids = @{ $args->{record_ids} }; + my $regex_mod = $args->{regex_mod}; + my $new_values = $args->{new_values}; + my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority}; + my $mark_items_returned = $args->{mark_items_returned}; + my $sort1 = $args->{sort1}; + my $sort2 = $args->{sort2}; my $report = { - total_records => scalar @record_ids, - modified_fields => 0, + total_records => scalar @record_ids, + modified_fields => 0, }; try { my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update( - { regex_mod => $regex_mod, + { + regex_mod => $regex_mod, new_values => $new_values, exclude_from_local_holds_priority => $exclude_from_local_holds_priority, mark_items_returned => $mark_items_returned, + sort1 => $sort1, + sort2 => $sort2, callback => sub { $self->step; }, } ); $report->{modified_itemnumbers} = $results->{modified_itemnumbers}; $report->{modified_fields} = $results->{modified_fields}; - } - catch { + } catch { warn $_; die "Something terrible has happened!" - if ( $_ =~ /Rollback failed/ ); # Rollback failed + if ( $_ =~ /Rollback failed/ ); # Rollback failed }; my $data = $self->decoded_data; $data->{report} = $report; - $self->finish( $data ); + $self->finish($data); } =head3 enqueue @@ -167,9 +169,7 @@ sub additional_report { if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) { return { too_many_items_display => 1 }; } else { - my $items_table = - Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } ) - ->build_table; + my $items_table = Koha::UI::Table::Builder::Items->new( { itemnumbers => $itemnumbers } )->build_table; return { items => $items_table->{items}, diff --git a/Koha/Items.pm b/Koha/Items.pm index f3edb77685..c4e258128b 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -198,7 +198,7 @@ sub move_to_biblio { =head3 batch_update - Koha::Items->search->batch_update + Koha::Items->search->batch_update( { new_values => { itemnotes => $new_item_notes, @@ -258,11 +258,13 @@ Callback function to call after an item has been modified sub batch_update { my ( $self, $params ) = @_; - my $regex_mod = $params->{regex_mod} || {}; - my $new_values = $params->{new_values} || {}; + my $regex_mod = $params->{regex_mod} || {}; + my $new_values = $params->{new_values} || {}; my $exclude_from_local_holds_priority = $params->{exclude_from_local_holds_priority}; - my $mark_items_returned = $params->{mark_items_returned}; - my $callback = $params->{callback}; + my $mark_items_returned = $params->{mark_items_returned}; + my $sort1 = $params->{sort1}; + my $sort2 = $params->{sort2}; + my $callback = $params->{callback}; my (@modified_itemnumbers, $modified_fields); my $i; @@ -271,13 +273,20 @@ sub batch_update { try {$schema->txn_do(sub { my $modified_holds_priority = 0; - my $item_returned = 0; + my $item_returned = 0; + my $sort_fields_modified = 0; if ( defined $exclude_from_local_holds_priority ) { if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) { $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store; $modified_holds_priority = 1; } } + if ( defined $sort1 || defined $sort2 ) { + $item->sort1($sort1)->store if $sort1 ne ""; + $sort_fields_modified++ if $sort1 ne ""; + $item->sort2($sort2)->store if $sort2 ne ""; + $sort_fields_modified++ if $sort2 ne ""; + } my $modified = 0; my $new_values = {%$new_values}; # Don't modify the original @@ -375,8 +384,9 @@ sub batch_update { } } - push @modified_itemnumbers, $item->itemnumber if $modified || $modified_holds_priority || $item_returned; - $modified_fields += $modified + $modified_holds_priority + $item_returned; + push @modified_itemnumbers, $item->itemnumber + if $modified || $modified_holds_priority || $item_returned || $sort_fields_modified; + $modified_fields += $modified + $modified_holds_priority + $item_returned + $sort_fields_modified; })} catch { warn $_ diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index 5b092763df..64bc6b2682 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -29,17 +29,19 @@ my $cgi= CGI->new; checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet'); -my $op = $cgi->param('op') || ""; -my $biblionumber=$cgi->param('biblionumber'); -my $itemnumber=$cgi->param('itemnumber'); -my $biblioitemnumber=$cgi->param('biblioitemnumber'); -my $itemlost=$cgi->param('itemlost'); -my $itemnotes=$cgi->param('itemnotes'); -my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic'); -my $withdrawn=$cgi->param('withdrawn'); -my $damaged=$cgi->param('damaged'); +my $op = $cgi->param('op') || ""; +my $biblionumber = $cgi->param('biblionumber'); +my $itemnumber = $cgi->param('itemnumber'); +my $biblioitemnumber = $cgi->param('biblioitemnumber'); +my $itemlost = $cgi->param('itemlost'); +my $itemnotes = $cgi->param('itemnotes'); +my $itemnotes_nonpublic = $cgi->param('itemnotes_nonpublic'); +my $withdrawn = $cgi->param('withdrawn'); +my $damaged = $cgi->param('damaged'); my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority'); -my $bookable = $cgi->param('bookable'); +my $bookable = $cgi->param('bookable'); +my $sort1 = $cgi->param('sort1'); +my $sort2 = $cgi->param('sort2'); my $confirm=$cgi->param('confirm'); my $dbh = C4::Context->dbh; @@ -80,6 +82,10 @@ elsif ( $op eq "cud-set_public_note" ) { # i.e., itemnotes parameter passed from $item->bookable($bookable); } elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) { $item->damaged($damaged); +} elsif ( $op eq "set_sort1" && $sort1 ne $item_data_hashref->{'sort1'} ) { + $item->sort1($sort1); +} elsif ( $op eq "set_sort2" && $sort2 ne $item_data_hashref->{'sort2'} ) { + $item->sort2($sort2); } else { #nothings changed, so do nothing. print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index aabed1ca3b..d5bb9586d4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -379,6 +379,38 @@ </div> <!-- /.rows --> </div> <!-- /.listgroup --> + <div class="listgroup"> + <h4>Sort fields</h4> + <div class="rows"> + <ol class="bibliodetails"> + <li> + <span class="label">Sort 1:</span> + [% IF ( CAN_user_editcatalogue_edit_items ) %] + <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" /> + <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" /> + <input type="hidden" name="op" value="set_sort1" /> + <textarea name="sort1" rows="2" cols="30">[% ITEM_DAT.sort1 | html %]</textarea><input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" /> + </form> + [% ELSE %] + [% ITEM_DAT.sort1 | html %] + [% END %] + </li> + <li> + <span class="label">Sort 2:</span> + [% IF ( CAN_user_editcatalogue_edit_items ) %] + <form class="inline" action="updateitem.pl" method="post"><input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" /> + <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" /><input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" /> + <input type="hidden" name="op" value="set_sort2" /> + <textarea name="sort2" rows="2" cols="30">[% ITEM_DAT.sort2 | html %]</textarea><input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" /> + </form> + [% ELSE %] + [% ITEM_DAT.sort2 | html %] + [% END %] + </li> + </ol> <!-- /.bibliodetails --> + </div> <!-- /.rows --> + </div> <!-- /.listgroup --> + <div class="listgroup"> <h4>History</h4> <div class="rows"> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt index 1b442b5fcf..bda70fd938 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt @@ -218,6 +218,18 @@ </select> </div> </li> + <li> + <div class="subfield_line"> + <label for="sort1">Sort 1:</label> + <input type="text" id="sort1" name="sort1" class="input_marceditor" maxlength="50" value="" /> + </div> + </li> + <li> + <div class="subfield_line"> + <label for="sort1">Sort 2:</label> + <input type="text" id="sort2" name="sort2" class="input_marceditor" maxlength="50" value="" /> + </div> + </li> </ol> </fieldset> <fieldset class="rows"> diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 1b43231857..28926698de 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -41,18 +41,20 @@ use Koha::BackgroundJob::BatchUpdateItem; use Koha::UI::Form::Builder::Item; use Koha::UI::Table::Builder::Items; -my $input = CGI->new; -my $dbh = C4::Context->dbh; -my $error = $input->param('error'); -my @itemnumbers = $input->multi_param('itemnumber'); -my $biblionumber = $input->param('biblionumber'); -my $op = $input->param('op'); -my $del = $input->param('del'); -my $del_records = $input->param('del_records'); -my $src = $input->param('src'); -my $use_default_values = $input->param('use_default_values'); +my $input = CGI->new; +my $dbh = C4::Context->dbh; +my $error = $input->param('error'); +my @itemnumbers = $input->multi_param('itemnumber'); +my $biblionumber = $input->param('biblionumber'); +my $op = $input->param('op'); +my $del = $input->param('del'); +my $del_records = $input->param('del_records'); +my $src = $input->param('src'); +my $use_default_values = $input->param('use_default_values'); my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority'); -my $mark_items_returned = $input->param('mark_items_returned'); +my $sort1 = $input->param('sort1'); +my $sort2 = $input->param('sort2'); +my $mark_items_returned = $input->param('mark_items_returned'); my $template_name; my $template_flag; @@ -177,7 +179,8 @@ if ( $op eq "cud-action" ) { && $mark_items_returned ne "" ) ? $mark_items_returned : undef, - + sort1 => ( defined $sort1 && $sort1 ne "" ) ? $sort1 : undef, + sort2 => ( defined $sort2 && $sort2 ne "" ) ? $sort2 : undef, }; try { my $job_id = -- 2.37.1 (Apple Git-137.1)