I have a custom Trigger that is set to execute when a particular type of content is created. The content may be created by anonymous users, so I want them to be redirected to a thank you for your submission page instead of the content itself. The reason being that the content should not be visible by anonymous users. Additionally, I want an email to be sent to an administrator when the content is created.

I have been beating my head trying to figure out why the email was never being sent until I noticed on line 97 of includes/actions.inc this comment: "// Fire actions, in no particular order." The issue that I was facing is that the redirect action was created first and therefore had a lower aid than the email action. Unfortunately, the actions are executed in "no particular order" which seems to usually be in aid order as that is what the database call returns.

Could core be modified to execute the actions in the order that they are passed to actions_do in the action_ids array? The attached patch does this just fine and doesn't change any other behavior

CommentFileSizeAuthor
actions-in-order.patch651 bytesdouglasmiller

Comments

neRok’s picture

Version: 7.15 » 7.x-dev
Component: base system » action.module
Status: Active » Needs work

Further up actions_do() is the following code

    $conditions = array();
    foreach ($action_ids as $action_id) {
      if (is_numeric($action_id)) {
        $conditions[] = $action_id;
      }
      elseif (isset($available_actions[$action_id])) {
        $actions[$action_id] = $available_actions[$action_id];
      }
    }

After this, $conditions is used as db query and added to $actions. Then the actions in $actions fire.

The problem I see with your patch is that you presume that each $action_ids is-set within $actions. Based on the two if statements above though, it is possible that an action could not be found for the action_id, and was not added to $actions. I think the patch needs a tweak to accommodate this.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.