backporting the relevant portions of r15619, get a matchpoint as early as possible...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 9 Mar 2010 15:49:57 +0000 (15:49 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 9 Mar 2010 15:49:57 +0000 (15:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_0@15759 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/100.circ_matrix.sql
Open-ILS/src/sql/Pg/110.hold_matrix.sql

index 9eb1d5b..25d05f5 100644 (file)
@@ -241,7 +241,7 @@ BEGIN
     -- Fail if the user is BARRED
     SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
 
-    -- Fail if we couldn't find a set of tests
+    -- Fail if we couldn't find the user 
     IF user_object.id IS NULL THEN
         result.fail_part := 'no_user';
         result.success := FALSE;
@@ -250,6 +250,28 @@ BEGIN
         RETURN;
     END IF;
 
+    SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
+
+    -- Fail if we couldn't find the item 
+    IF item_object.id IS NULL THEN
+        result.fail_part := 'no_user';
+        result.success := FALSE;
+        done := TRUE;
+        RETURN NEXT result;
+        RETURN;
+    END IF;
+
+    SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, match_item, match_user, renewal);
+    result.matchpoint := circ_test.id;
+
+    -- Fail if we couldn't find a matchpoint
+    IF result.matchpoint IS NULL THEN
+        result.fail_part := 'no_matchpoint';
+        result.success := FALSE;
+        done := TRUE;
+        RETURN NEXT result;
+    END IF;
+
     IF user_object.barred IS TRUE THEN
         result.fail_part := 'actor.usr.barred';
         result.success := FALSE;
@@ -258,7 +280,6 @@ BEGIN
     END IF;
 
     -- Fail if the item can't circulate
-    SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
     IF item_object.circulate IS FALSE THEN
         result.fail_part := 'asset.copy.circulate';
         result.success := FALSE;
@@ -288,19 +309,8 @@ BEGIN
         RETURN NEXT result;
     END IF;
 
-    SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, match_item, match_user, renewal);
-    result.matchpoint := circ_test.id;
-
     SELECT INTO context_org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( circ_test.org_unit );
 
-    -- Fail if we couldn't find a set of tests
-    IF result.matchpoint IS NULL THEN
-        result.fail_part := 'no_matchpoint';
-        result.success := FALSE;
-        done := TRUE;
-        RETURN NEXT result;
-    END IF;
-
     -- Fail if the test is set to hard non-circulating
     IF circ_test.circulate IS FALSE THEN
         result.fail_part := 'config.circ_matrix_test.circulate';
index 2da8808..b7e792c 100644 (file)
@@ -185,6 +185,8 @@ BEGIN
     SELECT INTO user_object * FROM actor.usr WHERE id = match_user;
     SELECT INTO context_org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( pickup_ou );
 
+    result.success := TRUE;
+
     -- Fail if we couldn't find a user
     IF user_object.id IS NULL THEN
         result.fail_part := 'no_user';
@@ -194,15 +196,6 @@ BEGIN
         RETURN;
     END IF;
 
-    -- Fail if user is barred
-    IF user_object.barred IS TRUE THEN
-        result.fail_part := 'actor.usr.barred';
-        result.success := FALSE;
-        done := TRUE;
-        RETURN NEXT result;
-        RETURN;
-    END IF;
-
     SELECT INTO item_object * FROM asset.copy WHERE id = match_item;
 
     -- Fail if we couldn't find a copy
@@ -215,6 +208,16 @@ BEGIN
     END IF;
 
     SELECT INTO matchpoint_id action.find_hold_matrix_matchpoint(pickup_ou, request_ou, match_item, match_user, match_requestor);
+    result.matchpoint := matchpoint_id;
+
+    -- Fail if user is barred
+    IF user_object.barred IS TRUE THEN
+        result.fail_part := 'actor.usr.barred';
+        result.success := FALSE;
+        done := TRUE;
+        RETURN NEXT result;
+        RETURN;
+    END IF;
 
     -- Fail if we couldn't find any matchpoint (requires a default)
     IF matchpoint_id IS NULL THEN
@@ -227,9 +230,6 @@ BEGIN
 
     SELECT INTO hold_test * FROM config.hold_matrix_matchpoint WHERE id = matchpoint_id;
 
-    result.matchpoint := hold_test.id;
-    result.success := TRUE;
-
     IF hold_test.holdable IS FALSE THEN
         result.fail_part := 'config.hold_matrix_test.holdable';
         result.success := FALSE;