3

I am using this module under Drupal 7 to execute some code after nodes of a particular content type get updated. My question, is this module reliable? Would the post save event be called every time my target nodes get updated?

This is the module's page: https://www.drupal.org/project/hook_post_action

1 Answer 1

5

The module register a shutdown function in hook_entiyt_delete(), hook_entity_insert(), and hook_entity_update().

/**
 * @param $entity
 * @param $type
 */
function hook_post_action_entity_insert($entity, $type) {
  drupal_register_shutdown_function('_hook_post_action_post_save', $entity, $type, 'insert');
}

As such, the hooks invoked from that shutdown function are always invoked, except in the case the shutdown function is not called, which as the documentation for register_shutdown() says, it can happen if the process is killed with a SIGTERM or SIGKILL signal. Since PHP doesn't have a function to removed a shutdown function, I would say the module is reliable.

As side note, hook_node_postsave() and hook_entity_postsave() are always invoked, whenever the entity is created, updated, or deleted.

/**
 * @param $entity
 * @param $type
 * @param $op
 */
function _hook_post_action_post_save($entity, $type, $op) {
  $entity_is_saved = FALSE;
  $new_entity = NULL;

  if ($op == 'insert' || $op == 'update') {
    $entity_is_saved = TRUE;
  }
  if ($op == 'delete') {
    list($id) = entity_extract_ids($type, $entity);
    $new_entity = entity_load($type, array($id));
    if (!$new_entity) {
      $entity_is_saved = TRUE;
    }
  }
  if ($entity_is_saved) {
    module_invoke_all('entity_post' . $op, $entity, $type);
    module_invoke_all('entity_postsave', $entity, $type, $op);

    if ($type == 'node') {
      module_invoke_all('node_post' . $op, $entity);
      module_invoke_all('node_postsave', $entity, $op);
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.