[open-ils-commits] r13464 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Cat (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jun 24 23:03:34 EDT 2009
Author: erickson
Date: 2009-06-24 23:03:32 -0400 (Wed, 24 Jun 2009)
New Revision: 13464
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm
Log:
when a copy is manually edited and is either deleted or changed into a non-holdable status, reset any holds whose current_copy matches the changed copy
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm 2009-06-25 03:02:03 UTC (rev 13463)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm 2009-06-25 03:03:32 UTC (rev 13464)
@@ -135,7 +135,7 @@
sub update_copy {
- my($class, $editor, $override, $vol, $copy) = @_;
+ my($class, $editor, $override, $vol, $copy, $retarget_holds) = @_;
my $evt;
my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;
@@ -152,15 +152,47 @@
if ref $copy->age_protect;
$class->fix_copy_price($copy);
+ $class->check_hold_retarget($editor, $copy, $orig_copy, $retarget_holds);
return $editor->event unless $editor->update_asset_copy($copy);
return $class->remove_empty_objects($editor, $override, $orig_vol);
}
+sub check_hold_retarget {
+ my($class, $editor, $copy, $orig_copy, $retarget_holds) = @_;
+ return unless $retarget_holds;
+ if( !($copy->isdeleted or $U->is_true($copy->deleted)) ) {
+ # see if a status change warrants a retarget
+
+ $orig_copy = $editor->retrieve_asset_copy($copy->id) unless $orig_copy;
+
+ if($orig_copy->status == $copy->status) {
+ # no status change, no retarget
+ return;
+ }
+
+ my $stat = $editor->retrieve_config_copy_status($copy->status);
+
+ # new status is holdable, no retarget. Later add logic to find potential
+ # holds and retarget those to pick up the newly available copy
+ return if $U->is_true($stat->holdable);
+ }
+
+ my $hold_ids = $editor->search_action_hold_request(
+ { current_copy => $copy->id,
+ cancel_time => undef,
+ fulfillment_time => undef
+ }, {idlist => 1}
+ );
+
+ push(@$retarget_holds, @$hold_ids);
+}
+
+
# this does the actual work
sub update_fleshed_copies {
- my($class, $editor, $override, $vol, $copies, $delete_stats) = @_;
+ my($class, $editor, $override, $vol, $copies, $delete_stats, $retarget_holds) = @_;
my $evt;
my $fetchvol = ($vol) ? 0 : 1;
@@ -193,7 +225,7 @@
$copy->clear_stat_cat_entries;
if( $copy->isdeleted ) {
- $evt = $class->delete_copy($editor, $override, $vol, $copy);
+ $evt = $class->delete_copy($editor, $override, $vol, $copy, $retarget_holds);
return $evt if $evt;
} elsif( $copy->isnew ) {
@@ -202,7 +234,7 @@
} elsif( $copy->ischanged ) {
- $evt = $class->update_copy( $editor, $override, $vol, $copy );
+ $evt = $class->update_copy( $editor, $override, $vol, $copy, $retarget_holds );
return $evt if $evt;
}
@@ -218,7 +250,7 @@
sub delete_copy {
- my($class, $editor, $override, $vol, $copy ) = @_;
+ my($class, $editor, $override, $vol, $copy, $retarget_holds ) = @_;
return $editor->event unless
$editor->allowed('DELETE_COPY', $class->copy_perm_org($vol, $copy));
@@ -249,6 +281,8 @@
or return $editor->event;
}
+ $class->check_hold_retarget($editor, $copy, undef, $retarget_holds);
+
return $class->remove_empty_objects($editor, $override, $vol);
}
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm 2009-06-25 03:02:03 UTC (rev 13463)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm 2009-06-25 03:03:32 UTC (rev 13464)
@@ -449,19 +449,32 @@
return $evt if $evt;
my $editor = new_editor(requestor => $reqr, xact => 1);
my $override = $self->api_name =~ /override/;
+ my $retarget_holds = [];
$evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies(
- $editor, $override, undef, $copies, $delete_stats);
+ $editor, $override, undef, $copies, $delete_stats, $retarget_holds);
+
if( $evt ) {
$logger->info("fleshed copy update failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt));
$editor->rollback;
return $evt;
}
+
$editor->commit;
$logger->info("fleshed copy update successfully updated ".scalar(@$copies)." copies");
+ reset_hold_list($auth, $retarget_holds);
+
return 1;
}
+sub reset_hold_list {
+ my($auth, $hold_ids) = @_;
+ return unless @$hold_ids;
+ $logger->info("reseting holds after copy status change: @$hold_ids");
+ my $ses = OpenSRF::AppSession->create('open-ils.circ');
+ $ses->request('open-ils.circ.hold.reset.batch', $auth, $hold_ids);
+}
+
__PACKAGE__->register_method(
method => 'merge',
api_name => 'open-ils.cat.biblio.records.merge',
@@ -572,6 +585,7 @@
my $override = ($self->api_name =~ /override/);
my $editor = new_editor( requestor => $reqr, xact => 1 );
+ my $retarget_holds = [];
for my $vol (@$volumes) {
$logger->info("vol-update: investigating volume ".$vol->id);
@@ -613,12 +627,13 @@
if( $copies and @$copies and !$vol->isdeleted ) {
$_->call_number($vol->id) for @$copies;
$evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies(
- $editor, $override, $vol, $copies, $delete_stats);
+ $editor, $override, $vol, $copies, $delete_stats, $retarget_holds);
return $evt if $evt;
}
}
$editor->finish;
+ reset_hold_list($auth, $retarget_holds);
return scalar(@$volumes);
}
More information about the open-ils-commits
mailing list