New in Sulu 1.5: Automation

Beside the versioning feature we have implemented a second big feature for the new release: Automation!

The basic idea behind this was to enhance the content management with the abililty to plan the publishing time of a page. In the near future other tasks will also be added. One of many scenarios we are discussing are time based notifications so e.g. an editor would be notfied every 6 months to check the content of a page.

Automation Tab Automation Tab

Installation

We have decided to implement the automation feature outside the core installation as an optional dependency for your project.

To enable the feature you have to install the SuluAutomationBundle via composer. The following command will install the bundle and the library which we use to schedule the tasks (php-task):

composer require sulu/automation-bundle

Enabling the required bundles:

<?php
// app/AdminKernel.php

class AdminKernel extends SuluKernel
{
    public function registerBundles()
    {
        $bundles = parent::registerBundles();
        $bundles[] = new Task\TaskBundle\TaskBundle();
        $bundles[] = new Sulu\Bundle\AutomationBundle\SuluAutomationBundle();

        ...

        return $bundles;
    }
}

Add the routes for the automation-bundle:

# app/config/admin/routing.yml

sulu_automation_api:
    type: rest
    resource: "@SuluAutomationBundle/Resources/config/routing_api.xml"
    prefix: /admin/api

sulu_automation:
    type: rest
    resource: "@SuluAutomationBundle/Resources/config/routing.xml"
    prefix: /admin/automation

The bundle will add additional tables to your database which contain the tasks and some other information. Last but not least export also the translations for your Sulu-Admin:

bin/console doctrine:schema:update
bin/console sulu:translate:export

PHP-Task

This library is able to schedule tasks on a specific time in the future. The tasks which are overdue will be executed when the following command will be called (for more detailed information consider the documentation of php-task):

bin/console task:run

Cron-Job

The best-practice is to create a cron-job on your server which is running the above mentioned commands periodically (e.g. every 5 minutes). This intervall will define the accuracy of the schedule time. 

$ crontab -e
*/5 * * * * /path/to/project/bin/console task:run -e prod

Usage

Track the state of a task Track the state of a task

Currently two tasks can be scheduled for pages:

  • Publish
  • Unpublish

For both a timestamp can be defined when the selected action will be called. After scheduling a task you can track the state of it in the second list.

This new feature is a basic implementation at the moment. It is customizable and will be extended soon in the core with additional possibilities.

We think automation is very usefull and want to encourage you to use it. Please let us know what you think about it as the community feedback is very important to us! Also, stay tuned for more automaged tasks in the future.