Lines 120-146
if ( $op eq 'cud-move' ) {
Link Here
|
120 |
my @success_messages; |
120 |
my @success_messages; |
121 |
my @error_messages; |
121 |
my @error_messages; |
122 |
|
122 |
|
123 |
foreach my $hold_id (@hold_ids) { |
123 |
#Get a list of all the holds to move, ordered by current priority |
124 |
my $hold = Koha::Holds->find($hold_id); |
124 |
my @moving_holds = Koha::Holds->search( |
|
|
125 |
{ reserve_id => \@hold_ids }, |
126 |
{ order_by => { -asc => 'priority' } } |
127 |
)->as_list; |
128 |
|
129 |
#Get the highest current priority of the target biblio |
130 |
my $highest_priority = Koha::Holds->search( |
131 |
{ biblionumber => $new_biblionumber }, |
132 |
{ order_by => { -desc => 'priority' }, rows => 1 } |
133 |
)->next; |
134 |
|
135 |
#Get a starting priority point to increment from on the new biblio |
136 |
my $base_priority = $highest_priority ? $highest_priority->priority : 0; |
137 |
|
138 |
my $offset = 0; |
139 |
foreach my $hold (@moving_holds) { |
125 |
my $original_biblio = Koha::Biblios->find( $hold->biblionumber ); |
140 |
my $original_biblio = Koha::Biblios->find( $hold->biblionumber ); |
126 |
my $result = $hold->move_hold_item( |
141 |
|
|
|
142 |
#increment priority |
143 |
my $priority = ( $base_priority + $offset++ ) + 1; |
144 |
my $result = $hold->move_hold_item( |
127 |
{ |
145 |
{ |
128 |
new_itemnumber => $new_itemnumber, |
146 |
new_itemnumber => $new_itemnumber, |
129 |
new_biblionumber => $new_biblionumber, |
147 |
new_biblionumber => $new_biblionumber, |
|
|
148 |
priority => $priority |
130 |
} |
149 |
} |
131 |
); |
150 |
); |
132 |
|
151 |
|
133 |
#push info about successes and errors to the template |
152 |
#push info about successes and errors to the template |
134 |
if ( $result->{success} ) { |
153 |
if ( $result->{success} ) { |
135 |
push @success_messages, { |
154 |
push @success_messages, { |
136 |
hold_id => $hold_id, |
155 |
hold_id => $hold->id, |
137 |
success => 1, |
156 |
success => 1, |
138 |
original_biblio => $original_biblio, |
157 |
original_biblio => $original_biblio, |
139 |
target_biblio => $target_biblio, |
158 |
target_biblio => $target_biblio, |
140 |
}; |
159 |
}; |
141 |
} else { |
160 |
} else { |
142 |
push @error_messages, { |
161 |
push @error_messages, { |
143 |
hold_id => $hold_id, |
162 |
hold_id => $hold->id, |
144 |
success => 0, |
163 |
success => 0, |
145 |
original_biblio => $original_biblio, |
164 |
original_biblio => $original_biblio, |
146 |
target_biblio => $target_biblio, |
165 |
target_biblio => $target_biblio, |
147 |
- |
|
|