View | Details | Raw Unified | Return to bug 23678
Collapse All | Expand All

(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-34 / +44 lines)
Lines 60-110 sub process { Link Here
60
    }
60
    }
61
61
62
    my $job_progress = 0;
62
    my $job_progress = 0;
63
    $job->started_on(dt_from_string)
63
    $job->started_on(dt_from_string)->progress($job_progress)
64
        ->progress($job_progress)
64
      ->status('started')->store;
65
        ->status('started')
66
        ->store;
67
65
68
    my @hold_ids = @{ $args->{hold_ids} };
66
    my @hold_ids = @{ $args->{hold_ids} };
69
67
70
    my $report = {
68
    my $report = {
71
        total_holds => scalar @hold_ids,
69
        total_holds   => scalar @hold_ids,
72
        total_success => 0,
70
        total_success => 0,
73
    };
71
    };
74
    my @messages;
72
    my @messages;
75
    HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) {
73
      HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) {
76
        next unless $hold_id;
74
        next unless $hold_id;
75
77
        # Authorities
76
        # Authorities
78
        my ($hold, $patron, $biblio);
77
        my ( $hold, $patron, $biblio );
79
        $hold = Koha::Holds->find($hold_id);
78
        $hold = Koha::Holds->find($hold_id);
80
79
81
        my $error = eval {
80
        my $error = eval {
82
            $patron = $hold->patron;
81
            $patron = $hold->patron;
83
            $biblio = $hold->biblio;
82
            $biblio = $hold->biblio;
84
            $hold->cancel({cancellation_reason => $args->{reason}});
83
            $hold->cancel( { cancellation_reason => $args->{reason} } );
85
        };
84
        };
86
85
87
        if ( $error and $error != $hold or $@ ) {
86
        if ( $error and $error != $hold or $@ ) {
88
            push @messages, {
87
            push @messages,
89
                type => 'error',
88
              {
90
                code => 'hold_not_cancelled',
89
                type        => 'error',
91
                patron_id => defined $patron?$patron->borrowernumber:'',
90
                code        => 'hold_not_cancelled',
92
                patron_name => defined $patron?($patron->firstname?$patron->firstname.', ':'').$patron->surname:'',
91
                patron_id   => defined $patron ? $patron->borrowernumber : '',
93
                biblio_id => defined $biblio?$biblio->biblionumber:'',
92
                patron_name => defined $patron
94
                biblio_title => defined $biblio?$biblio->title:'',
93
                ? ( $patron->firstname ? $patron->firstname . ', ' : '' )
95
                hold_id => $hold_id,
94
                  . $patron->surname
96
                error => defined $hold?($@ ? $@ : 0):'No hold with id '.$hold_id.' found',
95
                : '',
97
            };
96
                biblio_id    => defined $biblio ? $biblio->biblionumber : '',
98
        } else {
97
                biblio_title => defined $biblio ? $biblio->title        : '',
99
            push @messages, {
98
                hold_id      => $hold_id,
100
                type => 'success',
99
                error        => defined $hold
101
                code => 'hold_cancelled',
100
                ? ( $@ ? $@ : 0 )
101
                : 'No hold with id ' . $hold_id . ' found',
102
              };
103
        }
104
        else {
105
            push @messages,
106
              {
107
                type      => 'success',
108
                code      => 'hold_cancelled',
102
                patron_id => $patron->borrowernumber,
109
                patron_id => $patron->borrowernumber,
103
                patron_name => ($patron->firstname?$patron->firstname.', ':'').$patron->surname,
110
                patron_name =>
104
                biblio_id => $biblio->biblionumber,
111
                  ( $patron->firstname ? $patron->firstname . ', ' : '' )
112
                  . $patron->surname,
113
                biblio_id    => $biblio->biblionumber,
105
                biblio_title => $biblio->title,
114
                biblio_title => $biblio->title,
106
                hold_id => $hold_id,
115
                hold_id      => $hold_id,
107
            };
116
              };
108
            $report->{total_success}++;
117
            $report->{total_success}++;
109
        }
118
        }
110
        $job->progress( ++$job_progress )->store;
119
        $job->progress( ++$job_progress )->store;
Lines 112-121 sub process { Link Here
112
121
113
    my $job_data = decode_json $job->data;
122
    my $job_data = decode_json $job->data;
114
    $job_data->{messages} = \@messages;
123
    $job_data->{messages} = \@messages;
115
    $job_data->{report} = $report;
124
    $job_data->{report}   = $report;
116
125
117
    $job->ended_on(dt_from_string)
126
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
118
        ->data(encode_json $job_data);
119
    $job->status('finished') if $job->status ne 'cancelled';
127
    $job->status('finished') if $job->status ne 'cancelled';
120
    $job->store;
128
    $job->store;
121
129
Lines 128-144 Enqueue the new job Link Here
128
=cut
136
=cut
129
137
130
sub enqueue {
138
sub enqueue {
131
    my ( $self, $args) = @_;
139
    my ( $self, $args ) = @_;
132
140
133
    # TODO Raise exception instead
141
    # TODO Raise exception instead
134
    return unless exists $args->{hold_ids};
142
    return unless exists $args->{hold_ids};
135
143
136
    my @hold_ids = @{ $args->{hold_ids} };
144
    my @hold_ids = @{ $args->{hold_ids} };
137
145
138
    $self->SUPER::enqueue({
146
    $self->SUPER::enqueue(
139
        job_size => scalar @hold_ids,
147
        {
140
        job_args => {hold_ids => \@hold_ids, reason => $args->{reason}}
148
            job_size => scalar @hold_ids,
141
    });
149
            job_args => { hold_ids => \@hold_ids, reason => $args->{reason} }
150
        }
151
    );
142
}
152
}
143
153
144
1;
154
1;
(-)a/circ/waitingreserves.pl (-13 / +13 lines)
Lines 73-91 if ( C4::Context->preference('IndependentBranches') ) { Link Here
73
}
73
}
74
$template->param( all_branches => 1 ) if $all_branches;
74
$template->param( all_branches => 1 ) if $all_branches;
75
75
76
if ( $cancelBulk ) {
76
if ($cancelBulk) {
77
  my $cancellation_reason = $input->param("cancellation-reason");
77
    my $reason   = $input->param("cancellation-reason");
78
  my @hold_ids = split ',', $input->param("ids");
78
    my @hold_ids = split ',', $input->param("ids");
79
  my $params = {
79
    my $params   = {
80
      reason       => $cancellation_reason,
80
        reason   => $reason,
81
      hold_ids  => \@hold_ids,
81
        hold_ids => \@hold_ids,
82
  };
82
    };
83
  my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
83
    my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
84
84
85
  $template->param(
85
    $template->param(
86
    enqueued => 1,
86
        enqueued => 1,
87
    job_id => $job_id
87
        job_id   => $job_id
88
  )
88
    );
89
}
89
}
90
90
91
my (@reserve_loop, @over_loop);
91
my (@reserve_loop, @over_loop);
(-)a/reserve/request.pl (-38 / +45 lines)
Lines 90-132 my $action = $input->param('action'); Link Here
90
$action ||= q{};
90
$action ||= q{};
91
91
92
if ( $action eq 'move' ) {
92
if ( $action eq 'move' ) {
93
  my $where           = $input->param('where');
93
    my $where           = $input->param('where');
94
  my $reserve_id      = $input->param('reserve_id');
94
    my $reserve_id      = $input->param('reserve_id');
95
  my $prev_priority   = $input->param('prev_priority');
95
    my $prev_priority   = $input->param('prev_priority');
96
  my $next_priority   = $input->param('next_priority');
96
    my $next_priority   = $input->param('next_priority');
97
  my $first_priority  = $input->param('first_priority');
97
    my $first_priority  = $input->param('first_priority');
98
  my $last_priority   = $input->param('last_priority');
98
    my $last_priority   = $input->param('last_priority');
99
  my $hold_itemnumber = $input->param('itemnumber');
99
    my $hold_itemnumber = $input->param('itemnumber');
100
  if ( $prev_priority == 0 && $next_priority == 1 ){
100
    if ( $prev_priority == 0 && $next_priority == 1 ) {
101
      C4::Reserves::RevertWaitingStatus({ itemnumber => $hold_itemnumber });
101
        C4::Reserves::RevertWaitingStatus( { itemnumber => $hold_itemnumber } );
102
  } else {
102
    }
103
      AlterPriority( $where, $reserve_id, $prev_priority, $next_priority, $first_priority, $last_priority );
103
    else {
104
  }
104
        AlterPriority(
105
} elsif ( $action eq 'cancel' ) {
105
            $where,         $reserve_id,     $prev_priority,
106
  my $reserve_id = $input->param('reserve_id');
106
            $next_priority, $first_priority, $last_priority
107
  my $cancellation_reason = $input->param("cancellation-reason");
107
        );
108
  my $hold = Koha::Holds->find( $reserve_id );
108
    }
109
  $hold->cancel({ cancellation_reason => $cancellation_reason }) if $hold;
109
}
110
} elsif ( $action eq 'setLowestPriority' ) {
110
elsif ( $action eq 'cancel' ) {
111
  my $reserve_id = $input->param('reserve_id');
111
    my $reserve_id          = $input->param('reserve_id');
112
  ToggleLowestPriority( $reserve_id );
112
    my $cancellation_reason = $input->param("cancellation-reason");
113
} elsif ( $action eq 'toggleSuspend' ) {
113
    my $hold                = Koha::Holds->find($reserve_id);
114
  my $reserve_id = $input->param('reserve_id');
114
    $hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold;
115
  my $suspend_until  = $input->param('suspend_until');
115
}
116
  ToggleSuspend( $reserve_id, $suspend_until );
116
elsif ( $action eq 'setLowestPriority' ) {
117
} elsif ( $action eq 'cancelBulk') {
117
    my $reserve_id = $input->param('reserve_id');
118
  my $cancellation_reason = $input->param("cancellation-reason");
118
    ToggleLowestPriority($reserve_id);
119
  my @hold_ids = split ',', $input->param("ids");
119
}
120
  my $params = {
120
elsif ( $action eq 'toggleSuspend' ) {
121
      reason       => $cancellation_reason,
121
    my $reserve_id    = $input->param('reserve_id');
122
      hold_ids  => \@hold_ids,
122
    my $suspend_until = $input->param('suspend_until');
123
  };
123
    ToggleSuspend( $reserve_id, $suspend_until );
124
  my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
124
}
125
125
elsif ( $action eq 'cancelBulk' ) {
126
  $template->param(
126
    my $cancellation_reason = $input->param("cancellation-reason");
127
    enqueued => 1,
127
    my @hold_ids            = split ',', $input->param("ids");
128
    job_id => $job_id
128
    my $params              = {
129
  )
129
        reason   => $cancellation_reason,
130
        hold_ids => \@hold_ids,
131
    };
132
    my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
133
134
    $template->param(
135
        enqueued => 1,
136
        job_id   => $job_id
137
    );
130
}
138
}
131
139
132
if ($findborrower) {
140
if ($findborrower) {
133
- 

Return to bug 23678