Index: DEVELOPER.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/Attic/DEVELOPER.txt,v
retrieving revision 1.1.2.13
diff -u -p -r1.1.2.13 DEVELOPER.txt
--- DEVELOPER.txt	15 Jun 2009 22:58:41 -0000	1.1.2.13
+++ DEVELOPER.txt	24 Oct 2009 05:47:05 -0000
@@ -18,6 +18,9 @@ hook_activity_info()
                    @see activity_record(). This is needed because the $object
                    parameter is not available, so we need a key name in order to
                    reference the object from within the $context parameter.
+    eid_field    - the field of the object_type that identifies this activity.
+                   For instance, comment module uses this as 'cid' so that all
+                   activities dealing with that comment can be retrieved or deleted.
     objects      - corresponds to the objects that are passed as properties of
                    the $context array within a module's hook_trigger_name(). @see
                    the example in flag_friend.module - compare it's
Index: activity.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/activity.install,v
retrieving revision 1.1.2.1.2.6.2.4.2.9
diff -u -p -r1.1.2.1.2.6.2.4.2.9 activity.install
--- activity.install	5 Oct 2009 00:17:03 -0000	1.1.2.1.2.6.2.4.2.9
+++ activity.install	24 Oct 2009 05:47:05 -0000
@@ -13,14 +13,13 @@ function activity_schema() {
         'description' => 'The primary identifier for any activity',
         'type' => 'serial',
         'not null' => TRUE,
-        'disp-width' => '11',
         'unsigned' => TRUE,
       ),
       'uid' => array(
         'description' => 'The user id of whomever performed the activity being recorded.',
         'type' => 'int',
         'not null' => TRUE,
-        'disp-width' => '11',
+        'unsigned' => TRUE,
       ),
       'op' => array(
         'description' => 'The operation being performed (update, insert, etc.)',
@@ -35,18 +34,28 @@ function activity_schema() {
         'not null' => TRUE,
        ),
       'nid' => array(
-        'description' => t('A foreign key used with node_access table. Can be NULL for all non-node, comment activities'),
+        'description' => 'A foreign key used with node_access table. Can be NULL for all non-node, comment activities',
+        'type' => 'int',
+        'unsigned' => TRUE,
+      ),
+      'eid' => array(
+        'description' => 'Entity ID used to maintain the relationship between activity and the entity that created the activity',
         'type' => 'int',
+        'default value' => NULL,
+        'unsigned' => TRUE,
       ),
       'created' => array(
-        'description' => t('When the activity was recorded'),
+        'description' => 'When the activity was recorded',
         'type' => 'int',
         'not null' => TRUE,
+        'unsigned' => TRUE,
       ),
     ),
     'primary key' => array('aid'),
     'indexes' => array(
       'nid' => array('nid'),
+      'eid' => array('eid'),
+      'created' => array('created'),
     ),
   );
   
Index: activity.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/activity.module,v
retrieving revision 1.1.2.2.2.30.2.31.2.62
diff -u -p -r1.1.2.2.2.30.2.31.2.62 activity.module
--- activity.module	21 Oct 2009 06:08:12 -0000	1.1.2.2.2.30.2.31.2.62
+++ activity.module	24 Oct 2009 05:47:05 -0000
@@ -37,6 +37,9 @@ function activity_get_module_info($modul
         if (!isset($info->types)) {
           $info->types = array();
         }
+        if (!isset($info->eid_field)) {
+          $info->eid_field = '';
+        }
         $cache[$module] = $info;
       }
     }
