I'm trying to make a basic publishing workflow where a node moves from "draft" to a "published" state, but when I create these states, there is no option to "publish node" as a choice under actions.

Am I missing something here, or is this just not functioning?

Thanks!

Comments

Bastlynn’s picture

Status: Active » Postponed (maintainer needs more info)

Do you have the workflow_actions module turned on?
I need a little more detail about what pages you're looking at to help you with this.

Anonymous’s picture

Status: Postponed (maintainer needs more info) » Needs work
StatusFileSize
new53.56 KB

I'm having the same issue (using latest dev-release). Workflow_actions is enabled.
The triggers are missing at /admin/structure/trigger/workflow/2
I'm expecting a 'publish node' trigger overthere.

Please see the attached screenshot for more clarification.

Jessica A’s picture

JesseDP's screenshot is the same issue I have

wonder95’s picture

StatusFileSize
new1.17 KB

The problem is that the node publish action is only defined for the following triggers in node.module:

  • node_presave
  • comment_insert
  • comment_update
  • comment_delete

So the trick is to define the action for the different workflow transitions. The attached patch does that with a hook_drupal_alter() implementation that gets all the available transitions and defines them as triggers for the node_publish action. This gets them to show up at admin/structure/trigger/workflow/%d.

wonder95’s picture

Status: Needs work » Needs review
wonder95’s picture

StatusFileSize
new1.17 KB

Re-roll of patch with correct spelling of $transitions variable.

snoopy77’s picture

Good deal. Had the same problem, now the Publish action does show up. Many thanks.

icetristar’s picture

I got an error while applying the patch on Workflow 7.x-1.0.

patching file b/workflow_actions/workflow_actions.module
Hunk #1 FAILED at 341.
1 out of 1 hunk FAILED -- saving rejects to file b/workflow_actions/workflow_actions.module.rej

wonder95’s picture

As indicated in the issue header, the patch was against 7.x-1.x-dev, so you probably need to download the latest dev and apply it against that. Either that, or since it's just a new function and doesn't change any existing code, you could just add it to the end of workflow_actions.module.

icetristar’s picture

Copy-pasting works fine, however I couldn't get the patch applied even on the dev version. Thanks for the quick response.

wonder95’s picture

Hmmm, not sure why, since the line numbers in the patch match what's in current dev. Did you apply it from /sites/all/modules/workflow directory (or wherever your module directory is)?

wonder95’s picture

Re-rolled patch (also renamed to include the nid for this issue) is attached that also adds the node_unpublish action, since it makes sense to be able to unpublish content if you're going to be able to publish it.

What do people think about just adding all node operations from node_action_info()? It would be very easy to just loop through them in this function and add all of them instead of having to add a new line for each action that you want to enable. If it's okay with @bastlynn, I can go ahead and add that.

acrollet’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #12 works for me.

pianomansam’s picture

+1
Patch in #12 also works for me.

wonder95’s picture

Well, still no response from @Bastlynn on my proposal in #12, so I went ahead and re-rolled the patch to include all actions from node_action_info().

Bastlynn’s picture

Thanks - many apologies for the delay in responding here. There's a project at work that's in crunch mode so I've not had as many hours to spare in the last few weeks. It looks to be easing up in the next day or so, so as soon as I can I'll hit this up and get it in.

wonder95’s picture

Re-roll of patch from #15 to get rid of duplicate 'actions' text in doc block.

cyberwolf’s picture

Status: Reviewed & tested by the community » Needs work

There still seems to be an issue when using the action "Publish content" in a workflow transition from (creation) to another state. I always get a PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '10846' for key 'PRIMARY': INSERT INTO {node} ... where the primary key - here 10846 - differs each time.

wonder95’s picture

You shouldn't need to specify 'Publish content" for the first state; whatever is the default publishing option for the node is what will be used, since when the node is saved, it is automatically moved into the first state after (creation).

At least that's the way it's always worked for me...

cyberwolf’s picture

The "Publish content" action is always automatically added, unfortunately. I need to investigate if I can remove it again. Anyhow, I think it's too easy for Drupal Workflow newbies to make mistakes against it this way.

wonder95’s picture

