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

API Update API to reflect changes to CLI interaction #552

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions docs/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,45 @@ In order to apply workflow to other classes (e.g. `MyObject`), you need
to apply it to both the model class and the controller
which is used for editing it. Here's an example for `MyObject`
which is managed through a `MyObjectAdmin` controller,
extending from `ModelAdmin`. `mysite/_config/config.yml`:

:::yml
MyObject:
extensions:
- WorkflowApplicable
MyObjectAdmin:
extensions:
- AdvancedWorkflowExtension

We strongly recommend also setting the `NotifyUsersWorkflowAction` configuration parameter `whitelist_template_variables`
extending from `ModelAdmin`. `app/_config/config.yml`:

```yml
MyObject:
extensions:
- Symbiote\AdvancedWorkflow\Extensions\WorkflowApplicable
MyObjectAdmin:
extensions:
- Symbiote\AdvancedWorkflow\Extensions\AdvancedWorkflowExtension
```
We strongly recommend also setting the `NotifyUsersWorkflowAction` configuration parameter `whitelist_template_variables`
to true on new projects. This configuration will achieve this:

:::yml
NotifyUsersWorkflowAction:
whitelist_template_variables: true
```yml
Symbiote\AdvancedWorkflow\Actions\NotifyUsersWorkflowAction:
whitelist_template_variables: true
```

See the Security section below for more details.

### Embargo and Expiry
This add-on functionality allows you to embargo some content changes to only appear as published at some future date. To enable it,
add the `WorkflowEmbargoExpiryExtension`.

:::yml
SiteTree:
extensions:
- WorkflowEmbargoExpiryExtension
```yml
SilverStripe\CMS\Model\SiteTree:
extensions:
- Symbiote\AdvancedWorkflow\Extensions\WorkflowEmbargoExpiryExtension
```

Make sure the [QueuedJobs](https://github.com/nyeholt/silverstripe-queuedjobs)
Make sure the [QueuedJobs](https://github.com/nyeholt/silverstripe-queuedjobs)
module is installed and configured correctly.
You should have a cronjob similar to the following in place, running
You should have a cronjob similar to the following in place, running
as the webserver user.

*/1 * * * * cd && sudo -u www php /var/www/framework/cli-script.php dev/tasks/ProcessJobQueueTask
```sh
*/1 * * * * cd && sudo -u www php /var/www/vendor/bin/sake tasks:ProcessJobQueueTask
```

It also allows for an optional subsequent expiry date. Note: Changes to these dates also constitute modifications to the content and as such
are subject to the same workflow approval processes, where a particular workflow instance is in effect. The embargo export functionality can also be used independently of any workflow.
Expand All @@ -52,9 +57,11 @@ than a couple of days (configurable in each "Workflow Definition" through the CM

Periodically run the Workflow Reminder Task by adding a task like this one to the crontab:

# Check every minute if someone needs to be reminded about pending workflows
*/1 * * * * cd /var/www && sudo -u www ./sapphire/sake dev/tasks/WorkflowReminderTask
```sh
# Check every minute if someone needs to be reminded about pending workflows
*/1 * * * * cd /var/www && sudo -u www vendor/bin/sake tasks:WorkflowReminderTask
```

This is an example only. The key is to run the task as the same user as the web server.

You can run the task manually for testing by visiting the `/dev/tasks/WorkflowReminderTask` URL of your site.
You can run the task manually for testing by visiting the `/dev/tasks/WorkflowReminderTask` URL of your site.
16 changes: 10 additions & 6 deletions src/Tasks/WorkflowReminderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use SilverStripe\Dev\BuildTask;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Email\Email;
use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\ORM\FieldType\DBDatetime;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

/**
* A task that sends a reminder email to users assigned to a workflow that has
Expand All @@ -17,12 +19,13 @@
*/
class WorkflowReminderTask extends BuildTask
{
protected $title = 'Workflow Reminder Task';
protected $description = 'Sends out workflow reminder emails to stale workflow instances';
protected string $title = 'Workflow Reminder Task';

private static $segment = 'WorkflowReminderTask';
protected static string $description = 'Sends out workflow reminder emails to stale workflow instances';

public function run($request)
protected static string $commandName = 'WorkflowReminderTask';

protected function execute(InputInterface $input, PolyOutput $output): int
{
$sent = 0;
if (WorkflowInstance::get()->count()) { // Don't attempt the filter if no instances -- prevents a crash
Expand Down Expand Up @@ -69,6 +72,7 @@ public function run($request)
}
}
}
echo "Sent $sent workflow reminder emails.\n";
$output->writeln("Sent $sent workflow reminder emails.");
return Command::SUCCESS;
}
}
Loading