Index: ezflowoperations.php
===================================================================
--- ezflowoperations.php	(revision 3769)
+++ ezflowoperations.php	(working copy)
@@ -151,6 +151,40 @@
             $db->commit();
         }
 
+        // Remove items that have been moved to trash or deleted
+        $itemArray = array();
+        // Find items that have been moved to trash
+        $items = $db->arrayQuery( 'SELECT DISTINCT object_id
+                                   FROM ezm_pool, ezcontentobject
+                                   WHERE ezm_pool.object_id = ezcontentobject.id
+                                   AND ezcontentobject.status = 2' );
+        if ( $items )
+        {
+            foreach( $items as $item )
+            {
+                $itemArray[] = $item['object_id'];
+            }
+        }
+        // Find items that have been deleted
+        $items = $db->arrayQuery( 'SELECT DISTINCT object_id
+                                   FROM ezm_pool
+                                   WHERE object_id NOT IN ( SELECT id FROM ezcontentobject );' );
+        if ( $items )
+        {
+            foreach( $items as $item )
+            {
+                $itemArray[] = $item['object_id'];
+            }
+        }
+        // Remove them all from the flow
+        if ( count( $itemArray ) > 0 )
+        {
+            $db->begin();
+            $db->query( "DELETE FROM ezm_pool
+                         WHERE object_id IN ( " . implode( ',', $itemArray ) . ")" );
+            $db->commit();
+        }
+
         // Update pool and pages for all nodes
         $res = $db->arrayQuery( "SELECT DISTINCT node_id
                          FROM ezm_block" );
