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/ScenarioStepClass.php +37 -36 10.2.2 → 11.1.0 View file →
@@ -13,33 +13,25 @@
13 13 $this->table = 'scenario_step';
14 14 $this->pkey = 'id';
15 15 }
16 16
17 - public function save($element)
17 + public function save(object $element): ?int
18 18 {
19 19 if (!empty($element->params) && !is_string($element->params)) {
20 20 $element->params = json_encode($element->params);
21 21 }
22 22
23 - $test = $this->getOneById($element->id);
24 - $this->forceInsert = empty($test);
23 + // The id is a string
24 + $scenarioStep = acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE `id` = '.acym_escapeDB($element->id));
25 +
26 + $previousForce = $this->forceInsert;
27 + $this->forceInsert = empty($scenarioStep);
25 28 $id = parent::save($element);
26 - $this->forceInsert = false;
29 + $this->forceInsert = $previousForce;
27 30
28 - return $id;
31 + return (int)$id;
29 32 }
30 33
31 - public function getOneById($id)
32 - {
33 - $scenarioStep = acym_loadObject('SELECT * FROM #__acym_'.acym_secureDBColumn($this->table).' WHERE `'.acym_secureDBColumn($this->pkey).'` = '.acym_escapeDB($id));
34 -
35 - if (!empty($scenarioStep->params)) {
36 - $scenarioStep->params = json_decode($scenarioStep->params);
37 - }
38 -
39 - return $scenarioStep;
40 - }
41 -
42 34 public function getAllByScenarioId(int $scenarioId): array
43 35 {
44 36 $steps = array_map([$this, 'formatStep'], acym_loadObjectList('SELECT * FROM #__acym_scenario_step WHERE scenario_id = '.$scenarioId, 'id'));
45 37
@@ -58,16 +50,26 @@
58 50
59 51 return $steps;
60 52 }
61 53
62 - public function getFirstStepByScenarioId(int $scenarioId)
54 + public function getFirstStepByScenarioId(int $scenarioId): ?object
63 55 {
64 - return $this->formatStep(acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE previous_id IS NULL AND scenario_id = '.$scenarioId));
56 + $step = acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE previous_id IS NULL AND scenario_id = '.$scenarioId);
57 + if (empty($step)) {
58 + return null;
59 + }
60 +
61 + return $this->formatStep($step);
65 62 }
66 63
67 - public function getStepByPreviousStepId(string $parentId)
64 + public function getStepByPreviousStepId(string $parentId): ?object
68 65 {
69 - return $this->formatStep(acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE previous_id = '.acym_escapeDB($parentId)));
66 + $step = acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE previous_id = '.acym_escapeDB($parentId));
67 + if (empty($step)) {
68 + return null;
69 + }
70 +
71 + return $this->formatStep($step);
70 72 }
71 73
72 74 public function getAllStepsToDelete(int $scenarioId, array $stepIdsToKeep): array
73 75 {
@@ -84,28 +86,20 @@
84 86
85 87 return acym_loadResultArray($query);
86 88 }
87 89
88 - private function formatStep($step)
90 + public function getStepByPreviousConditionId(string $parentId, bool $conditionValid): ?object
89 91 {
92 + $conditionValidValue = $conditionValid ? 1 : 0;
93 +
94 + $step = acym_loadObject('SELECT * FROM #__acym_scenario_step WHERE condition_valid = '.$conditionValidValue.' AND previous_id = '.acym_escapeDB($parentId));
90 95 if (empty($step)) {
91 96 return null;
92 97 }
93 98
94 - $step->params = json_decode($step->params, true);
95 -
96 - return $step;
99 + return $this->formatStep($step);
97 100 }
98 101
99 - public function getStepByPreviousConditionId(string $parentId, bool $conditionValid)
100 - {
101 - $conditionValidValue = $conditionValid ? 1 : 0;
102 -
103 - $query = 'SELECT * FROM #__acym_scenario_step WHERE condition_valid = '.$conditionValidValue.' AND previous_id = '.acym_escapeDB($parentId);
104 -
105 - return $this->formatStep(acym_loadObject($query));
106 - }
107 -
108 102 public function getAvailableStepsByDate(string $date): array
109 103 {
110 104 $query = 'SELECT scenario_step.*, scenario_process.user_id, scenario_process.id AS scenario_process_id
111 105 FROM #__acym_scenario_step AS scenario_step
@@ -114,9 +108,9 @@
114 108
115 109 return array_map([$this, 'formatStep'], acym_loadObjectList($query));
116 110 }
117 111
118 - public function getNumberOfProcessByStepByScenarioId(int $scenarioId)
112 + public function getNumberOfProcessByStepByScenarioId(int $scenarioId): array
119 113 {
120 114 $query = 'SELECT scenario_history.scenario_step_id , COUNT(scenario_history.id) AS count
121 115 FROM #__acym_scenario_step AS scenario_step
122 116 JOIN #__acym_scenario_history_line AS scenario_history ON scenario_step.id = scenario_history.scenario_step_id AND scenario_history.scenario_step_id IS NOT NULL
@@ -140,10 +134,10 @@
140 134 $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
141 135 $randomString = '';
142 136 $length = 24;
143 137
144 - for ($i = 0 ; $i < $length ; $i++) {
145 - $randomIndex = rand(0, strlen($letters) - 1);
138 + for ($i = 0; $i < $length; $i++) {
139 + $randomIndex = acym_rand(0, strlen($letters) - 1);
146 140 $randomString .= $letters[$randomIndex];
147 141 }
148 142
149 143 if (in_array($randomString, $allStepIds)) {
@@ -150,6 +144,13 @@
150 144 return $this->generateNewStepId($allStepIds);
151 145 }
152 146
153 147 return $randomString;
148 + }
149 +
150 + private function formatStep(object $step): object
151 + {
152 + $step->params = json_decode($step->params, true);
153 +
154 + return $step;
154 155 }
155 156 }