I have some code (hook_nodeapi) which wants to perform certain validation only when importing & other validation only when not importing (i.e. when the node is created by the usual node forms). This patch adds a field node_importing to the $node, which other code/modules can then detect.

//indicate to other modules that this node is being created by node_import
    $node->node_importing = true;

Robrecht please indicate if you'd prefer I commit changes like this. Since I might foresee argument about this patch I submit as regular patch.

CommentFileSizeAuthor
node_import-add-importing-flag.patch904 bytesdado

Comments

Robrecht Jacques’s picture

If you have a module that implements hook_nodeapi(), you can easily also implement hook_node_import_static() and do a "$node->this_node_is_importing = true" there.

I think that is a better solution because it is more general: some module may have enough by doing "$node->node_importing = true/false", but another may want to know more than that (I don't know what, eg the filename of the file importing or whatever).

The idea of node_import is to create nodes as if they were created through the web, and that's why I dislike having any properties assigned to $node that wouldn't be there is it was created through the web. That's why I also do a "unset($node->...)" in hook_node_import_prepare()". Just to avoid side effects.

Do you think implementing the hook_node_import_static() in your module would be enough? If really not, then I might consider adding this patch to node_import.module.

dado’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

i completely agree. Will add something like this to my site's custom module

/**
 * indicate when we are node_importing
 */
function mysite_node_import_static($type) {
  return array('node_importing'=>true);
}