PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.1
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.0.1, at back/Helpers/Update/Patchv6.php

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