} elsif( $vol->ischanged ) {
$logger->info("vol-update: update volume");
- my $resp = update_volume($vol, $editor, ($oargs->{all} or grep { $_ eq 'VOLUME_LABEL_EXISTS' } @{$oargs->{events}} or $auto_merge_vols));
- return $resp->{evt} if $resp->{evt};
- $vol = $resp->{merge_vol} if $resp->{merge_vol};
+
+ # check to see if we're editing all existing copies
+ my $editing_all_copies = 1;
+ my $all_copies = $editor->search_asset_copy({
+ call_number => $vol->id,
+ deleted => 'f'
+ });
+ my $edit_map = {};
+ foreach my $id (map { $_->id } @$copies) {
+ $edit_map->{$id} = 1;
+ }
+ foreach my $id (map { $_->id } @$all_copies) {
+ if (! $edit_map->{$id}) {
+ $editing_all_copies = 0;
+ }
+ }
+
+ if ($editing_all_copies) { # edit existing volume (and potentially auto-merge)
+
+ my $resp = update_volume($vol, $editor, ($oargs->{all} or grep { $_ eq 'VOLUME_LABEL_EXISTS' } @{$oargs->{events}} or $auto_merge_vols));
+ return $resp->{evt} if $resp->{evt};
+ $vol = $resp->{merge_vol} if $resp->{merge_vol};
+
+ } else { # create new volume (and potentially auto-merge)
+
+ ($vol,$evt) = $assetcom->create_volume( $auto_merge_vols ? { all => 1} : $oargs, $editor, $vol );
+ return $evt if $evt;
+
+ }
}
# now update any attached copies