Hmmm, not sure if I understand the objection, but how about making it a configurable option on a per-node-action basis? Maybe even a per-transition and per-node action basis? Wouldn't bee too tough.

Bastlynn’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB

@wonder95 In D7 if you select an action to publish, it also automatically adds an action to save. That's not workflow's behavior - that's nodes actions doing it.

Thankfully you can remove the save after the fact, but in the interest of avoiding newbie errors (unless you want to handle the issue queue on the matter ;) ) it should be accounted for.

I've added a flag that passes information to the alter function about the transition, namely if it's a creation type or not. That should help determine available actions on the other side. For the moment the patch just doesn't add any node responses to a creation -> anything state, since the node doesn't yet exist in that situation. Temporary solution, but it works to get the triggers available elsewhere until another patch can be rolled for handling creation situations. See patch. I'll leave this up for some additional review before committing anything.

jramby’s picture

Hi all,

Another question on it... Is there any reason that in each trigger select box, there is not all existing actions ? (In other word, some actions are not listed there, why ?)

wonder95’s picture

@jrmaby, see my comment in #4 - each action needs to be defined for the appropriate hooks, hence my patches to do just that for the node actions. In order to add all actions, they would have to be defined for the workflow transition triggers. They don't just show up automagically. :-)

@bastlynn - I recognize that the save action is added automatically, but why is that an issue? Call me desnse, but somehow I'm not understanding the concern about newbie errors. Can you please elaborate?

cyberwolf’s picture

@wonder95 see #18. The "Publish content" action caused a PDOException when triggering it on a state transition from (creation) to another state.

wonder95’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, Bastlynn and I discussed this in person at Drupalcon last week. We both agree that her patch should be committed. We can add more triggers in a separate patch if needed.

ufku’s picture

Wouldn't it be better to iterate over each action and check if its type is "node" and then set the trigger accordingly.

/**
 * Implementation of hook_drupal_alter().
 */
function workflow_actions_action_info_alter(&$info) {
  $transitions = workflow_actions_trigger_info();
  foreach ($transitions['workflow'] as $transition => $data) {
    // Loop through all available node actions and add them as triggers.
    // But not if this has been flagged as a creation state.
    if ($data['workflow_creation_state'] != TRUE) {
      // Enable the trigger for all node actions
      foreach ($info as $action => $data) {
        if ($data['type'] == 'node') {
          $info[$action]['triggers'][] = $transition;
        }
      }
    }
    // Either way, unset the creation flag so we don't confuse anyone later.
    unset($transitions['workflow'][$transition]['workflow_creation_state']);
  }
}
DRippstein’s picture

Thanks for the patch, look forward to seeing this committed. However, I noticed a Warning after applying this patch when I didn't have any existing workflows. PHP didn't like having a foreach() on an empty variable.

Warning: Invalid argument supplied for foreach() in workflow_actions_action_info_alter() (line 353 of /sites/all/modules/workflow/workflow_actions/workflow_actions.module).

Changing line 353 solves it.
From:

