updating the reshelving complete query
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 7 Sep 2006 06:41:25 +0000 (06:41 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 7 Sep 2006 06:41:25 +0000 (06:41 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6013 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm

index 78c3bd2..a058fee 100644 (file)
@@ -126,12 +126,17 @@ sub complete_reshelving {
        my $sql = <<"   SQL";
                UPDATE  $cp
                  SET   status = 0
-                 WHERE id IN ( SELECT  cp.id
+                 WHERE id IN
+                       ( SELECT id FROM (
+                               SELECT  cp.id, MAX(circ.checkin_time)
                                  FROM  $cp cp
                                        JOIN $circ circ ON (circ.target_copy = cp.id)
                                  WHERE circ.checkin_time IS NOT NULL
-                                       AND circ.checkin_time < NOW() - CAST(? AS INTERVAL)
-                                       AND cp.status = 7 )
+                                       AND cp.status = 7
+                                 GROUP BY 1
+                                       HAVING MAX(circ.checkin_time) < NOW() - CAST(? AS INTERVAL)
+                       ) AS foo
+               )
        SQL
 
        my $sth = action::circulation->db_Main->prepare_cached($sql);