|
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; |