PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Classes/AutomationClass.php +22 -5 10.11.1 → 11.1.0 View file →
@@ -76,9 +76,9 @@
76 76 if (empty($value)) {
77 77 continue;
78 78 }
79 79
80 - $element->$oneAttribute = is_array($value) ? json_encode($value) : strip_tags($value);
80 + $element->$oneAttribute = is_array($value) ? json_encode($value) : acym_stripTags($value);
81 81 }
82 82
83 83 return parent::save($element);
84 84 }
@@ -95,8 +95,12 @@
95 95
96 96 return parent::delete($elements);
97 97 }
98 98
99 + /**
100 + * @param mixed $trigger The identifier of the trigger
101 + * @param array $data An array with data for user-type triggers (user id, order, event...)
102 + */
99 103 public function trigger($triggers, array $data = []): void
100 104 {
101 105 if (!acym_level(ACYM_ENTERPRISE) || empty($triggers)) {
102 106 return;
@@ -116,12 +120,15 @@
116 120 foreach ($steps as $step) {
117 121 $newData = $data;
118 122 $execute = false;
119 123
124 + // If we reached the next execution time we execute
125 + // next_execution is only set if one of the time triggers like "asap" or "day" is selected in the automation
120 126 if (!empty($step->next_execution) && $step->next_execution <= $newData['time']) {
121 127 $execute = true;
122 128 }
123 129
130 + // Call the triggers to set the next execution time
124 131 acym_trigger('onAcymExecuteTrigger', [&$step, &$execute, &$newData]);
125 132
126 133 $newData['automation'] = $this->getOneById($step->automation_id);
127 134
@@ -129,9 +136,11 @@
129 136 $step->last_execution = $newData['time'];
130 137 $conditions = $conditionClass->getConditionsByStepId($step->id);
131 138 if (!empty($conditions)) {
132 139 foreach ($conditions as $condition) {
133 - if (!$this->verifyCondition($condition->conditions, $newData)) continue;
140 + if (!$this->verifyCondition($condition->conditions, $newData)) {
141 + continue;
142 + }
134 143
135 144 $actions = $actionClass->getActionsByStepId($step->id);
136 145 if (empty($actions)) continue;
137 146
@@ -186,8 +195,9 @@
186 195 if (empty($action->filters)) {
187 196 $query->where = $initialWhere;
188 197 }
189 198
199 + //We do the or first
190 200 foreach ($action->filters as $or => $orValue) {
191 201 if (empty($orValue)) {
192 202 continue;
193 203 }
@@ -192,10 +202,12 @@
192 202 continue;
193 203 }
194 204 $num = 0;
195 205 $query->where = $initialWhere;
206 + //Next the and
196 207 foreach ($orValue as $and => $andValue) {
197 208 $num++;
209 + //Finally we have all names filter
198 210 foreach ($andValue as $filterName => $filterOptions) {
199 211 acym_trigger('onAcymProcessFilter_'.$filterName, [&$query, &$filterOptions, &$num]);
200 212 }
201 213 }
@@ -231,15 +243,17 @@
231 243
232 244 return $this->didAnAction;
233 245 }
234 246
235 - private function verifyCondition($conditions, array $data = []): bool
247 + private function verifyCondition(array $conditions, array $data = []): bool
236 248 {
237 - if (empty($conditions)) return true;
249 + if (empty($conditions)) {
250 + return true;
251 + }
252 +
238 253 $userTriggeringAction = empty($data['userId']) ? 0 : $data['userId'];
239 254 $usersTriggeringAction = empty($data['userIds']) ? [] : $data['userIds'];
240 255
241 - $conditions = json_decode($conditions, true);
242 256 $query = new AutomationHelper();
243 257 $initialWhere = ['1 = 1'];
244 258 if (!empty($conditions['type_condition']) && $conditions['type_condition'] == 'user') {
245 259 if (empty($usersTriggeringAction)) {
@@ -257,13 +271,16 @@
257 271
258 272 foreach ($conditions as $or => $orValue) {
259 273 if (empty($orValue)) continue;
260 274
275 + // we increment id condition not validate
261 276 $conditionNotValid = 0;
262 277 $num = 0;
278 + //Next the and
263 279 foreach ($orValue as $and => $andValue) {
264 280 $num++;
265 281 $query->where = $initialWhere;
282 + //Finally we have all names condition
266 283 foreach ($andValue as $filterName => $filterOptions) {
267 284 acym_trigger('onAcymProcessCondition_'.$filterName, [&$query, &$filterOptions, &$num, &$conditionNotValid]);
268 285 }
269 286 }