Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrchardCore.Workflows Publish Content task does not publish content #16939

Open
AmyBlaine opened this issue Oct 30, 2024 · 10 comments
Open

OrchardCore.Workflows Publish Content task does not publish content #16939

AmyBlaine opened this issue Oct 30, 2024 · 10 comments
Labels
Milestone

Comments

@AmyBlaine
Copy link

AmyBlaine commented Oct 30, 2024

Describe the bug

The workflow module 'publish content' task fails to publish content when triggered by an event.

Orchard Core version

2.0.2 - Simple web application with 2.0.2 nuget packages
1.8.3 - Simple web application with 1.8.3 nuget packages
701c07e - OrchardCore.Cms.Web

To Reproduce

  1. Setup site using Blog recipe
  2. Navigate to the Admin Dashboard Features menu. Enable Workflows (OrchardCore.Workflows)
  3. Import workflows with attached Recipe.json or manually create workflows
  4. Recipe.json
  5. Create a Simplified workflow or import workflow recipe
    • Add Event - Content Draft Saved
      • Select Content Types - Page
      • Save
      • Set as startup event.
    • Add Task - Publish Content
      • Leave settings blank
    • Connect the 'Done' outcome of the Content Draft Saved event to the Publish Content task.
    • Add Task - Notify
      • Notification Type - Warning
      • Message - Content was not published :(
    • Connect the 'Noop' outcome of the Publish Content task to the Warning Notification
    • Add Task - Notify
      • Notification Type - Success
      • Message - Content published :)
    • Connect the 'Published' outcome of the Publisch Content task to the Success Notification
    • Save the workflow
  6. Navigate to Content Items
  7. Create a new Page
    • Enter a title
    • Save Draft
  8. Observations
    • Notification - Content was not published :(
    • Notification - Your Page draft has been saved
    • The content item has the draft status
  9. Navigate to Workflows
  10. View the instances for the workflow created above
    • A new instance should have been created 'a moment ago'
    • This instance should have a status of 'Finished'
  11. Restarting the instance of the workflow results in successfully publishing the content item.
  12. Observations
    • Notification - Content published :)
    • Notification - Workflow has been restarted
    • A new Workflow Instance has was 'Created a moment ago' and has the Finished label
  13. Navigate to Content Items
  14. The Content Item (Page) created above is now Published

Example #2

  1. Create an Publish Approval Process workflow or import workflow recipe
    • Add Event - Content Draft Saved
      • Select Content Types - Page
      • Save
      • Set as startup event.
    • Add Event - User Task
      • Enter Title - Review content
      • Enter Actions - Approve, Reject
      • Select Roles - Administrator, Editor
      • Save
    • Connect the 'Done' outcome of the Content Draft Saved event to the Review Content event.
    • Add Task - Notify
      • Notification Type - Warning
      • Message - Content was rejected :(
    • Connect the 'Reject' outcome of the Review Content event to the Warning Notification
    • Add Task - Notify
      • Notification Type - Success
      • Message - Content published :)
    • Connect the 'Approve' outcome of the Review Content event to the Success Notification
    • Add Task - Publish Content
      • Leave settings blank
    • Connect the 'Done' outcome of the Success Notification to the Publish Content task
    • Add Task - Notify
      • Notification Type - Warning
      • Message - Content was not published :(
    • Connect the 'Noop' outcome of the Publish Content task to the Warning Notification
    • Add Task - Notify
      • Notification Type - Success
      • Message - Content published :)
    • Connect the 'Published' outcome of the Publisch Content task to the Success Notification
    • Save the workflow
  2. Navigate to Content Items
  3. Create a new Page
    • Enter a title
    • Save Draft and Continue
  4. When page reloads, Approve and Save
  5. Observations
    • Notification - Content approved :)
    • Notification - Content was not published :(
    • Notification - Your Page draft has been saved
    • The content item has the draft status
  6. Navigate to Workflows
  7. View the instances for the Publish Approval workflow created above
    • Two instances of the workflow exist
      • created 'a moment ago' (from Approve and Save) - This instance is halted
      • created 1 minute ago (from initial Save Draft and Continue) - This instance is finished
  8. Restart the workflow instance
  9. Observations
    • Notification - Workflow has been restarted
    • A new Workflow Instance has was 'Created a moment ago' and has the Halted label
  10. Navigate to Content Items
  11. The Content Item (Page) created above is still not Published

Expected behavior

The content item is published by the workflow when the Publish Content task is triggered.

The workflow does not need to be restarted for the publish content task to run successfully.

Observations

The content item is published when InlineEvent.ContentItemId is null which occurs when the workflow is restarted.

if (String.Equals(InlineEvent.ContentItemId, content.ContentItem.ContentItemId, StringComparison.OrdinalIgnoreCase))

Logs and screenshots

Simplified Workflow
image

Example #2 Workflow
image

Logs
orchard-log-2024-10-30.log

Why is this important?

My goal is to configure a publishing approval process using workflows. Ultimately, a user with the author role will create a draft content item, then a user with an editor role will approve the content item prior to it being published.

The following workflow fails to publish a content item. While troubleshooting, I reproduced the same problem without inserting the User Task event as this propagates the number of workflow instances with each 'Approve and Save' action.

Copy link
Contributor

Thank you for submitting your first issue, awesome! 🚀 We're thrilled to receive your input. If you haven't completed the template yet, please take a moment to do so. This ensures that we fully understand your feature request or bug report. On what happens next, see the docs.

@sebastienros sebastienros added this to the 2.x milestone Oct 31, 2024
Copy link
Contributor

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

@sebastienros
Copy link
Member

Can you try this change?

if (!content.HasDraft())
{
    return Outcomes("Noop");
}

instead of

if (string.Equals(InlineEvent.ContentItemId, content.ContentItem.ContentItemId, StringComparison.OrdinalIgnoreCase))
{
    return Outcomes("Noop");
}

Then test with an UpdateContentTask before. Also from a user triggered event. And from a schedule? (triggering from a Content Handler or not could be why we had this InlineEvent code).

@hishamco
Copy link
Member

hishamco commented Nov 3, 2024

Screenshot 2024-11-04 004616

@hishamco
Copy link
Member

hishamco commented Nov 3, 2024

@AmyBlaine please test the related PR, I did a quick test, seems everything works as expected

@sebastienros
Copy link
Member

We tested this change during triage. The ask here was to test more thoroughly with events triggers inline or not. And bonus with functional tests that would catch any regression in these tasks.

@hishamco
Copy link
Member

hishamco commented Nov 4, 2024

Ah, I didn't know that you are testing that during triage, @AmyBlaine please do some test through UI, I will try to add a functional test

@AmyBlaine
Copy link
Author

Here are the workflows I used to test. Recipe.json

Publish Approval Process on Content Draft Saved event
image

Test Publish Content with UpdateContentTask start event
image

For the 'Publish content on a schedule' workflow, another change may be needed.

For this test, I created a new content item, then set the contentItemId explicitly in the Publish Content task. The content item was not found here:

else if (options.IsDraft || options.IsDraftRequired)

I tried this change assuming that when a content item is created, it is the latest version of the content item by default.
image

With this additional change, the 'Publish content on a schedule' workflow succeeds.

@AmyBlaine
Copy link
Author

I tried to create a branch / pull request, but I need to be given write access. What's the process to get write access?

image

@sebastienros
Copy link
Member

@AmyBlaine you need to fork the repository and do the changes on your fork.

@hishamco hishamco removed their assignment Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants