Download & Extend

wrong parameter type in hook_nodeapi

Project:BigBlueButton
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I found a possible bug today and i thought i should share it with you. I've encountered this issue while programmatically updating a node with bbb capabilities. Here is the code:

<?php
$node
->field_adhoc_code[0]['value'] = '123456';
node_save($node);
?>

field_adhoc_code is a cck field, i added to the node type. after changing it and saving the node the hook_nodeapi gets executed. For updating its defined like this in the bbb.module:

<?php
case 'update':
 
// local update
 
bbb_update_meeting($node, $node->bbb);
  break;
?>

The bbb_update_meeting function expects an array as the second parameter:

<?php
function bbb_update_meeting($node, $params = array()) {
 
$params = array_merge($params, bbb_init_meeting($node, $params));
  return
drupal_write_record('bbb_meetings', $params, 'nid');
}
?>

This is where the problem lies, since the hook_nodeapi passes "$node->bbb" which isn't an array but an object of type "stdobject". Subsequently, the array_merge will fail, because the #1 parameter isn't an array. I don't know exactly how you would fix this, i did it by checking the parameter "$params" and casting it with a little trick through the json extension:

<?php
if (is_object($params)) {
 
$params = json_decode(json_encode($params), true);
}
?>

This casts the param to an array. I'm not sure if this fixes all the problems, this is for you to judge ;).

Regards Benjamin