Trying to get this to work with a custom module but I'm getting the same error as Fatal error when deleting Heartbeat Template.

I'm using the statuses module for my first test but I plan to use heartbeat for a lot of activity. This is just test 1 but I can't get it to work. The statuses module is not currently working with rules so I can't make a rule for when a status is submitted. Either way I'd really prefer to do this with a custom module.

I have a function that is executed when a status is submitted, there I have this code:

global $user;
$message_id = 'user_updated_status';
$variables = array(
  '@username' => l(custom_full_name($user->uid), 'user/' . $user->uid),
  '@node_type' => 'status',
  '@node_title' => l('status', 'statuses/' . $status->sid),
);
heartbeat_api_log($message_id, $user->uid, 0, $status->sid, 0, $variables);

And then I have a custom module with this code:

function my_module_heartbeat_message_info() { 
  $info = array( 

    0 => 
    array( 
      'message' => '!username updated his/her !node_title', 
      'message_concat' => '!user updated his/her !node_title', 
      'message_id' => 'user_updated_status', 
      'concat_args' => 
		  array( 
			'type' => '', 
			'group_by' => '', 
			'group_target' => '', 
			'group_by_target' => '', 
			'group_num_max' => '', 
			'merge_separator' => ',', 
			'merge_end_separator' => '', 
			'roles' => 
				array( 
				  0 => '0', 
				  1 => '0', 
				  2 => '0', 
				  3 => '0', 
				  4 => '0', 
				  5 => '0', 
			), 
		  ), 
      'description' => 'User updated status', 
      'perms' => '1', 
      'custom' => '0', 
      'variables' => 
      array( 
      ), 
    ), 
  ); 

  return $info; 

}

When I try to post a status which of course was working fine before I get:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /statuses/ajax
StatusText: error
ResponseText: Recoverable fatal error: Argument 2 passed to HeartbeatActivity::__construct() must be an instance of HeartbeatMessageTemplate, null given, called in /www/sites/all/modules/heartbeat/heartbeat.module on line 612 and defined in HeartbeatActivity->__construct() (line 67 of /www/sites/all/modules/heartbeat/includes/heartbeatactivity.inc).

So I guess this means I don't have a template but again I can't use rules and I thought the hook_heartbeat_message_info() was to create the template.

Any help?

Comments

favosys’s picture

So no help, I guess I can't use heartbeat and activity doesn't have an official D7 release, anybody know of another module I can use?

Stalski’s picture

Please update to the dev version. A release will come out soon. The dev version has much bug fixes and improvements.

- Edit - I just saw you originally posted 2 days ago. Do you realize that drupal modules are developed by volunteers and that whole community you are asking questions too is doing the best they can?
I would be happy to help you if you are a little more patient.

Stalski’s picture

Status: Active » Closed (cannot reproduce)

So

Trying to get this to work with a custom module but I'm getting the same error as Fatal error when deleting Heartbeat Template.

This would be fixed in latest dev.

I'm using the statuses module for my first test but I plan to use heartbeat for a lot of activity. This is just test 1 but I can't get it to work. The statuses module is not currently working with rules so I can't make a rule for when a status is submitted. Either way I'd really prefer to do this with a custom module.

Each developer and even non-developers can easily create that rule for user style statusses. There are lots of examples on how to trigger that "onSaveStatus" thing.
I also prefer to log activity by code. You can easily do that in a custom module. This is done by calling the heartbeat_api_log function manually from the hook that provides the event. There is a very good example in the heartbeat_example module that ships with the module. Just mind the "!" in the messages and the "@" in the variables at log time.

BTW: I just saw you did it like that :) . Well I don't see any reason why it would not work. I also tried this and it works great.

favosys’s picture

Updated to dev and got a similar msg

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /statuses/ajax
StatusText: error
ResponseText: Recoverable fatal error: Argument 2 passed to HeartbeatActivity::__construct() must be an instance of HeartbeatMessageTemplate, null given, called in /www/sites/all/modules/heartbeat/heartbeat.module on line 819 and defined in HeartbeatActivity->__construct() (line 68 of /www/sites/all/modules/heartbeat/includes/heartbeatactivity.inc).

Stalski’s picture

Well that errors tells us that a heartbeatActivity object must be constructed with a HeartbeatMessageTemplate as second parameter.
So in your case this is not working and that can only mean one thing ... that your message template you are addressing is not there.
Check the name (user_updated_status does not exist appearantly.) and it will work just fine.

If it is there, with that machine name, then I can only recommend to remove it and add it again or something.