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 / Patchv6.php

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

823 lines 33.2 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\ActionClass;
6 use AcyMailing\Classes\ConditionClass;
7 use AcyMailing\Classes\ConfigurationClass;
8 use AcyMailing\Classes\FieldClass;
9 use AcyMailing\Classes\ListClass;
10 use AcyMailing\Classes\MailClass;
11 use AcyMailing\Classes\PluginClass;
12 use AcyMailing\Controllers\PluginsController;
13 use AcyMailing\Helpers\AutomationHelper;
14 use AcyMailing\Helpers\UpdateHelper;
15
16 trait Patchv6
17 {
18 private function updateFor603(): void
19 {
20 if ($this->isPreviousVersionAtLeast('6.0.3')) {
21 return;
22 }
23
24 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD COLUMN `bounce_details` LONGTEXT NULL');
25 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD COLUMN `bounce_unique` MEDIUMINT(8) NOT NULL');
26 $this->updateQuery('ALTER TABLE #__acym_user_stat ADD COLUMN `bounce` TINYINT(4) NOT NULL');
27 $this->updateQuery('ALTER TABLE #__acym_user_stat ADD COLUMN `bounce_rule` VARCHAR(255) NULL');
28 $this->updateQuery(
29 'CREATE TABLE IF NOT EXISTS `#__acym_history` (
30 `user_id` INT NOT NULL,
31 `date` INT NOT NULL,
32 `ip` VARCHAR(16) DEFAULT NULL,
33 `action` VARCHAR(50) NOT NULL,
34 `data` text,
35 `source` text,
36 `mail_id` MEDIUMINT DEFAULT NULL,
37 PRIMARY KEY (`user_id`,`date`)
38 )'
39 );
40 $this->updateQuery('ALTER TABLE #__acym_rule CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT');
41 $this->updateQuery('ALTER TABLE #__acym_rule ADD COLUMN `increment_stats` TINYINT(3) NOT NULL');
42 $this->updateQuery('ALTER TABLE #__acym_rule ADD COLUMN `execute_action_after` INT NOT NULL');
43
44 $this->updateQuery('UPDATE #__acym_field SET `name` = "ACYM_NAME" WHERE `id` = 1 AND `name` = "Name"');
45 $this->updateQuery('UPDATE #__acym_field SET `name` = "ACYM_EMAIL" WHERE `id` = 2 AND `name` = "Email"');
46 $this->updateQuery('UPDATE #__acym_field SET `backend_profile` = 1, `backend_listing` = 1 WHERE `id` IN (1, 2)');
47
48 $this->updateQuery('UPDATE #__acym_mail SET `thumbnail` = ""');
49
50 if (ACYM_CMS === 'wordpress') {
51 $this->updateQuery('UPDATE #__acym_configuration SET `value` = '.acym_escapeDB(ACYM_UPLOAD_FOLDER).' WHERE `name` = "uploadfolder"');
52 $this->updateQuery('UPDATE #__acym_configuration SET `value` = '.acym_escapeDB(ACYM_LOGS_FOLDER.'report_{year}_{month}.log').' WHERE `name` = "cron_savepath"');
53 }
54 }
55
56 private function updateFor610(): void
57 {
58 if ($this->isPreviousVersionAtLeast('6.1.0')) {
59 return;
60 }
61
62 $this->updateQuery('DROP TABLE IF EXISTS `#__acym_automation_has_step`, `#__acym_step`, `#__acym_automation`');
63 $this->updateQuery(
64 'CREATE TABLE IF NOT EXISTS `#__acym_automation` (
65 `id` INT NOT NULL AUTO_INCREMENT,
66 `name` VARCHAR(255) NOT NULL,
67 `description` LONGTEXT NULL,
68 `active` TINYINT(3) NOT NULL,
69 `report` TEXT NULL,
70 `tree` LONGTEXT NULL,
71 PRIMARY KEY (`id`)
72 )
73 ENGINE = InnoDB;'
74 );
75 $this->updateQuery(
76 'CREATE TABLE IF NOT EXISTS `#__acym_step` (
77 `id` INT NOT NULL AUTO_INCREMENT,
78 `name` VARCHAR(255) NOT NULL,
79 `triggers` LONGTEXT NULL,
80 `automation_id` INT NOT NULL,
81 `last_execution` INT NULL,
82 `next_execution` INT NULL,
83 PRIMARY KEY (`id`),
84 CONSTRAINT `fk#__acym__step1`
85 FOREIGN KEY(`automation_id`)
86 REFERENCES `#__acym_automation` (`id`)
87 ON DELETE NO ACTION
88 ON UPDATE NO ACTION
89 )
90 ENGINE = InnoDB;'
91 );
92 $this->updateQuery(
93 'CREATE TABLE IF NOT EXISTS `#__acym_condition` (
94 `id` INT NOT NULL AUTO_INCREMENT,
95 `step_id` INT NOT NULL,
96 `conditions` LONGTEXT NULL,
97 PRIMARY KEY (`id`),
98 CONSTRAINT `fk_#__acym_condition1`
99 FOREIGN KEY (`step_id`)
100 REFERENCES `#__acym_step` (`id`)
101 ON DELETE NO ACTION
102 ON UPDATE NO ACTION
103 )
104 ENGINE =InnoDB;'
105 );
106 $this->updateQuery(
107 'CREATE TABLE IF NOT EXISTS `#__acym_action` (
108 `id` INT NOT NULL AUTO_INCREMENT,
109 `condition_id` INT NOT NULL,
110 `actions` LONGTEXT NULL,
111 `filters` LONGTEXT NULL,
112 `order` INT NOT NULL,
113 PRIMARY KEY (`id`),
114 CONSTRAINT `fk_#__acym_action1`
115 FOREIGN KEY (`condition_id`)
116 REFERENCES `#__acym_condition` (`id`)
117 ON DELETE NO ACTION
118 ON UPDATE NO ACTION
119 )
120 ENGINE =InnoDB;'
121 );
122
123 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `automation` VARCHAR(50) NOT NULL');
124
125 $query = 'SELECT field.type AS type, userfield.user_id AS user_id, userfield.field_id AS field_id, userfield.value AS user_value
126 FROM #__acym_user_has_field AS userfield
127 JOIN #__acym_field AS field ON userfield.field_id = field.id
128 WHERE field.type IN ("checkbox", "multiple_dropdown")';
129 $fieldValues = acym_loadObjectList($query);
130 foreach ($fieldValues as $fieldValue) {
131 $value = [];
132 if ('checkbox' === $fieldValue->type) {
133 $value = json_decode($fieldValue->user_value, true);
134 $value = array_keys($value);
135 } elseif ('multiple_dropdown' === $fieldValue->type) {
136 $value = json_decode($fieldValue->user_value, true);
137 }
138 $value = implode(',', $value);
139 $this->updateQuery(
140 'UPDATE #__acym_user_has_field
141 SET `value` = '.acym_escapeDB($value).'
142 WHERE user_id = '.intval($fieldValue->user_id).'
143 AND field_id = '.intval($fieldValue->field_id)
144 );
145 }
146 }
147
148 private function updateFor612(): void
149 {
150 if ($this->isPreviousVersionAtLeast('6.1.2')) {
151 return;
152 }
153
154 $this->updateQuery('ALTER TABLE #__acym_mail ADD `media_folder` VARCHAR(255) NULL');
155 $this->updateQuery('ALTER TABLE #__acym_field ADD `namekey` VARCHAR(255) NOT NULL');
156
157 $query = 'SELECT field.type AS type, userfield.user_id AS user_id, userfield.field_id AS field_id, userfield.value AS user_value
158 FROM #__acym_user_has_field AS userfield
159 JOIN #__acym_field AS field ON userfield.field_id = field.id
160 WHERE field.type IN ("phone")';
161 $fieldValues = acym_loadObjectList($query);
162
163 if (!empty($fieldValues)) {
164 foreach ($fieldValues as $fieldValue) {
165 $value = json_decode($fieldValue->user_value, true);
166 $value = implode(',', $value);
167 $this->updateQuery(
168 'UPDATE #__acym_user_has_field
169 SET `value` = '.acym_escapeDB($value).'
170 WHERE user_id = '.intval($fieldValue->user_id).'
171 AND field_id = '.intval($fieldValue->field_id)
172 );
173 }
174 }
175
176 $fieldClass = new FieldClass();
177 $fields = acym_loadObjectList('SELECT * FROM #__acym_field');
178 foreach ($fields as $field) {
179 if (!empty($field->namekey)) continue;
180 $field->namekey = $fieldClass->generateNamekey($field->name);
181 $fieldClass->save($field);
182 }
183 }
184
185 private function updateFor613(): void
186 {
187 if ($this->isPreviousVersionAtLeast('6.1.3')) {
188 return;
189 }
190
191 $this->updateQuery('UPDATE #__acym_user_has_list SET `status` = 1 WHERE `status` = 2');
192 }
193
194 private function updateFor614(): void
195 {
196 if ($this->isPreviousVersionAtLeast('6.1.4')) {
197 return;
198 }
199
200 $this->updateQuery('ALTER TABLE #__acym_mail ADD `headers` TEXT NULL');
201 $this->updateQuery('ALTER TABLE #__acym_mail ADD `autosave` LONGTEXT NULL');
202
203 $columns = acym_getColumns('condition');
204 if (!in_array('conditions', $columns)) {
205 $this->updateQuery('ALTER TABLE #__acym_condition CHANGE `condition` `conditions` LONGTEXT NULL');
206 }
207
208 $this->updateQuery('ALTER TABLE #__acym_automation ADD `admin` TINYINT(3) NULL');
209 }
210
211 private function updateFor615(ConfigurationClass $config): void
212 {
213 if ($this->isPreviousVersionAtLeast('6.1.5')) {
214 return;
215 }
216
217 $this->updateQuery('ALTER TABLE #__acym_mail ADD `preheader` VARCHAR(255) NULL');
218
219 $wrongRuleAddresses = acym_loadObjectList('SELECT `id`, `action_message` FROM `#__acym_rule` WHERE `action_message` LIKE "%\"forward_to\":\"\'%"');
220 if (!empty($wrongRuleAddresses)) {
221 foreach ($wrongRuleAddresses as $oneRule) {
222 $actions = json_decode($oneRule->action_message, true);
223 $actions['forward_to'] = trim($actions['forward_to'], "'");
224 $this->updateQuery('UPDATE `#__acym_rule` SET `action_message` = '.acym_escapeDB(json_encode($actions)).' WHERE `id` = '.intval($oneRule->id));
225 }
226 }
227
228 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
229 if (!empty($socialIcons['google'])) {
230 unset($socialIcons['google']);
231
232 $newConfig = new \stdClass();
233 $newConfig->social_icons = json_encode($socialIcons);
234 $config->save($newConfig);
235 }
236
237
238 $mailsWithGoogle = acym_loadObjectList('SELECT `id`, `body` FROM `#__acym_mail` WHERE `body` LIKE "%googleplus%"');
239 foreach ($mailsWithGoogle as $oneMail) {
240 $body = preg_replace('#<a [^>]*googleplus[^>]*>[^<]*<img [^>]*>[^<]*</a>#Uis', '', $oneMail->body);
241 if (empty($body)) continue;
242
243 $this->updateQuery('UPDATE `#__acym_mail` SET `body` = '.acym_escapeDB($body).' WHERE `id` = '.intval($oneMail->id));
244 }
245
246 $this->updateQuery('ALTER TABLE #__acym_user ADD `confirmation_date` DATETIME DEFAULT NULL');
247 $this->updateQuery('ALTER TABLE #__acym_user ADD `confirmation_ip` VARCHAR(16) DEFAULT NULL');
248
249 $mails = acym_loadObjectList('SELECT subject, id FROM #__acym_mail');
250 $mailClass = new MailClass();
251 $mails = $mailClass->encode($mails);
252
253 foreach ($mails as $oneMail) {
254 $this->updateQuery('UPDATE #__acym_mail SET `subject` = '.acym_escapeDB($oneMail->subject).' WHERE `id` = '.intval($oneMail->id));
255 }
256 }
257
258 private function updateFor616(): void
259 {
260 if ($this->isPreviousVersionAtLeast('6.1.6')) {
261 return;
262 }
263
264 $mails = acym_loadObjectList('SELECT `id`, `name`, `body`, `autosave`, `preheader` FROM #__acym_mail');
265 $mailClass = new MailClass();
266 $mails = $mailClass->encode($mails);
267
268 foreach ($mails as $oneMail) {
269 $this->updateQuery(
270 'UPDATE #__acym_mail SET `body` = '.acym_escapeDB($oneMail->body).', `autosave` = '.acym_escapeDB($oneMail->autosave).', `name` = '.acym_escapeDB(
271 $oneMail->name
272 ).', `preheader` = '.acym_escapeDB($oneMail->preheader).' WHERE `id` = '.intval($oneMail->id)
273 );
274 }
275 }
276
277 private function updateFor617(): void
278 {
279 if ($this->isPreviousVersionAtLeast('6.1.7')) {
280 return;
281 }
282
283 $actionClass = new ActionClass();
284 $actions = $actionClass->getAll();
285 foreach ($actions as $action) {
286 $action->actions = str_replace('{time}', '[time]', $action->actions);
287 $action->filters = str_replace('{time}', '[time]', $action->filters);
288 $actionClass->save($action);
289 }
290
291 $conditionClass = new ConditionClass();
292 $conditions = $conditionClass->getAll();
293 foreach ($conditions as $condition) {
294 $condition->conditions = str_replace('{time}', '[time]', $condition->conditions);
295 $conditionClass->save($condition);
296 }
297 }
298
299 private function updateFor622(ConfigurationClass $config): void
300 {
301 if ($this->isPreviousVersionAtLeast('6.2.2')) {
302 return;
303 }
304
305 $allowedExtensions = explode(',', $config->get('allowed_files'));
306 if (!empty($allowedExtensions)) {
307 $uploadFolder = trim(acym_cleanPath(html_entity_decode(ACYM_UPLOAD_FOLDER)), DS.' ').DS;
308 $uploadPath = acym_cleanPath(ACYM_ROOT.$uploadFolder.'userfiles'.DS);
309
310 if (file_exists($uploadPath)) {
311 $files = acym_getFiles($uploadPath);
312 if (!empty($files)) {
313 foreach ($files as $fileName) {
314 if (!preg_match('#\.('.implode('|', $allowedExtensions).')$#Ui', $fileName)) {
315 acym_deleteFile($uploadPath.DS.$fileName);
316 }
317 }
318 }
319 }
320 }
321 }
322
323 private function updateFor640(): void
324 {
325 if ($this->isPreviousVersionAtLeast('6.4.0')) {
326 return;
327 }
328
329 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `sending_type` VARCHAR(16) DEFAULT NULL');
330 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `sending_params` TEXT DEFAULT NULL');
331 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `parent_id` INT DEFAULT NULL');
332 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `last_trigger` INT DEFAULT NULL');
333 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `next_trigger` INT DEFAULT NULL');
334
335 $this->updateQuery('UPDATE #__acym_campaign SET `sending_type` = "now" WHERE `scheduled` = 0');
336 $this->updateQuery('UPDATE #__acym_campaign SET `sending_type` = "scheduled" WHERE `scheduled` = 1');
337 $this->updateQuery('UPDATE #__acym_campaign SET `sending_params` = "[]"');
338
339 $this->updateQuery('ALTER TABLE #__acym_campaign DROP `scheduled`');
340 }
341
342 private function updateFor650(): void
343 {
344 if ($this->isPreviousVersionAtLeast('6.5.0')) {
345 return;
346 }
347
348 $this->updateQuery(
349 'CREATE TABLE IF NOT EXISTS `#__acym_plugin` (
350 `id` INT NOT NULL AUTO_INCREMENT,
351 `title` VARCHAR (100) NOT NULL,
352 `folder_name` VARCHAR(100) NOT NULL,
353 `version` VARCHAR (10) NULL,
354 `active` INT NOT NULL,
355 `category` VARCHAR (100) NOT NULL,
356 `level` VARCHAR (50) NOT NULL,
357 `uptodate` INT NOT NULL,
358 `features` VARCHAR (255) NOT NULL,
359 `description` LONGTEXT NOT NULL,
360 `latest_version` VARCHAR (255) NOT NULL,
361 PRIMARY KEY (`id`)
362 )
363 ENGINE = InnoDB;'
364 );
365
366 $pluginsBefore650 = [
367 'joomla' => [
368 'cbuilder' => 'com_comprofiler',
369 'eventbooking' => 'com_eventbooking',
370 'hikashop' => 'com_hikashop',
371 'jevents' => 'com_jevents',
372 'payplans' => 'com_payplans',
373 'seblod' => 'com_cck',
374 'virtuemart' => 'com_virtuemart',
375 ],
376 'wordpress' => [
377 'woocommerce' => 'woocommerce',
378 ],
379 ];
380
381 $pluginsController = new PluginsController();
382 foreach ($pluginsBefore650[ACYM_CMS] as $plugin => $extension) {
383 $install = false;
384 if (defined('JPATH_ADMINISTRATOR') && file_exists(rtrim(JPATH_ADMINISTRATOR, DS).DS.'components'.DS.$extension.DS)) {
385 $install = true;
386 }
387
388 if (defined('WP_PLUGIN_DIR') && file_exists(rtrim(WP_PLUGIN_DIR, DS).DS.$extension.DS)) {
389 $install = true;
390 }
391
392 if ($install) {
393 $error = $pluginsController->download(false, $plugin);
394 if (!empty($error)) {
395 acym_enqueueMessage($error, 'error');
396 }
397 }
398 }
399 $this->updateQuery('ALTER TABLE #__acym_campaign CHANGE `last_trigger` `last_generated` INT DEFAULT NULL');
400 }
401
402 private function updateFor660(): void
403 {
404 if ($this->isPreviousVersionAtLeast('6.6.0')) {
405 return;
406 }
407
408 $mailClass = new MailClass();
409 $firstEmail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY));
410 if (!empty($firstEmail)) {
411 $firstEmail->body = preg_replace(
412 '#(<em class="acym_remove_dynamic acymicon-close">)(</em>)#Uis',
413 '$1&zwj;$2',
414 $firstEmail->body
415 );
416
417
418
419 $closing = '<em class="acym_remove_dynamic acymicon-close">&zwj;</em>';
420
421 $firstEmail->body = preg_replace(
422 '#(<span[^>]+data\-dynamic="{readonline}.+<span class="acym_online">[^<]+</span>[^<]*</a>[^<]*)(</span>)#Uis',
423 '$1'.$closing.'$2',
424 $firstEmail->body
425 );
426
427 $firstEmail->body = preg_replace(
428 '#(<span[^>]+data\-dynamic="{subscriber:name[^>]+>[^<]+)(</span>)#Uis',
429 '$1'.$closing.'$2',
430 $firstEmail->body
431 );
432
433 $firstEmail->body = preg_replace(
434 '#(<span[^>]+data\-dynamic="{unsubscribe}.+<span class="acym_unsubscribe">[^<]+</span>[^<]*</a>[^<]*)(</span>)#Uis',
435 '$1'.$closing.'$2',
436 $firstEmail->body
437 );
438
439 $mailClass->save($firstEmail);
440 }
441
442 $joomlaPluginsBefore650 = [
443 'cbuilder',
444 'eventbooking',
445 'hikashop',
446 'jevents',
447 'payplans',
448 'seblod',
449 'virtuemart',
450 ];
451
452 $installedAddons = acym_loadResultArray('SELECT folder_name FROM #__acym_plugin');
453
454 foreach ($joomlaPluginsBefore650 as $folderName) {
455 if (in_array($folderName, $installedAddons) || !file_exists(ACYM_ADDONS_FOLDER_PATH.$folderName)) continue;
456
457 acym_deleteFolder(ACYM_ADDONS_FOLDER_PATH.$folderName);
458 }
459 }
460
461 private function updateFor670(): void
462 {
463 if ($this->isPreviousVersionAtLeast('6.7.0')) {
464 return;
465 }
466
467 $this->updateQuery('DELETE FROM #__acym_configuration WHERE `name` = "small_display"');
468 $this->updateQuery('UPDATE #__acym_configuration SET `value` = REPLACE(REPLACE(`value`, ",", "comma"), ";", "semicol") WHERE `name` = "export_separator"');
469 $this->updateQuery('ALTER TABLE #__acym_field DROP COLUMN frontend_form');
470 $this->updateQuery('ALTER TABLE #__acym_field CHANGE `frontend_profile` `frontend_edition` TINYINT(3) NULL');
471 $this->updateQuery('ALTER TABLE #__acym_field CHANGE `backend_profile` `backend_edition` TINYINT(3) NULL');
472 $this->updateQuery('ALTER TABLE #__acym_list ADD COLUMN `front_management` INT NULL');
473 }
474
475 private function updateFor692(): void
476 {
477 if ($this->isPreviousVersionAtLeast('6.9.2')) {
478 return;
479 }
480
481 $socialFilesFolder = ACYM_ROOT.ACYM_UPLOAD_FOLDER.'socials';
482 if (file_exists($socialFilesFolder)) {
483 $uploadedFiles = acym_getFiles($socialFilesFolder);
484 foreach ($uploadedFiles as $oneFile) {
485 $extension = acym_fileGetExt($oneFile);
486 if (!in_array($extension, acym_getImageFileExtensions())) {
487 acym_deleteFile($socialFilesFolder.DS.$oneFile);
488 }
489 }
490 }
491 }
492
493 private function updateFor6100(): void
494 {
495 if ($this->isPreviousVersionAtLeast('6.10.0')) {
496 return;
497 }
498
499 $mailClass = new MailClass();
500 $fieldColumns = acym_getColumns('field');
501 if (in_array('backend_filter', $fieldColumns)) {
502 $this->updateQuery('ALTER TABLE #__acym_field DROP COLUMN backend_filter');
503 }
504 if (in_array('frontend_filter', $fieldColumns)) {
505 $this->updateQuery('ALTER TABLE #__acym_field DROP COLUMN frontend_filter');
506 }
507 $mails = acym_loadObjectList('SELECT * FROM #__acym_mail WHERE thumbnail LIKE "%data:image/png;base64%"');
508 foreach ($mails as $mail) {
509 unset($mail->thumbnail);
510 $mailClass->save($mail);
511 }
512
513 $this->updateQuery('DELETE FROM #__acym_user_has_field WHERE `value` = ""');
514
515 $phoneFields = acym_loadResultArray('SELECT `id` FROM #__acym_field WHERE `type` = "phone"');
516 if (!empty($phoneFields)) {
517 $this->updateQuery('DELETE FROM #__acym_user_has_field WHERE `value` LIKE "%," AND `field_id` IN ('.implode(', ', $phoneFields).')');
518 }
519 }
520
521 private function updateFor6102(): void
522 {
523 if ($this->isPreviousVersionAtLeast('6.10.2')) {
524 return;
525 }
526
527 $this->updateQuery('ALTER TABLE #__acym_mail ADD COLUMN `links_language` VARCHAR(10) NOT NULL DEFAULT ""');
528 }
529
530 private function updateFor6104(): void
531 {
532 if ($this->isPreviousVersionAtLeast('6.10.4')) {
533 return;
534 }
535
536 $columnsUser = acym_getColumns('user');
537 if (!empty($columnsUser)) {
538 foreach ($columnsUser as $i => $oneColumn) {
539 $columnsUser[$i] = acym_escapeDB($oneColumn);
540 }
541
542 $customFieldsWrongNamekey = acym_loadObjectList('SELECT * FROM #__acym_field WHERE namekey IN ('.implode(', ', $columnsUser).')');
543 $fieldClass = new FieldClass();
544
545 foreach ($customFieldsWrongNamekey as $field) {
546 $field->namekey = $fieldClass->generateNamekey($field->name);
547 $fieldClass->save($field);
548 }
549 }
550
551 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `type` `type` VARCHAR(30) NOT NULL');
552 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `media_folder` `media_folder` VARCHAR(100) NULL');
553 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `links_language` `links_language` VARCHAR(10) NOT NULL');
554 }
555
556 private function updateFor6110(): void
557 {
558 if ($this->isPreviousVersionAtLeast('6.11.0')) {
559 return;
560 }
561
562 $this->updateQuery('ALTER TABLE #__acym_mail ADD `access` VARCHAR(50) NOT NULL DEFAULT ""');
563 $this->updateQuery('ALTER TABLE #__acym_list ADD `access` VARCHAR(50) NOT NULL DEFAULT ""');
564
565 $sourceMap = [
566 'wordpress_profile' => 'WordPress user profile',
567 'backend_management' => 'Back-end',
568 'frontend_management' => 'Front-end',
569 'auto_on_sending' => 'When sending a test',
570 'menu_' => 'Menu n°',
571 'mod_' => 'Module n°',
572 '_frontregister' => ' registration form',
573 'import_' => 'Import on ',
574 ];
575
576 foreach ($sourceMap as $oldSource => $newSource) {
577 acym_query('UPDATE `#__acym_user` SET `source` = REPLACE(`source`, '.acym_escapeDB($oldSource).', '.acym_escapeDB($newSource).')');
578 }
579
580 $this->updateQuery('ALTER TABLE #__acym_list ADD `description` TEXT NOT NULL DEFAULT ""');
581 }
582
583 private function updateFor6120(): void
584 {
585 if ($this->isPreviousVersionAtLeast('6.12.0')) {
586 return;
587 }
588
589 $this->updateQuery('ALTER TABLE #__acym_user ADD `tracking` TINYINT(1) NOT NULL DEFAULT 1');
590 $this->updateQuery('ALTER TABLE #__acym_list ADD `tracking` TINYINT(1) NOT NULL DEFAULT 1');
591 $this->updateQuery('ALTER TABLE #__acym_mail ADD `tracking` TINYINT(1) NOT NULL DEFAULT 1');
592 $this->updateQuery('ALTER TABLE #__acym_plugin ADD `settings` LONGTEXT NULL');
593 }
594
595 private function updateFor6130(): void
596 {
597 if ($this->isPreviousVersionAtLeast('6.13.0')) {
598 return;
599 }
600
601 $this->updateQuery('ALTER TABLE #__acym_plugin ADD `core` TINYINT(1) NOT NULL DEFAULT 0');
602 $this->updateQuery('ALTER TABLE #__acym_plugin CHANGE `latest_version` `latest_version` VARCHAR(10) NOT NULL');
603 }
604
605 private function updateFor6140(): void
606 {
607 if ($this->isPreviousVersionAtLeast('6.14.0')) {
608 return;
609 }
610
611 $this->updateQuery(
612 'CREATE TABLE IF NOT EXISTS `#__acym_form` (
613 `id` INT NOT NULL AUTO_INCREMENT,
614 `name` VARCHAR(255) NOT NULL,
615 `creation_date` DATETIME NOT NULL,
616 `active` TINYINT(1) NOT NULL DEFAULT 1,
617 `type` VARCHAR(20) NOT NULL,
618 `lists_options` LONGTEXT,
619 `fields_options` LONGTEXT,
620 `style_options` LONGTEXT,
621 `button_options` LONGTEXT,
622 `image_options` LONGTEXT,
623 `delay` SMALLINT(10),
624 `pages` TEXT,
625 PRIMARY KEY (`id`)
626 )
627 ENGINE = InnoDB;'
628 );
629
630 if (file_exists(ACYM_ADDONS_FOLDER_PATH.'Volumes')) {
631 $wrongAddons = acym_getFolders(ACYM_ADDONS_FOLDER_PATH.'Volumes'.DS.'workspace'.DS.'acymailing'.DS.'addons'.DS);
632
633 $pluginClass = new PluginClass();
634 foreach ($wrongAddons as $oneGoneWrong) {
635 $pluginClass->downloadAddon($oneGoneWrong, false);
636 }
637
638 acym_deleteFolder(ACYM_ADDONS_FOLDER_PATH.'Volumes');
639 }
640
641 $this->updateQuery('ALTER TABLE #__acym_user ADD `language` VARCHAR(10) NOT NULL');
642 $this->updateQuery('ALTER TABLE #__acym_mail ADD `language` VARCHAR(10) NOT NULL');
643 $this->updateQuery('ALTER TABLE #__acym_mail ADD `parent_id` INT NULL');
644 }
645
646 private function updateFor6150(): void
647 {
648 if ($this->isPreviousVersionAtLeast('6.15.0')) {
649 return;
650 }
651
652 $this->updateQuery('ALTER TABLE #__acym_user_stat ADD `tracking_sale` FLOAT NULL');
653 $this->updateQuery('ALTER TABLE #__acym_user_stat ADD `currency` VARCHAR(10) NULL');
654 $this->updateQuery('ALTER TABLE #__acym_campaign ADD `visible` TINYINT(1) NOT NULL DEFAULT 1');
655 $this->updateQuery('ALTER TABLE #__acym_user CHANGE `language` `language` VARCHAR(10) NOT NULL DEFAULT ""');
656 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `language` `language` VARCHAR(10) NOT NULL DEFAULT ""');
657 $this->updateQuery('ALTER TABLE `#__acym_mail` CHANGE `preheader` `preheader` TEXT NULL');
658 }
659
660 private function updateFor6160(): void
661 {
662 if ($this->isPreviousVersionAtLeast('6.16.0')) {
663 return;
664 }
665
666 $this->updateQuery('ALTER TABLE `#__acym_mail_stat` CHANGE `bounce_unique` `bounce_unique` MEDIUMINT(8) NOT NULL DEFAULT 0');
667 $this->updateQuery('ALTER TABLE `#__acym_user_stat` CHANGE `bounce` `bounce` TINYINT(4) NOT NULL DEFAULT 0');
668 $this->updateQuery('ALTER TABLE #__acym_plugin ADD `type` VARCHAR(20) NOT NULL DEFAULT "ADDON"');
669 $this->updateQuery('UPDATE `#__acym_plugin` SET `type` = "ADDON" WHERE `core` = 0');
670 $this->updateQuery('UPDATE `#__acym_plugin` SET `type` = "CORE" WHERE `core` = 1');
671 $this->updateQuery('ALTER TABLE #__acym_plugin DROP `core`');
672 $this->updateQuery('ALTER TABLE `#__acym_form` ADD termspolicy_options LONGTEXT');
673 $this->updateQuery('UPDATE `#__acym_form` SET `termspolicy_options` = "{\"termscond\":0,\"privacy\":0}" WHERE `termspolicy_options` is NULL');
674 }
675
676 private function updateFor6170(): void
677 {
678 if ($this->isPreviousVersionAtLeast('6.17.0')) {
679 return;
680 }
681
682 $this->updateQuery(
683 'CREATE TABLE IF NOT EXISTS `#__acym_segment` (
684 `id` INT NOT NULL AUTO_INCREMENT,
685 `name` VARCHAR(255) NOT NULL,
686 `creation_date` DATETIME NOT NULL,
687 `active` TINYINT(1) NOT NULL DEFAULT 1,
688 `filters` LONGTEXT NULL,
689 PRIMARY KEY (`id`)
690 )
691 ENGINE = InnoDB;'
692 );
693 $automationHelper = new AutomationHelper();
694 $automationHelper->deleteUnusedEmails();
695 $this->updateQuery('ALTER TABLE `#__acym_form` ADD cookie VARCHAR(30)');
696 $this->updateQuery('UPDATE `#__acym_form` SET `cookie` = "{\"cookie_expiration\":1}" WHERE `cookie` IS NULL');
697 }
698
699 private function updateFor6180(): void
700 {
701 if ($this->isPreviousVersionAtLeast('6.18.0')) {
702 return;
703 }
704
705 $this->updateQuery(
706 'CREATE TABLE IF NOT EXISTS `#__acym_followup` (
707 `id` INT NOT NULL AUTO_INCREMENT,
708 `name` VARCHAR(255) NOT NULL,
709 `display_name` VARCHAR(255) NOT NULL,
710 `creation_date` DATETIME NOT NULL,
711 `trigger` VARCHAR(50),
712 `condition` LONGTEXT,
713 `active` TINYINT(1) NOT NULL DEFAULT 1,
714 `send_once` TINYINT(1) NOT NULL DEFAULT 1,
715 `list_id` INT NULL,
716 `last_trigger` INT NULL,
717 PRIMARY KEY (`id`),
718 INDEX `fk_#__acym_followup_has_list`(`list_id` ASC),
719 CONSTRAINT `fk_#__acym_followup_has_list`
720 FOREIGN KEY (`list_id`)
721 REFERENCES `#__acym_list`(`id`)
722 ON DELETE NO ACTION
723 ON UPDATE NO ACTION
724 )
725 ENGINE = InnoDB;'
726 );
727 $this->updateQuery(
728 'CREATE TABLE IF NOT EXISTS `#__acym_followup_has_mail` (
729 `mail_id` INT NOT NULL,
730 `followup_id` INT NOT NULL,
731 `delay` INT NOT NULL,
732 `delay_unit` INT NOT NULL,
733 PRIMARY KEY (`mail_id`, `followup_id`),
734 INDEX `fk_#__acym_mail_has_followup1`(`followup_id` ASC),
735 INDEX `fk_#__acym_mail_has_followup2`(`mail_id` ASC),
736 CONSTRAINT `fk_#__acym_mail_has_followup1`
737 FOREIGN KEY (`mail_id`)
738 REFERENCES `#__acym_mail`(`id`)
739 ON DELETE NO ACTION
740 ON UPDATE NO ACTION,
741 CONSTRAINT `fk_#__acym_mail_has_followup2`
742 FOREIGN KEY (`followup_id`)
743 REFERENCES `#__acym_followup`(`id`)
744 ON DELETE NO ACTION
745 ON UPDATE NO ACTION
746 )
747 ENGINE = InnoDB;'
748 );
749
750 $this->updateQuery('ALTER TABLE `#__acym_list` ADD `type` VARCHAR(20) NOT NULL DEFAULT '.acym_escapeDB(ListClass::LIST_TYPE_STANDARD));
751 $this->updateQuery('UPDATE `#__acym_list` SET `type` = '.acym_escapeDB(ListClass::LIST_TYPE_FRONT).' WHERE `front_management` = 1');
752 $this->updateQuery('ALTER TABLE `#__acym_list` DROP COLUMN front_management');
753
754 $this->updateQuery(
755 'CREATE TABLE IF NOT EXISTS `#__acym_mail_override` (
756 `id` INT NOT NULL AUTO_INCREMENT,
757 `mail_id` INT NOT NULL,
758 `description` VARCHAR(255) NOT NULL,
759 `source` VARCHAR (20) NOT NULL,
760 `active` TINYINT(1) NOT NULL DEFAULT 1,
761 `base_subject` TEXT NOT NULL,
762 `base_body` TEXT NOT NULL,
763 PRIMARY KEY(`id`),
764 CONSTRAINT `fk_#__acym_mail_override1`
765 FOREIGN KEY (`mail_id`)
766 REFERENCES `#__acym_mail`(`id`)
767 ON DELETE NO ACTION
768 ON UPDATE NO ACTION
769 )
770 ENGINE = InnoDB;'
771 );
772 }
773
774 private function updateFor6181(): void
775 {
776 if ($this->isPreviousVersionAtLeast('6.18.1')) {
777 return;
778 }
779
780 $mailClass = new MailClass();
781 $emails = acym_loadObjectList('SELECT id, access FROM `#__acym_mail` WHERE access LIKE "%,,%" OR access LIKE "%[\"%"');
782
783 foreach ($emails as $email) {
784 if (strpos($email->access, ',,') !== false) {
785 $access = explode(',', $email->access);
786 } else {
787 $access = json_decode(trim($email->access, ','));
788 }
789 $finalAccess = [];
790 foreach ($access as $oneAccess) {
791 if (!empty($oneAccess)) {
792 $finalAccess[] = $oneAccess;
793 }
794 }
795 $email->access = empty($finalAccess) ? '' : $finalAccess;
796 $mailClass->save($email);
797 }
798 }
799
800 private function updateFor6190(): void
801 {
802 if ($this->isPreviousVersionAtLeast('6.19.0')) {
803 return;
804 }
805
806 $this->updateQuery('ALTER TABLE `#__acym_mail_stat` ADD `unsubscribe_total` INT NOT NULL DEFAULT 0');
807 $this->updateQuery('ALTER TABLE `#__acym_user_stat` ADD `unsubscribe` INT NOT NULL DEFAULT 0');
808 $this->updateQuery('ALTER TABLE `#__acym_user_stat` ADD `device` VARCHAR(50) NULL');
809 $this->updateQuery('ALTER TABLE `#__acym_user_stat` ADD `opened_with` VARCHAR(50) NULL');
810
811 $this->updateQuery('ALTER TABLE `#__acym_mail` CHANGE `media_folder` `mail_settings` TEXT NULL');
812 $templatesMediaFolders = acym_loadObjectList('SELECT `id`, `mail_settings` FROM `#__acym_mail` WHERE `mail_settings` IS NOT NULL');
813 if (!empty($templatesMediaFolders)) {
814 foreach ($templatesMediaFolders as $oneTemplate) {
815 $settings = [
816 'media_folder' => $oneTemplate->mail_settings,
817 ];
818 $this->updateQuery('UPDATE `#__acym_mail` SET `mail_settings` = '.acym_escapeDB(json_encode($settings)).' WHERE `id` = '.intval($oneTemplate->id));
819 }
820 }
821 }
822 }
823