publishpress / PublishPress-Future

This plugin was known as "Post Expirator", and now it is called "PublishPress Future".
https://wordpress.org/plugins/post-expirator/
7 stars 11 forks source link

Improve support for multiple handles in the same step, with different outputs #828

Open andergmartins opened 4 months ago

andergmartins commented 4 months ago

See a use case for the schedule:

Add distinct handles on "Schedule" step to allow having different flow for scheduling and continuing

Feature: Stick a post after one week and warn admin on each step

  Scenario: Specifying different flows for the same node
    Given The workflow is published
    When a post is saved and the filters match the workflow configuration
    Then the engine will schedule an action to stick the post on week after published and send an email to the site admin
    And after scheduling it will send an email saying the action was scheduled
    And if there is any issue while scheduling, send a message to Ray Debug

Here is an example of the handle schema for the node:

public function getHandleSchema(): array
{
    return [
        "target" => [
            [
                "id" => "input",
                "left" => "50%",
            ]
        ],
        "source" => [
            [
                "id" => "output",
                "left" => "15%",
                "label" => __("To schedule", "publishpress-future-pro"),
            ],
            [
                "id" => "success",
                "left" => "50%",
                "label" => __("On Success", "publishpress-future-pro"),
            ],
            [
                "id" => "fail",
                "left" => "85%",
                "label" => __("On fail", "publishpress-future-pro"),
            ]
        ]
    ];
}

And here an example of the implemented workflow:

image

The output schema needs to be modified to specify different output for specific handles. If no handle is specified, the output is available for any handle:

public function getOutputSchema(): array
{
    return [
        [
            "name" => "input",
            "type" => "input",
            "label" => __("Step input", "publishpress-future-pro"),
            "description" => __("The input data for this step.", "publishpress-future-pro"),
        ],
        [
            "name" => "schedule_id",
            "type" => "string",
            "label" => __("Scheduled task ID", "publishpress-future-pro"),
            "description" => __("The ID of the scheduled task.", "publishpress-future-pro"),
            "handle" => "success",
        ],
        [
            "name" => "error",
            "type" => "string",
            "label" => __("Error", "publishpress-future-pro"),
            "description" => __("The error message if the step fails.", "publishpress-future-pro"),
            "handle" => "fail",
        ],
    ];
}
andergmartins commented 4 months ago

This can be extended to the other steps, like "Send email" we can have different handles. One for success, and another for failure.

andergmartins commented 4 months ago

@stevejburge do you think these multiple flows for the same step make sense?

stevejburge commented 4 months ago

@andergmartins Yes, for Advanced users and when debugging issues

andergmartins commented 4 months ago

Nice, thanks. We can keep it simple when Advanced Settings are not enabled.

andergmartins commented 2 weeks ago

This is probably colliding with #848