PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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
acymailing / back / Helpers / Update / Patchv8.php

Patchv8.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at back/Helpers/Update/Patchv8.php

380 lines 13.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Helpers\Update;
4
5 use AcyMailing\Classes\ConfigurationClass;
6 use AcyMailing\Classes\FormClass;
7 use AcyMailing\Classes\MailClass;
8 use AcyMailing\Classes\RuleClass;
9
10 trait Patchv8
11 {
12 private function updateFor800(ConfigurationClass $config): void
13 {
14 if ($this->isPreviousVersionAtLeast('8.0.0')) {
15 return;
16 }
17
18 $secretKey = $config->get('smtp_secret');
19 $config->save(['smtp_type' => empty($secretKey) ? 'password' : 'oauth']);
20
21 $this->updateQuery(
22 'CREATE TABLE IF NOT EXISTS `#__acym_mailbox_action` (
23 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
24 `name` varchar(255) DEFAULT NULL,
25 `frequency` int(10) UNSIGNED NOT NULL DEFAULT 0,
26 `nextdate` int(10) UNSIGNED NOT NULL DEFAULT 0,
27 `description` text DEFAULT NULL,
28 `server` varchar(255) NULL,
29 `port` varchar(50) NULL,
30 `connection_method` ENUM(\'imap\', \'pop3\', \'pear\') NULL,
31 `secure_method` ENUM(\'ssl\', \'tls\') NULL,
32 `self_signed` tinyint(4) NULL,
33 `username` varchar(255) NULL,
34 `password` varchar(50) NULL,
35 `conditions` text DEFAULT NULL,
36 `actions` text DEFAULT NULL,
37 `report` text DEFAULT NULL,
38 `delete_wrong_emails` tinyint(4) NOT NULL DEFAULT 0,
39 `senderfrom` tinyint(4) NOT NULL DEFAULT 0,
40 `senderto` tinyint(4) NOT NULL DEFAULT 0,
41 `active` tinyint(4) NOT NULL DEFAULT 0,
42 PRIMARY KEY (`id`),
43 INDEX `index_#__acym_mailbox_action1`(`name` ASC)
44 )
45 ENGINE = InnoDB;'
46 );
47 }
48
49 private function updateFor810(): void
50 {
51 if ($this->isPreviousVersionAtLeast('8.1.0')) {
52 return;
53 }
54
55 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `settings` TEXT');
56 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `display_languages` VARCHAR(255)');
57
58 $formClass = new FormClass();
59 $forms = $formClass->getAll();
60
61 foreach ($forms as $oneForm) {
62 $oneForm->settings = [];
63 foreach ($oneForm as $key => $value) {
64 $optionsPos = strpos($key, '_options');
65 if (empty($value) || ($key !== 'cookie' && $optionsPos === false)) {
66 continue;
67 }
68
69 $category = $key === 'cookie' ? 'cookie' : substr($key, 0, $optionsPos);
70 $oneForm->settings[$category] = json_decode($value, true);
71 }
72
73 $oneForm->settings = json_encode($oneForm->settings);
74 $formClass->save($oneForm);
75 }
76
77 $this->updateQuery(
78 'ALTER TABLE `#__acym_form`
79 DROP `lists_options`,
80 DROP `fields_options`,
81 DROP `style_options`,
82 DROP `button_options`,
83 DROP `image_options`,
84 DROP `termspolicy_options`,
85 DROP `cookie`,
86 DROP `redirection_options`,
87 DROP `display_options`,
88 DROP `message_options`'
89 );
90
91 $this->updateQuery('ALTER TABLE `#__acym_user` CHANGE `key` `key` VARCHAR(40) NULL');
92 }
93
94 private function updateFor811(): void
95 {
96 if ($this->isPreviousVersionAtLeast('8.1.1')) {
97 return;
98 }
99
100 $formClass = new FormClass();
101 $forms = $formClass->getAll();
102
103 foreach ($forms as $oneForm) {
104 if (!empty($oneForm->display_languages)) {
105 continue;
106 }
107 $oneForm->display_languages = '["all"]';
108 $formClass->save($oneForm);
109 }
110 }
111
112 private function updateFor850(): void
113 {
114 if ($this->isPreviousVersionAtLeast('8.5.0')) {
115 return;
116 }
117
118 $aclPages = [
119 'forms',
120 'users',
121 'fields',
122 'lists',
123 'segments',
124 'campaigns',
125 'mails',
126 'override',
127 'automation',
128 'queue',
129 'plugins',
130 'bounces',
131 'stats',
132 'configuration',
133 ];
134
135 $config = acym_config();
136 $groups = array_keys(acym_getGroups());
137
138 foreach ($aclPages as $page) {
139 $aclConfig = $config->get('acl_'.$page, 'all');
140
141 if ($aclConfig === 'all') {
142 continue;
143 }
144
145 $groupsAuthorized = [];
146
147 foreach ($groups as $group) {
148 if ($config->get('acl_'.$page.'_'.$group, 1) == 1) {
149 $groupsAuthorized[] = $group;
150 }
151 }
152
153 $config->save(['acl_'.$page => implode(',', $groupsAuthorized)]);
154 }
155
156 $queries = file_get_contents(ACYM_BACK.'tables.sql');
157 $tables = explode('CREATE TABLE IF NOT EXISTS ', $queries);
158 $tableNames = [];
159 $indexes = [];
160 $constraints = [];
161
162 foreach ($tables as $oneTable) {
163 if (strpos($oneTable, '`#__') !== 0) {
164 continue;
165 }
166 $tableName = substr($oneTable, 1, strpos($oneTable, '`', 1) - 1);
167 $tableNames[] = $tableName;
168
169 $fields = explode("\n", $oneTable);
170 foreach ($fields as $key => $oneField) {
171 $oneField = rtrim(trim($oneField), ',');
172 if (strpos($oneField, 'INDEX') === 0) {
173 $firstBackquotePos = strpos($oneField, '`');
174 $indexName = substr($oneField, $firstBackquotePos + 1, strpos($oneField, '`', $firstBackquotePos + 1) - $firstBackquotePos - 1);
175
176 $indexes[$tableName][$indexName] = $oneField;
177 } elseif (strpos($oneField, 'FOREIGN KEY') !== false) {
178 preg_match('/(#__fk.*)\`/Uis', $fields[$key - 1], $matchesConstraints);
179 preg_match('/(#__.*)\`\(`(.*)`\)/Uis', $fields[$key + 1], $matchesTable);
180 preg_match('/\`(.*)\`/Uis', $oneField, $matchesColumn);
181 if (!empty($matchesConstraints) && !empty($matchesTable) && !empty($matchesColumn)) {
182 if (empty($constraints[$tableName])) $constraints[$tableName] = [];
183 $constraints[$tableName][$matchesConstraints[1]] = [
184 'table' => $matchesTable[1],
185 'column' => $matchesColumn[1],
186 'table_column' => $matchesTable[2],
187 ];
188 }
189 }
190 }
191 }
192
193 foreach ($tableNames as $tableName) {
194 if (!empty($indexes[$tableName])) {
195 foreach ($indexes[$tableName] as $newName => $query) {
196 $oldName = str_replace('#__index_', 'index_#__', $newName);
197 preg_match('#\(.*\)#U', $query, $matches);
198 try {
199 acym_query('ALTER TABLE `'.$tableName.'` DROP INDEX `'.$oldName.'`, ADD INDEX `'.$newName.'`'.$matches[0]);
200 } catch (\Exception $exception) {
201 if (function_exists('acym_logError')) {
202 acym_logError('Error while renaming index '.$oldName.', with the error '.$exception->getMessage());
203 }
204 }
205 }
206 }
207
208 if (!empty($constraints[$tableName])) {
209 acym_query('SET FOREIGN_KEY_CHECKS=0;');
210 foreach ($constraints[$tableName] as $newName => $constraintInfo) {
211 $oldName = str_replace('#__fk_', 'fk_#__', $newName);
212 $query = 'ALTER TABLE '.$tableName.' DROP FOREIGN KEY `'.$oldName.'`,ADD CONSTRAINT `'.$newName.'` FOREIGN KEY (`'.$constraintInfo['column'].'`) REFERENCES `'.$constraintInfo['table'].'` (`'.$constraintInfo['table_column'].'`) ON DELETE NO ACTION ON UPDATE NO ACTION;';
213 try {
214 acym_query($query);
215 } catch (\Exception $exception) {
216 if (function_exists('acym_logError')) {
217 acym_logError('Error while renaming foreign key '.$oldName.', with the error '.$exception->getMessage());
218 }
219 }
220 }
221 acym_query('SET FOREIGN_KEY_CHECKS=1;');
222 }
223 }
224 }
225
226 private function updateFor860(): void
227 {
228 if ($this->isPreviousVersionAtLeast('8.6.0')) {
229 return;
230 }
231
232 $ruleClass = new RuleClass();
233
234 $rule = new \stdClass();
235 $rule->name = 'ACYM_SUPPRESSION_LIST';
236 $rule->ordering = 2;
237 $rule->regex = 'suppression list';
238 $rule->executed_on = '["body"]';
239 $rule->action_message = '["delete_message"]';
240 $rule->action_user = '["unsubscribe_user","block_user","empty_queue_user"]';
241 $rule->active = 1;
242 $rule->increment_stats = 1;
243 $rule->execute_action_after = 0;
244 $ruleClass->save($rule);
245
246 $rule = new \stdClass();
247 $rule->name = 'ACYM_REJECTED';
248 $rule->ordering = 9;
249 $rule->regex = 'rejected *your *message|email *provider *rejected *it';
250 $rule->executed_on = '["body"]';
251 $rule->action_message = '["delete_message"]';
252 $rule->action_user = '[]';
253 $rule->active = 1;
254 $rule->increment_stats = 1;
255 $rule->execute_action_after = 0;
256 $ruleClass->save($rule);
257
258 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_sent_date` DATETIME NULL');
259 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_open_date` DATETIME NULL');
260 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_click_date` DATETIME NULL');
261
262 $this->updateQuery(
263 'CREATE TABLE IF NOT EXISTS `#__acym_mail_archive` (
264 `id` INT NOT NULL AUTO_INCREMENT,
265 `mail_id` INT NOT NULL,
266 `date` INT(10) UNSIGNED NOT NULL,
267 `body` LONGTEXT NOT NULL,
268 `subject` VARCHAR(255) NULL,
269 `settings` TEXT NULL,
270 `stylesheet` TEXT NULL,
271 `attachments` TEXT NULL,
272 PRIMARY KEY (`id`),
273 CONSTRAINT `#__fk_acym_mail_archive1`
274 FOREIGN KEY (`mail_id`)
275 REFERENCES `#__acym_mail`(`id`)
276 ON DELETE NO ACTION
277 ON UPDATE NO ACTION
278 )
279 ENGINE = InnoDB;'
280 );
281 }
282
283 private function updateFor862(): void
284 {
285 if ($this->isPreviousVersionAtLeast('8.6.2')) {
286 return;
287 }
288
289 $this->updateQuery('DELETE FROM #__acym_campaign WHERE mail_id IS NULL');
290
291 $mailsToClean = acym_loadResultArray(
292 'SELECT mail.id
293 FROM `#__acym_mail` AS mail
294 LEFT JOIN #__acym_campaign AS campaign
295 ON mail.id = campaign.mail_id
296 WHERE campaign.mail_id IS NULL
297 AND mail.parent_id IS NULL
298 AND mail.type = '.acym_escapeDB(MailClass::TYPE_STANDARD)
299 );
300
301 if (!empty($mailsToClean)) {
302 $this->updateQuery('DELETE FROM #__acym_mail_archive WHERE mail_id IN ('.implode(',', $mailsToClean).')');
303 $mailClass = new MailClass();
304 $mailClass->delete($mailsToClean);
305 }
306 }
307
308 private function updateFor870(): void
309 {
310 if ($this->isPreviousVersionAtLeast('8.7.0')) {
311 return;
312 }
313
314 $this->updateQuery('ALTER TABLE #__acym_plugin DROP `features`');
315 }
316
317 private function updateFor872(ConfigurationClass $config): void
318 {
319 if ($this->isPreviousVersionAtLeast('8.7.2')) {
320 return;
321 }
322
323 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
324 if (empty($socialIcons['X'])) {
325 $socialIcons['X'] = ACYM_IMAGES.'logo/x.png';
326
327 $newConfig = new \stdClass();
328 $newConfig->social_icons = json_encode($socialIcons);
329 $config->save($newConfig);
330 }
331 }
332
333 private function updateFor873(ConfigurationClass $config): void
334 {
335 if ($this->isPreviousVersionAtLeast('8.7.3')) {
336 return;
337 }
338
339 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
340
341 if (!empty($socialIcons['X'])) {
342 unset($socialIcons['X']);
343
344 $newConfig = new \stdClass();
345 $newConfig->social_icons = json_encode($socialIcons);
346 $config->save($newConfig);
347 }
348
349 if (empty($socialIcons['x'])) {
350 $socialIcons['x'] = ACYM_IMAGES.'logo/x.png';
351
352 $newConfig = new \stdClass();
353 $newConfig->social_icons = json_encode($socialIcons);
354 $config->save($newConfig);
355 }
356 }
357
358 private function updateFor874(ConfigurationClass $config): void
359 {
360 if ($this->isPreviousVersionAtLeast('8.7.4') || ACYM_CMS !== 'joomla') {
361 return;
362 }
363
364 $config->save(['malicious_scan' => 1]);
365 }
366
367 private function updateFor881(ConfigurationClass $config): void
368 {
369 if ($this->isPreviousVersionAtLeast('8.7.0')) {
370 return;
371 }
372
373 $uploadFolder = $config->get('uploadfolder');
374 if (!empty($uploadFolder) && strpos($uploadFolder, '\\') !== false) {
375 $uploadFolder = str_replace('\\', '/', $uploadFolder);
376 $config->save(['uploadfolder' => $uploadFolder]);
377 }
378 }
379 }
380