LP1883171 & LP1940663: Modify new update inventory method
authorJason Stephenson <jason@sigio.com>
Sat, 8 Jan 2022 19:01:43 +0000 (14:01 -0500)
committerJason Stephenson <jason@sigio.com>
Sun, 9 Jan 2022 01:26:23 +0000 (20:26 -0500)
Modify the new circ update asset copy inventory method based on
testing:

1. Use savepoints to allow some updates to succeed when others fail.

2. Modify the return value to include success and failure counts so that
these could potentially be used in client feedback.

This work was sponsored by NOBLE.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm

index 23f99d4..6436f79 100644 (file)
@@ -376,19 +376,34 @@ __PACKAGE__->register_method(
 
 sub update_copy_inventory {
     my( $self, $conn, $auth, $args ) = @_;
-    my $e = new_editor(authtoken=>$auth, xact=>1);
-    return $e->die_event unless $e->checkauth;
+    my $e = new_editor(authtoken=>$auth);
+    return [0, 0, $e->die_event] unless $e->checkauth;
 
+    my ($success,$failure) = (0,0);
+    my $spname = "aci_update_savepoint";
+    $e->xact_begin();
     my $copies = $$args{copy_list};
     foreach my $copyid (@$copies) {
         my $aci = Fieldmapper::asset::copy_inventory->new;
         $aci->inventory_date('now');
         $aci->inventory_workstation($e->requestor->wsid);
         $aci->copy($copyid);
-        $e->create_asset_copy_inventory($aci) or return $e->die_event;
+        $e->set_savepoint($spname);
+        if ($e->create_asset_copy_inventory($aci)) {
+            $success++;
+        } else {
+            $failure++;
+            $e->rollback_savepoint($spname);
+        }
+        $e->release_savepoint($spname);
     }
-    $e->commit;
-    return 1;
+    if ($success) {
+        $e->commit();
+    } else {
+        $e->rollback();
+    }
+
+    return [ $success, $failure ];
 }
 
 __PACKAGE__->register_method(