From d7f8f46299c4165ad995c76c656bb3d42d48ae57 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 29 Sep 2021 20:20:38 -0300 Subject: [PATCH] Bug 23678: (QA follow-up) Use correct indentation Signed-off-by: Tomas Cohen Arazi JD amended patch: also Koha/BackgroundJob/BatchCancelHold.pm --- Koha/BackgroundJob/BatchCancelHold.pm | 78 ++++++++++++++----------- circ/waitingreserves.pl | 26 ++++----- reserve/request.pl | 82 +++++++++++++++------------ 3 files changed, 102 insertions(+), 84 deletions(-) diff --git a/Koha/BackgroundJob/BatchCancelHold.pm b/Koha/BackgroundJob/BatchCancelHold.pm index 47426f84556..fb009483f67 100644 --- a/Koha/BackgroundJob/BatchCancelHold.pm +++ b/Koha/BackgroundJob/BatchCancelHold.pm @@ -60,51 +60,60 @@ sub process { } my $job_progress = 0; - $job->started_on(dt_from_string) - ->progress($job_progress) - ->status('started') - ->store; + $job->started_on(dt_from_string)->progress($job_progress) + ->status('started')->store; my @hold_ids = @{ $args->{hold_ids} }; my $report = { - total_holds => scalar @hold_ids, + total_holds => scalar @hold_ids, total_success => 0, }; my @messages; - HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) { + HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) { next unless $hold_id; + # Authorities - my ($hold, $patron, $biblio); + my ( $hold, $patron, $biblio ); $hold = Koha::Holds->find($hold_id); my $error = eval { $patron = $hold->patron; $biblio = $hold->biblio; - $hold->cancel({cancellation_reason => $args->{reason}}); + $hold->cancel( { cancellation_reason => $args->{reason} } ); }; if ( $error and $error != $hold or $@ ) { - push @messages, { - type => 'error', - code => 'hold_not_cancelled', - patron_id => defined $patron?$patron->borrowernumber:'', - patron_name => defined $patron?($patron->firstname?$patron->firstname.', ':'').$patron->surname:'', - biblio_id => defined $biblio?$biblio->biblionumber:'', - biblio_title => defined $biblio?$biblio->title:'', - hold_id => $hold_id, - error => defined $hold?($@ ? $@ : 0):'No hold with id '.$hold_id.' found', - }; - } else { - push @messages, { - type => 'success', - code => 'hold_cancelled', + push @messages, + { + type => 'error', + code => 'hold_not_cancelled', + patron_id => defined $patron ? $patron->borrowernumber : '', + patron_name => defined $patron + ? ( $patron->firstname ? $patron->firstname . ', ' : '' ) + . $patron->surname + : '', + biblio_id => defined $biblio ? $biblio->biblionumber : '', + biblio_title => defined $biblio ? $biblio->title : '', + hold_id => $hold_id, + error => defined $hold + ? ( $@ ? $@ : 0 ) + : 'No hold with id ' . $hold_id . ' found', + }; + } + else { + push @messages, + { + type => 'success', + code => 'hold_cancelled', patron_id => $patron->borrowernumber, - patron_name => ($patron->firstname?$patron->firstname.', ':'').$patron->surname, - biblio_id => $biblio->biblionumber, + patron_name => + ( $patron->firstname ? $patron->firstname . ', ' : '' ) + . $patron->surname, + biblio_id => $biblio->biblionumber, biblio_title => $biblio->title, - hold_id => $hold_id, - }; + hold_id => $hold_id, + }; $report->{total_success}++; } $job->progress( ++$job_progress )->store; @@ -112,10 +121,9 @@ sub process { my $job_data = decode_json $job->data; $job_data->{messages} = \@messages; - $job_data->{report} = $report; + $job_data->{report} = $report; - $job->ended_on(dt_from_string) - ->data(encode_json $job_data); + $job->ended_on(dt_from_string)->data( encode_json $job_data); $job->status('finished') if $job->status ne 'cancelled'; $job->store; @@ -128,17 +136,19 @@ Enqueue the new job =cut sub enqueue { - my ( $self, $args) = @_; + my ( $self, $args ) = @_; # TODO Raise exception instead return unless exists $args->{hold_ids}; my @hold_ids = @{ $args->{hold_ids} }; - $self->SUPER::enqueue({ - job_size => scalar @hold_ids, - job_args => {hold_ids => \@hold_ids, reason => $args->{reason}} - }); + $self->SUPER::enqueue( + { + job_size => scalar @hold_ids, + job_args => { hold_ids => \@hold_ids, reason => $args->{reason} } + } + ); } 1; diff --git a/circ/waitingreserves.pl b/circ/waitingreserves.pl index ccbab78a2b1..d71c53bb778 100755 --- a/circ/waitingreserves.pl +++ b/circ/waitingreserves.pl @@ -73,19 +73,19 @@ if ( C4::Context->preference('IndependentBranches') ) { } $template->param( all_branches => 1 ) if $all_branches; -if ( $cancelBulk ) { - my $cancellation_reason = $input->param("cancellation-reason"); - my @hold_ids = split ',', $input->param("ids"); - my $params = { - reason => $cancellation_reason, - hold_ids => \@hold_ids, - }; - my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params); - - $template->param( - enqueued => 1, - job_id => $job_id - ) +if ($cancelBulk) { + my $reason = $input->param("cancellation-reason"); + my @hold_ids = split ',', $input->param("ids"); + my $params = { + reason => $reason, + hold_ids => \@hold_ids, + }; + my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params); + + $template->param( + enqueued => 1, + job_id => $job_id + ); } my (@reserve_loop, @over_loop); diff --git a/reserve/request.pl b/reserve/request.pl index 33adf216ea8..95a7fd43d1a 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -90,43 +90,51 @@ my $action = $input->param('action'); $action ||= q{}; if ( $action eq 'move' ) { - my $where = $input->param('where'); - my $reserve_id = $input->param('reserve_id'); - my $prev_priority = $input->param('prev_priority'); - my $next_priority = $input->param('next_priority'); - my $first_priority = $input->param('first_priority'); - my $last_priority = $input->param('last_priority'); - my $hold_itemnumber = $input->param('itemnumber'); - if ( $prev_priority == 0 && $next_priority == 1 ){ - C4::Reserves::RevertWaitingStatus({ itemnumber => $hold_itemnumber }); - } else { - AlterPriority( $where, $reserve_id, $prev_priority, $next_priority, $first_priority, $last_priority ); - } -} elsif ( $action eq 'cancel' ) { - my $reserve_id = $input->param('reserve_id'); - my $cancellation_reason = $input->param("cancellation-reason"); - my $hold = Koha::Holds->find( $reserve_id ); - $hold->cancel({ cancellation_reason => $cancellation_reason }) if $hold; -} elsif ( $action eq 'setLowestPriority' ) { - my $reserve_id = $input->param('reserve_id'); - ToggleLowestPriority( $reserve_id ); -} elsif ( $action eq 'toggleSuspend' ) { - my $reserve_id = $input->param('reserve_id'); - my $suspend_until = $input->param('suspend_until'); - ToggleSuspend( $reserve_id, $suspend_until ); -} elsif ( $action eq 'cancelBulk') { - my $cancellation_reason = $input->param("cancellation-reason"); - my @hold_ids = split ',', $input->param("ids"); - my $params = { - reason => $cancellation_reason, - hold_ids => \@hold_ids, - }; - my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params); - - $template->param( - enqueued => 1, - job_id => $job_id - ) + my $where = $input->param('where'); + my $reserve_id = $input->param('reserve_id'); + my $prev_priority = $input->param('prev_priority'); + my $next_priority = $input->param('next_priority'); + my $first_priority = $input->param('first_priority'); + my $last_priority = $input->param('last_priority'); + my $hold_itemnumber = $input->param('itemnumber'); + if ( $prev_priority == 0 && $next_priority == 1 ) { + C4::Reserves::RevertWaitingStatus( { itemnumber => $hold_itemnumber } ); + } + else { + AlterPriority( + $where, $reserve_id, $prev_priority, + $next_priority, $first_priority, $last_priority + ); + } +} +elsif ( $action eq 'cancel' ) { + my $reserve_id = $input->param('reserve_id'); + my $cancellation_reason = $input->param("cancellation-reason"); + my $hold = Koha::Holds->find($reserve_id); + $hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold; +} +elsif ( $action eq 'setLowestPriority' ) { + my $reserve_id = $input->param('reserve_id'); + ToggleLowestPriority($reserve_id); +} +elsif ( $action eq 'toggleSuspend' ) { + my $reserve_id = $input->param('reserve_id'); + my $suspend_until = $input->param('suspend_until'); + ToggleSuspend( $reserve_id, $suspend_until ); +} +elsif ( $action eq 'cancelBulk' ) { + my $cancellation_reason = $input->param("cancellation-reason"); + my @hold_ids = split ',', $input->param("ids"); + my $params = { + reason => $cancellation_reason, + hold_ids => \@hold_ids, + }; + my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params); + + $template->param( + enqueued => 1, + job_id => $job_id + ); } if ($findborrower) { -- 2.25.1