Problem with node_api hooks

tanc - September 30, 2008 - 04:11
Project:Media Actions
Version:5.x-2.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm using module version 5.x-2.0 with Actions 2 and Em field 5.x-1.x-dev

My local video field name is: field_news_video
My remote video field name is: field_news_video_embed

Everything works fine up to the point where media actions has correctly gathered all the data from blip.tv and has entered the data in the node array. But for some reason that node array isn't being saved, only the original (pre media actions) node array is saved which means the embedded field isn't filled in with the correct url from blip.tv.

I've checked this by adding a dpr($node) in the code. This reveals all the correct information has been added to the node array:

[field_news_video] => Array
        (
        )
[field_news_video_embed] => Array
        (
            [0] => Array
                (
                    [embed] => http://blip.tv/file/1306908/
                    [value] => 1306908
                    [provider] => bliptv
                    [data] => a:1:{s:7:"emthumb";a:0:{}}
                )

        )

Anyone know why the media action's altered node array is not being submitted with the node and consequently saved in the database?

#1

tanc - September 30, 2008 - 08:32
Title:Embed issue» Problem with node_api hooks

Ok, after a day of investigating it seems that using the node_api hooks 'insert' and 'update' hook in too late in the node saving process. 'Insert' and 'Update' are called after the node is saved in the database:

# excerpt from node.module:

  // Insert the node into the database:
  db_query($node_query, $node_table_values);
  db_query($revisions_query, $revisions_table_values);

  // Call the node specific callback (if any):
  if ($node->is_new) {
    node_invoke($node, 'insert');
    node_invoke_nodeapi($node, 'insert');
  }
  else {
    node_invoke($node, 'update');
    node_invoke_nodeapi($node, 'update');
  }

As you can see the db_query has been run before the callback to this action, which means the altered node object doesn't get saved in the database. I think one way to use this action is to alter it so that it does its own database queries after the node has been submitted, updating the embedded field with the correct data.

Otherwise some way of hooking in before the node is saved is needed, although this caused problems in my test with the file not being uploaded correctly. It looks like the video file must be put into the site's file system through a node save before the action can upload it to blip.tv

 
 

Drupal is a registered trademark of Dries Buytaert.