You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the database migrations to create the required tables:
30
-
31
-
```bash
32
-
php artisan igniter:up
33
-
```
34
-
35
-
## Automation workflow
36
-
37
-
The Automation extension follows a specific workflow when an automation is triggered:
38
-
39
-
1. The extension registers associated actions, conditions, and events using the registerAutomationRules method.
40
-
2. When a system event is triggered, the parameters of the event are captured, along with any global parameters.
41
-
3. These captured parameters are then attached to a job and placed onto the queue for background processing.
42
-
4. The job retrieves all automation rules that match the triggered system event and runs them.
43
-
5. The automation conditions are checked to ensure that any required conditions are met.
44
-
6. Finally, the automation actions associated with the triggered rules are executed using the captured parameters.
45
-
46
-
## Usage
47
-
48
-
You can manage automations in the admin panel by navigating to Tools > Automations.
49
-
50
-
### Defining events
51
-
52
-
An event class is responsible for preparing the parameters passed to the conditions and actions.
53
-
54
-
Automation Event classes are typically stored in the `src/AutomationRules/Events` directory of an extension. The Event class is a simple class that extends `Igniter\Automation\Classes\BaseEvent` and defines the `eventDetails` and `makeParamsFromEvent` methods.
class CustomerRegisteredEvent extends \Igniter\Automation\Classes\BaseEvent
62
-
{
63
-
public function eventDetails(): array
64
-
{
65
-
return [
66
-
'name' => 'Registered',
67
-
'description' => 'When a customer registers',
68
-
'group' => 'customer'
69
-
];
70
-
}
71
-
72
-
public static function makeParamsFromEvent(array $args, $eventName = null): array
73
-
{
74
-
return [
75
-
'user' => array_get($args, 0)
76
-
];
77
-
}
78
-
}
79
-
```
80
-
81
-
The `eventDetails` method returns information about the event, including the name and description. The `makeParamsFromEvent` method prepares the captured parameters passed to the conditions and actions.
82
-
83
-
These are the available options for the `eventDetails` method:
84
-
85
-
-`name` - The name of the event. This is displayed in the admin panel.
86
-
-`description` - A description of the event. This is displayed in the admin panel.
87
-
-`group` - The group to which the event belongs. This is used to group events in the admin panel.
88
-
89
-
### Defining actions
90
-
91
-
A action class defines the final step in an automation and performs the automation.
92
-
93
-
Action classes are typically stored in the `src/AutomationRules/Actions` directory of an extension. The Action class is a simple class that extends `Igniter\Automation\Classes\BaseAction` and defines the `actionDetails`, `defineFormFields`, and `triggerAction` methods.
The `actionDetails` method returns information about the action, including the name and description. The `defineFormFields` method defines the form fields required for the action, see [TastyIgniter's available form field types](https://tastyigniter.com/docs/advanced/forms#available-field-types). You can access fields defined in the `defineFormFields` method using `$this->model->field_name`. The `triggerAction` method performs the automation action.
135
-
136
-
These are the available options for the `actionDetails` method:
137
-
138
-
-`name` - The name of the action. This is displayed in the admin panel.
139
-
-`description` - A description of the action. This is displayed in the admin panel.
140
-
141
-
### Defining conditions
142
-
143
-
A condition class is used to check whether a condition is true or false.
144
-
145
-
Automation condition classes are typically stored in the extensions's `src/AutomationRules/Conditions` directory. The Condition class is a simple class that extends `Igniter\Automation\Classes\BaseCondition` and defines the `conditionDetails` and `isTrue` methods.
class MyCondition extends \Igniter\Automation\Classes\BaseCondition
151
-
{
152
-
public function conditionDetails(): array
153
-
{
154
-
return [
155
-
'name' => 'Condition',
156
-
'description' => 'My Condition is checked',
157
-
];
158
-
}
159
-
160
-
public function isTrue(&$params): bool
161
-
{
162
-
return true;
163
-
}
164
-
}
165
-
```
166
-
167
-
The `conditionDetails` method returns information about the condition, including the name and description. The `isTrue` method checks whether the condition is true for the specified parameters.
168
-
169
-
These are the available options for the `conditionDetails` method:
170
-
171
-
-`name` - The name of the condition. This is displayed in the admin panel.
172
-
-`description` - A description of the condition. This is displayed in the admin panel.
173
-
174
-
### Defining model attribute conditions
175
-
176
-
Just like the condition class above, a model attribute condition class applies conditions to sets of model attributes.
177
-
178
-
Automation model attribute condition classes are typically stored in the extensions's `src/AutomationRules/Conditions` directory. The model attribute condition class is a simple class that extends `Igniter\Automation\Classes\BaseCondition` and defines the `conditionDetails`, `defineModelAttributes`, and `isTrue` methods.
class CustomerAttribute extends \Igniter\Automation\Classes\BaseCondition
184
-
{
185
-
public function conditionDetails(): array
186
-
{
187
-
return [
188
-
'name' => 'Customer attribute',
189
-
];
190
-
}
191
-
192
-
public function defineModelAttributes(): array
193
-
{
194
-
return [
195
-
'first_name' => [
196
-
'label' => 'First Name',
197
-
],
198
-
'last_name' => [
199
-
'label' => 'Last Name',
200
-
],
201
-
];
202
-
}
203
-
204
-
public function isTrue(&$params): bool
205
-
{
206
-
return true;
207
-
}
208
-
}
209
-
```
210
-
211
-
The `defineModelAttributes` method defines the model attributes and labels required for the condition.
212
-
213
-
### Registering automation events, actions, and conditions
214
-
215
-
After creating the [event](#defining-events), [action](#defining-actions) and [condition](#defining-conditions) classes, you can make them available in the admin panel by registering them in the `registerAutomationRules` method of the extension class.
216
-
217
-
The `registerAutomationRules` method should return an array with the following keys:
218
-
219
-
-`events` - an array of event class that triggers an automation.
220
-
-`actions` - an array of action class that performs a task when an automation is triggered.
221
-
-`conditions` - an array of condition class that checks whether a condition is true or false before an action is performed.
222
-
-`presets` - predefined automation rules available in the admin panel.
0 commit comments