Tasks allow integrating custom operations into the lifecycle of form processing within the Wonderful Relations system. By attaching Tasks
to events such as INSERT
, UPDATE
, or DELETE
, developers can execute additional functionality either BEFORE
or AFTER
the main operation.
These tasks provide flexibility to connect external systems, perform data transformations, or trigger related operations seamlessly during the form processing workflow.
Visual Example
Parameters
Title
A descriptive title for the task, which is useful for documentation and debugging purposes.
Type
Specifies whether the task execution is:
- synchronous (syncron): The task runs in the same process as the main operation.
- asynchronous (asyncron): The task runs in a separate process/thread.
Event Type
Specifies when the task should be triggered relative to the main operation:
- BEFORE: Executes before the main operation.
- AFTER: Executes after the main operation.
Event
Specifies the operation type the task is associated with:
- INSERT: Triggered during the creation of a new form entry.
- UPDATE: Triggered when an existing form entry is updated.
- DELETE: Triggered when a form entry is removed.
Action
Defines the actual functionality to be executed.
Sort Order
Determines the sequence in which tasks are executed if multiple tasks are attached to the same event.
Example Use Cases
Synchronizing External Systems
Tasks can be used to synchronize external systems, such as ElasticSearch or CardDAV, when specific form actions are performed.
namespace TS\YourPlugin\Modules\CardDAV\Tasks;
use TS\WonderfulRelations\Modules\Form\Functions\Entry;
use TS\WonderfulRelations\Modules\Task\Task;
class DeleteEntry extends Task {
public function execute(Entry $entry): Entry {
// Logic to delete a CardDAV entry
// Example: $syncer->delete_card();
return $entry;
}
}
new DeleteOrganisation("carddav_delete_entry");
Updating ElasticSearch
Tasks can insert or update records in ElasticSearch when data changes. Example: Updating ElasticSearch on INSERT/UPDATE
namespace TS\YourPlugin\Modules\Search\Tasks;
use TS\WonderfulRelations\Modules\Form\Functions\Entry;
use TS\WonderfulRelations\Modules\Task\Task;
class ESUpdateTask extends Task {
public function execute(Entry $entry): Entry {
// Logic to update ElasticSearch
return $entry;
}
}
new ESUpdateTask("es_insert_update_data");
Generating Dynamic Data
Tasks can calculate and populate fields dynamically based on input or external data sources. Example: Generating Invoice Numbers
namespace TS\YourPlugin\Modules\Invoice\Tasks;
use TS\WonderfulRelations\Modules\Form\Functions\Entry;
use TS\WonderfulRelations\Modules\Task\Task;
class GenerateInvoiceNumber extends Task {
public function execute(Entry $entry): Entry {
// Logic to generate an invoice number
return $entry;
}
}
new GenerateInvoiceNumber("YourPlugin_generate_invoice_number");
Benefits of Using Tasks
Custom Logic
Add highly tailored logic to form operations without modifying the core system.
Integration
Seamlessly integrate with external systems like APIs, databases, or third-party services.
Data Consistency
Ensure data integrity by validating or transforming data during form operations.
Flexibility
Execute operations at different stages (before or after) of the main process.
Efficient Handling of Long-Running Tasks
Tasks can handle processes that require significant time to complete, such as image conversion, large data processing, or report generation. By running these tasks asynchronously (asyncron), they can offload the workload to the background, allowing the system’s frontend to remain highly responsive while the operations continue seamlessly in the background.
Improved User Experience
By processing tasks like notifications, external API calls, or batch operations asynchronously, the system ensures that users don’t experience delays or performance bottlenecks during interactions.