From 7546987220b1b9f5c7468f59dda3a121de749b6c Mon Sep 17 00:00:00 2001
From: Katherine Bailey <katherine@katbailey.net>
Date: Thu, 21 Apr 2011 12:39:10 -0700
Subject: [PATCH] Issue #1134898: checking for a valid handler object

---
 activity.module |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git activity.module activity.module
index 9b6adb3..c16f680 100644
--- activity.module
+++ activity.module
@@ -288,7 +288,7 @@ function activity_recreate_messages(array $records) {
   foreach ($records as $record) {
     // Load the handler and check it its batchable.
     $handler = activity_handler_load($record->actions_id);
-    if ($handler->batch) {
+    if ($handler && $handler->batch) {
       $amids = db_query("SELECT amid FROM {activity_targets} WHERE aid = :aid", array(":aid" => $record->aid))->fetchCol();
 
       if (!empty($amids)) {
@@ -368,14 +368,19 @@ function activity_update_status($activity_records) {
     $status = ACTIVITY_PUBLISHED;
 
     // Figure out if the status should be 1 or 0.
-    $handler = activity_handler_load($record->actions_id);
-    $objects = $handler->loadObjects($record->eid);
-    drupal_alter('activity_objects', $objects, $handler->type);
-
-    if (!$handler->isPublished($objects, $record->uid)) {
+    if ($handler = activity_handler_load($record->actions_id)) {
+      $objects = $handler->loadObjects($record->eid);
+      drupal_alter('activity_objects', $objects, $handler->type);
+  
+      if (!$handler->isPublished($objects, $record->uid)) {
+        $status = ACTIVITY_NOT_PUBLISHED;
+      }
+    }
+    else {
+      // The handler for this activity somehow doesn't exist anymore, so the
+      // status should probably be unpublished.
       $status = ACTIVITY_NOT_PUBLISHED;
     }
-
     $updated_activity[$status][] = $record->aid;
   }
 
-- 
1.7.4.1

