Index: server/pift_server.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue_file_test/server/pift_server.install,v
retrieving revision 1.6
diff -u -p -r1.6 pift_server.install
--- server/pift_server.install	25 Oct 2008 14:14:42 -0000	1.6
+++ server/pift_server.install	2 Nov 2008 09:11:20 -0000
@@ -101,4 +101,48 @@ function pift_server_uninstall() {
   }
 
   drupal_set_message(t('The Project issue file test server module was uninstalled successfully.'));
-}
\ No newline at end of file
+}
+
+/**
+ * Ensure that files added between the last cron run and the next node or
+ * comment insert are added to the pift queue.
+ */
+function pift_server_update_1() {
+
+  global $base_url;
+
+  // Pull both the last items processed, and the newest items submitted.
+  // This is the range that we can enter into the queue during this run.
+  $last = pift_server_get_last();
+  $newest = pift_server_get_newest();
+  $data['issues'] = array();
+  $data['followups'] = array();
+
+  // Pull all new issue data. Limit the results to 5 times the PIFT_SEND_LIMIT for consistency.
+  $issue_files = db_query_range("SELECT n.nid, n.uid, f.fid, f.filepath FROM {node} n INNER JOIN {files} f ON n.nid = f.nid WHERE n.type = 'project_issue' AND f.fid > %d AND f.fid <= %d AND f.filepath <> '' ORDER BY n.nid, f.fid", $last['issue'], $newest['issue'], 0, PIFT_SEND_LIMIT * 5);
+
+  while ($file = db_fetch_object($issue_files)) {
+    // Update last processed here, in case the server dies during the run.
+    variable_set('pift_server_last_issue_file_processed', $file->fid);
+
+    // Put the file data into the send queue.
+    if (preg_match(PIFT_FILE_REGEX, basename($file->filepath)) && file_exists($file->filepath)) {
+      $ftid = db_next_id('{pift_data}_ftid');
+      db_query("INSERT INTO {pift_data} (ftid, fid, nid, cid, uid, display_data, status, timestamp) VALUES (%d, %d, %d, %d, %d, '%s', %d, %d)", $ftid, $file->fid, $file->nid, 0, $file->uid, '', PIFT_UNTESTED, 0);
+    }
+  }
+
+  // Pull all new followup file data. Limit the results to 5 times the PIFT_SEND_LIMIT for consistency.
+  $followup_files = db_query_range("SELECT n.nid, c.cid, c.uid, cu.fid, cu.filepath FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {comment_upload_files} cu ON c.cid = cu.cid WHERE n.type = 'project_issue' AND cu.fid > %d AND cu.fid <= %d AND cu.filepath <> '' ORDER BY c.cid, cu.fid", $last['followup'], $newest['followup'], 0, PIFT_SEND_LIMIT * 5);
+
+  while ($file = db_fetch_object($followup_files)) {
+    // Update last processed here, in case the server dies during the run.
+    variable_set('pift_server_last_followup_file_processed', $file->fid);
+
+    // Put the file data into the send queue.
+    if (preg_match(PIFT_FILE_REGEX, basename($file->filepath)) && file_exists($file->filepath)) {
+      $ftid = db_next_id('{pift_data}_ftid');
+      db_query("INSERT INTO {pift_data} (ftid, fid, nid, cid, uid, display_data, status, timestamp) VALUES (%d, %d, %d, %d, %d, '%s', %d, %d)", $ftid, $file->fid, $file->nid, $file->cid, $file->uid, '', PIFT_UNTESTED, 0);
+    }
+  }
+}
Index: server/pift_server.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue_file_test/server/pift_server.module,v
retrieving revision 1.22
diff -u -p -r1.22 pift_server.module
--- server/pift_server.module	26 Oct 2008 00:51:36 -0000	1.22
+++ server/pift_server.module	2 Nov 2008 09:11:20 -0000
@@ -37,7 +37,6 @@ function pift_server_cron() {
     $frequency = $send * 60;
     // Time to send again?
     if ($time > ($last_sent + $frequency)) {
-      pift_server_add_new_files();
       pift_server_retest_check();
       pift_server_send_file_data();
       // Update last sent time.
@@ -391,45 +390,19 @@ function pift_server_reset_send_queue() 
 }
 
 /**
- * Adds newly submitted issues/folowups to the send queue.
+ * Adds files matching PIFT_FILE_REGEX to the send queue.
+ *
+ * @param $files
+ *   An array of file objects.
  */
-function pift_server_add_new_files() {
-  global $base_url;
-
-  // Pull both the last items processed, and the newest items submitted.
-  // This is the range that we can enter into the queue during this run.
-  $last = pift_server_get_last();
-  $newest = pift_server_get_newest();
-  $data['issues'] = array();
-  $data['followups'] = array();
-
-  // Pull all new issue data. Limit the results to 5 times the PIFT_SEND_LIMIT for consistency.
-  $issue_files = db_query_range("SELECT n.nid, n.uid, f.fid, f.filepath FROM {node} n INNER JOIN {files} f ON n.nid = f.nid WHERE n.type = 'project_issue' AND f.fid > %d AND f.fid <= %d AND f.filepath <> '' ORDER BY n.nid, f.fid", $last['issue'], $newest['issue'], 0, PIFT_SEND_LIMIT * 5);
-
-  while ($file = db_fetch_object($issue_files)) {
-    // Update last processed here, in case the server dies during the run.
-    variable_set('pift_server_last_issue_file_processed', $file->fid);
-
+function pift_server_add_files($files) {
+  foreach ($files as $file) {
     // Put the file data into the send queue.
     if (preg_match(PIFT_FILE_REGEX, basename($file->filepath)) && file_exists($file->filepath)) {
       $ftid = db_next_id('{pift_data}_ftid');
       db_query("INSERT INTO {pift_data} (ftid, fid, nid, cid, uid, display_data, status, timestamp) VALUES (%d, %d, %d, %d, %d, '%s', %d, %d)", $ftid, $file->fid, $file->nid, 0, $file->uid, '', PIFT_UNTESTED, 0);
     }
   }
-
-  // Pull all new followup file data. Limit the results to 5 times the PIFT_SEND_LIMIT for consistency.
-  $followup_files = db_query_range("SELECT n.nid, c.cid, c.uid, cu.fid, cu.filepath FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {comment_upload_files} cu ON c.cid = cu.cid WHERE n.type = 'project_issue' AND cu.fid > %d AND cu.fid <= %d AND cu.filepath <> '' ORDER BY c.cid, cu.fid", $last['followup'], $newest['followup'], 0, PIFT_SEND_LIMIT * 5);
-
-  while ($file = db_fetch_object($followup_files)) {
-    // Update last processed here, in case the server dies during the run.
-    variable_set('pift_server_last_followup_file_processed', $file->fid);
-
-    // Put the file data into the send queue.
-    if (preg_match(PIFT_FILE_REGEX, basename($file->filepath)) && file_exists($file->filepath)) {
-      $ftid = db_next_id('{pift_data}_ftid');
-      db_query("INSERT INTO {pift_data} (ftid, fid, nid, cid, uid, display_data, status, timestamp) VALUES (%d, %d, %d, %d, %d, '%s', %d, %d)", $ftid, $file->fid, $file->nid, $file->cid, $file->uid, '', PIFT_UNTESTED, 0);
-    }
-  }
 }
 
 /**
@@ -853,6 +826,11 @@ function pift_server_nodeapi(&$node, $op
           '#weight' => 51,  // Just below the upload attachments.
         );
         break;
+      case 'insert':
+        // Add attachments for this node to the send queue.
+        $files = upload_load($node);
+        pift_server_add_files($files);
+        break;
       case 'delete':
         // Remove related data in the test results table.
         db_query("DELETE FROM {pift_data} WHERE nid = %d", $node->nid);
@@ -934,6 +912,11 @@ function pift_server_comment(&$comment, 
         $comment->comment .= $cids[$comment->cid];
       }
       break;
+    case 'insert':
+      // Add attachments to this comment to the send queue.
+      $files = _comment_upload_load_files($comment->cid);
+      pift_server_add_files($files);
+      break;
     case 'update':
       // If files were deleted, remove related data in the test results table.
       if (is_array($comment['files'])) {
