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/StepClass.php +19 -15 10.2.2 → 11.1.0 View file →
@@ -13,41 +13,45 @@
13 13 $this->table = 'step';
14 14 $this->pkey = 'id';
15 15 }
16 16
17 - public function save($step)
17 + public function save(object $step): ?int
18 18 {
19 19 foreach ($step as $oneAttribute => $value) {
20 20 if (empty($value)) continue;
21 - if (is_array($value)) $value = json_encode($value);
22 21
23 - $step->$oneAttribute = strip_tags($value);
22 + $step->$oneAttribute = is_array($value) ? json_encode($value) : acym_stripTags($value);
24 23 }
25 24
26 - if (empty($step->name)) $step->name = 'step_'.time();
25 + //Some of the database need a name for the column name, they add an index and the name need to be unique
26 + if (empty($step->name)) {
27 + $step->name = 'step_'.time();
28 + }
27 29
28 30 return parent::save($step);
29 31 }
30 32
31 - public function getOneStepByAutomationId($automationId)
33 + public function getOneStepByAutomationId(int $automationId): ?object
32 34 {
33 - return acym_loadObject('SELECT * FROM #__acym_step WHERE automation_id = '.intval($automationId));
35 + $step = acym_loadObject('SELECT * FROM #__acym_step WHERE automation_id = '.intval($automationId));
36 +
37 + return empty($step) ? null : $step;
34 38 }
35 39
36 - public function getStepsByAutomationId($automationId)
40 + public function getStepsByAutomationId(int $automationId): array
37 41 {
38 42 return acym_loadObjectList('SELECT * FROM #__acym_step WHERE automation_id = '.intval($automationId));
39 43 }
40 44
41 - public function getActiveStepByTrigger($triggers)
45 + public function getActiveStepByTrigger(array $triggers): array
42 46 {
43 - if (empty($triggers)) return [];
47 + if (empty($triggers)) {
48 + return [];
49 + }
44 50
45 - if (!is_array($triggers)) $triggers = [$triggers];
46 -
47 51 $query = 'SELECT step.*
48 52 FROM #__acym_step AS step
49 - LEFT JOIN #__acym_automation AS automation ON step.automation_id = automation.id
53 + JOIN #__acym_automation AS automation ON step.automation_id = automation.id
50 54 WHERE automation.active = 1';
51 55
52 56 foreach ($triggers as $i => $oneTrigger) {
53 57 $triggers[$i] = 'step.triggers LIKE '.acym_escapeDB('%"'.$oneTrigger.'"%');
@@ -52,8 +56,9 @@
52 56 foreach ($triggers as $i => $oneTrigger) {
53 57 $triggers[$i] = 'step.triggers LIKE '.acym_escapeDB('%"'.$oneTrigger.'"%');
54 58 }
55 59 $query .= ' AND ('.implode(' OR ', $triggers).')';
60 + $query .= ' ORDER BY automation.ordering ASC';
56 61
57 62 $steps = acym_loadObjectList($query);
58 63
59 64 foreach ($steps as $i => $oneStep) {
@@ -62,18 +67,17 @@
62 67
63 68 return $steps;
64 69 }
65 70
66 - public function delete($elements)
71 + public function delete(array $elements): int
67 72 {
68 73 if (empty($elements)) return 0;
69 74
70 - if (!is_array($elements)) $elements = [$elements];
71 75 acym_arrayToInteger($elements);
72 76
73 77 $conditions = acym_loadResultArray('SELECT id FROM #__acym_condition WHERE step_id IN ('.implode(',', $elements).')');
74 78 $conditionClass = new ConditionClass();
75 - $conditionsDeleted = $conditionClass->delete($conditions);
79 + $conditionClass->delete($conditions);
76 80
77 81 return parent::delete($elements);
78 82 }
79 83 }