@@ -68,6 +71,7 @@ function comment_activity_info() {
   $info->objects = array('comment author' => 'comment', 'node author' => 'node', 'comment author is the node author' => 'node_comment_author'); // array key is the label
   $info->hooks = array('comment' => array('insert', 'update'));
   $info->realms = array('comment' => 'Comment'); // do we need a t()?
+  $info->eid_field = 'cid';
   foreach (node_get_types() as $type) {
     $info->type_options[$type->type] = t($type->name);
   }
@@ -197,16 +201,31 @@ function activity_menu() {
 }
 
 /**
+ * Implementation of hook_comment().
+ */
+function activity_comment(&$comment, $op) {
+  if ($op == 'delete') {
+    $db_result = db_query("SELECT aid FROM {activity} WHERE type = 'comment' AND eid = %d'", $comment->cid);
+    $aids = array();
+    while ($aid_obj = db_fetch_object($db_result)) {
+      $aids[] = $aid_obj->aid;
+    }
+    activity_delete($aids);
+  }
+}
+
+/**
  * Implementation of hook_nodeapi().
  */
 function activity_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   if ($op == 'delete') {
     // Remove all activity records for this node.
-    db_query("DELETE m, at, aa, a FROM {activity} a
-              LEFT JOIN {activity_access} aa ON aa.aid = a.aid
-              INNER JOIN {activity_targets} at ON at.aid = a.aid
-              INNER JOIN {activity_messages} m ON m.amid = at.amid
-              WHERE a.nid = %d", $node->nid);
+    $db_result = db_query("SELECT aid FROM {activity} WHERE nid = %d", $node->nid);
+    $aids = array();
+    while ($aid_obj = db_fetch_object($db_result)) {
+      $aids[] = $aid_obj->aid;
+    }
+    activity_delete($aids);
   }
 }
 
@@ -216,11 +235,12 @@ function activity_nodeapi(&$node, $op, $
 function activity_user($op, &$edit, &$account, $category = NULL) {
   if ($op == 'delete') {
     // Remove all activity records for this user.
-    db_query("DELETE m, at, aa, a FROM {activity} a
-              LEFT JOIN {activity_access} aa ON aa.aid = a.aid
-              INNER JOIN {activity_targets} at ON at.aid = a.aid
-              INNER JOIN {activity_messages} m ON m.amid = at.amid
-              WHERE a.uid = %d", $account->uid);
+    $db_result = db_query("SELECT aid FROM {activity} WHERE uid = %d", $account->uid);
+    $aids = array();
+    while ($aid_obj = db_fetch_object($db_result)) {
+      $aids[] = $aid_obj->aid;
+    }
+    activity_delete($aids);
   }
 }
 
@@ -533,6 +553,14 @@ function activity_record($object, $conte
   $record->type = $activity_object->name;
   $record->nid = $nid;
   $record->created = time(); // for PHP4 compat. for D7 use REQUEST_TIME
+  
+  // handle the entity id
+  if (!empty($info->eid_field) && isset($context[$type]->{$info->eid_field})) {
+    $record->eid = $context[$type]->{$info->eid_field};
+  }
+  else {
+    $record->eid = NULL;
+  }
 
   // allow other modules to manipulate the record before insertion
   drupal_alter('activity_record', $record, $context);
@@ -638,16 +666,22 @@ function activity_get_grants($record, $o
 /**
  * Delete an activity message.
  *
- * @param int $aid
- *   The activity message id for the activity message table.
+ * @param array $aids
+ *   The activity id or an array of actvity ids for the activity message table.
  */
-function activity_delete($aid) {
+function activity_delete($aids) {
+  if (is_numeric($aids)) {
+    $aids = array($aids);
+  }
+  if (!is_array($aids)) {
+    return; // early exit
+  }
   // This is MySQL specific multitable delete
   db_query("DELETE m, at, aa, a FROM {activity} a
            LEFT JOIN {activity_access} aa ON aa.aid = a.aid
            INNER JOIN {activity_targets} at ON at.aid = a.aid
            INNER JOIN {activity_messages} m ON m.amid = at.amid
-           WHERE a.aid = %d", $aid
+           WHERE a.aid IN (" . db_placeholders($aids) . ")", $aids
   );
 }
 