foreach ($transitions['workflow'] as $transition => $data) {

To:

foreach ((array)$transitions['workflow'] as $transition => $data) {

Now everything works great for me. LOVE this module!!

guillaumeduveau’s picture

Workflow is almost useless without that patch :-S

Jorenm’s picture

This patch doesn't seem to work for me. I still get the same problem as stated by OP.

*edit*

I lied, it works.

chrisschaub’s picture

Could this get committed. Works for me.

borniol’s picture

Still get the same problem even if i applied the latest patch #22 below.
Here is my code :

  return $aids;
}

/**
 * Implementation of hook_drupal_alter().
 */
function workflow_actions_action_info_alter(&$info) {
  $transitions = workflow_actions_trigger_info();
foreach ((array)$transitions['workflow'] as $transition => $data) {
    // Loop through all available node actions and add them as triggers.
    // But not if this has been flagged as a creation state.
    if ($data['workflow_creation_state'] != TRUE) {
      foreach (node_action_info() as $action => $data) {
        if ($data['type'] == 'node') {
          $info[$action]['triggers'][] = $transition;
        }
      }   
    }   
    // Either way, unset the creation flag so we don't confuse anyone later.
    unset($transitions['workflow'][$transition]['workflow_creation_state']);
  }
}

I created a "moderation" workflow and assign it to my personnal content type called "courses". When i try to configure action for my moderation workflow, i still didn t see any "publishing node" actions in the liste of the associated actions. Tried patch #12 and so no... without success to get it working.

If someone could help me.
Thanks in advance

borniol’s picture

Actually, to complete my previous comment, nodes actions shows well for transitions between my workflow states except for the creation-> state transitions, that is in fact what i needed.

pianomansam’s picture

Status: Reviewed & tested by the community » Needs work

I'm putting this back to needing work as several issues are still being reported, and am wondering about how we are coming along getting this resolved.

najim’s picture

Status: Needs work » Reviewed & tested by the community

@wonder95 you path #17 worked for me and saved me hours of stress

pianomansam’s picture

Status: Reviewed & tested by the community » Needs work

Najim, there are still issues being reported. Until the users who have reported those issues have a solution that solves them, I don't think we should mark this as RTBC.

m.david’s picture

Any word on when this issue might be fixed and committed? My attempts to use the patches were unsuccessful and I sure would like to use Workflow again. It worked so well in Drupal 6 and this issue is preventing use of the module in Drupal 7. Thanks!

nancydru’s picture

Component: Workflow Access: Code » Wokflow Actions
Status: Needs work » Fixed

I have committed Sarah's patch (#22) with DRippstein's modification. I don't use Actions, so I can't test it. If there are still problems, please open a new issue.

nancydru’s picture

Status: Fixed » Closed (fixed)

Included in 7.x-1.1-rc1

ttkaminski’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Component: Wokflow Actions » Code
Issue summary: View changes
Status: Closed (fixed) » Needs review
StatusFileSize
new1.42 KB

I've debugged the issue that was causing the PDOException when trying to run the Publish Post + Save Post for a workflow transition from (creation) to another state as described in #1380954-18: Triggers Missing. Turns out that a second node_save() is called within the hook_node_insert during a node_save() operation.

Here is a snippet from the node_save() function:

module_invoke_all('node_' . $op, $node);
module_invoke_all('entity_' . $op, $node, 'node');

// Update the node access table for this node.
node_access_acquire_grants($node);

// Clear internal properties.
unset($node->is_new);
unset($node->original);

Drupal will attempt to insert a new node if you call node_save() within hook_node_insert because $node->is_new is still set to TRUE and only unset *after* the hooks are invoked. I think this is a bug in the core. However, I've implemented a workaround withing the workflow module:

--- a/workflow.module
+++ b/workflow.module
@@ -248,8 +248,10 @@ function workflow_node_insert($node) {
     if (!isset($sid)) {
       $sid = $node->workflow;
     }
+    unset($node->is_new); // Allows node_save actions to perform an update instead of another insert
     // And make the transition.
     workflow_transition($node, $sid);
+    $node->is_new = TRUE; // Restore it in case another module requires it
   }
 }
 

The attached patch also re-enables all node action triggers for the creation state.

johnv’s picture

Version: 7.x-1.2 » 7.x-1.1-beta4
Status: Needs review » Closed (fixed)

@ttkaminski, as stated in #38, it is good practice to not open long-closed issues, but open a new one, referring the old one. This avoids long threads.
Also, IMO you're duplicating #1568864: Keep $node->is_new flag after firing "Workflow state has changed" event . If this is not the case, please open a new issue. Thanks.

johnv’s picture

O, and please test if the problem still exists in 7.x-2.x version. Any repairs will be done in that version.

Bastlynn’s picture

Threadomancy! Been a long time since this one still applied. Nancy and John have been doing a tremendous amount of work in the system since the last time the patches were put in on this, so a new thread is almost certainly warranted the code has changed so much since last I looked at it.

7.x-2.x really is a nice update, so if you've not moved to it yet I would strongly recommend doing so.

johnv’s picture

Component: Code » Actions and Triggers
Related issues: +#1568864: Keep $node->is_new flag after firing "Workflow state has changed" event

Some bookkeeping, since this seems still alive!
:-)