Index: project-usage-process.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/usage/project-usage-process.php,v
retrieving revision 1.2
diff -u -p -r1.2 project-usage-process.php
--- project-usage-process.php	5 Dec 2008 23:37:05 -0000	1.2
+++ project-usage-process.php	11 Dec 2008 16:27:48 -0000
@@ -85,14 +85,28 @@ if (variable_get('project_usage_last_dai
   variable_set('project_usage_last_daily', $now);
 }
 
-// Figure out if it's been a week since we did weekly stats. If the weekly
-// data has never been processed go back only as far as there is daily data.
+/*
+ Figure out if it's been a week since we processed weekly stats, or if the
+ start of the previous usage week is more than one week ago.  Effectively, the
+ last real data we have is the minimum of the last time we processed vs. the
+ start of the last real data week.  Comparing against this value protects this
+ code in the case where the weekly processing is out of sync from when the
+ start of the week happens.  In that case, we might need to process two times
+ in the span of one week to catch up -- what matters is that we've got a full
+ week of data since our last data, not necessarily that it's been one week
+ since we processed.  However, in cases where the weekly processing doesn't
+ run for a week, we might be two or more weeks behind, so we also need to
+ consider when we last processed data so we don't skip weeks.  If the weekly
+ data has never been processed go back only as far as there is daily data.
+*/
 $default = $now - variable_get('project_usage_life_daily', 4 * PROJECT_USAGE_WEEK);
-$last_weekly = variable_get('project_usage_last_weekly', $default);
-if ($last_weekly <= ($now - PROJECT_USAGE_WEEK)) {
-  project_usage_process_weekly($last_weekly);
+$last_week_start = project_usage_weekly_timestamp(NULL, -1);
+$last_weekly_process = variable_get('project_usage_last_weekly', $default);
+$week_ago = $now - PROJECT_USAGE_WEEK;
+$last_data = min($last_week_start, $last_weekly_process);
+if ($last_data <= $week_ago) {
+  project_usage_process_weekly($last_data);
   variable_set('project_usage_last_weekly', $now);
-
   // Reset the list of active weeks.
   project_usage_get_active_weeks(TRUE);
 }
