PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.3
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.3
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 / Patchv9.php

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

235 lines 11.3 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\UrlClickClass;
7
8 trait Patchv9
9 {
10 private function updateFor920(ConfigurationClass $config): void
11 {
12 if ($this->isPreviousVersionAtLeast('9.2.0')) {
13 return;
14 }
15
16 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
17 if (empty($socialIcons['telegram'])) {
18 $socialIcons['telegram'] = ACYM_IMAGES.'logo/telegram.png';
19
20 $config->saveConfig(['social_icons' => json_encode($socialIcons)]);
21 }
22
23 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD COLUMN `click_unique` INT NOT NULL DEFAULT 0');
24 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD COLUMN `click_total` INT NOT NULL DEFAULT 0');
25
26 $urlClickClass = new UrlClickClass();
27 $mailClicks = $urlClickClass->getTotalClicksPerMail();
28 if (!empty($mailClicks)) {
29 foreach ($mailClicks as $mailId => $stats) {
30 $this->updateQuery(
31 'UPDATE #__acym_mail_stat
32 SET click_unique = '.intval($stats->unique_clicks).', click_total = '.intval($stats->total_clicks).'
33 WHERE mail_id = '.intval($mailId)
34 );
35 }
36 }
37 }
38
39 private function updateFor930(): void
40 {
41 if ($this->isPreviousVersionAtLeast('9.3.0')) {
42 return;
43 }
44
45 $this->updateQuery('ALTER TABLE #__acym_rule ADD COLUMN `description` VARCHAR(250) NULL AFTER `name`');
46 }
47
48 private function updateFor931(): void
49 {
50 if ($this->isPreviousVersionAtLeast('9.3.1')) {
51 return;
52 }
53
54 $maxOrdering = acym_loadResult('SELECT MAX(ordering) FROM #__acym_rule');
55 $this->updateQuery('UPDATE #__acym_rule SET `ordering` = '.intval($maxOrdering + 1).' WHERE `id` = 17');
56 }
57
58 private function updateFor940(ConfigurationClass $config): void
59 {
60 if ($this->isPreviousVersionAtLeast('9.4.0')) {
61 return;
62 }
63
64 $config->saveConfig([
65 'from_email' => acym_strtolower($config->get('from_email')),
66 'replyto_email' => acym_strtolower($config->get('replyto_email')),
67 'bounce_email' => acym_strtolower($config->get('bounce_email')),
68 ]);
69
70 // Make sure that all domains in AcyMailer configuration are in lower cases
71 $acymailerParams = $config->get('acymailer_domains', '[]');
72 $acymailerParams = @json_decode($acymailerParams, true);
73 if (!empty($acymailerParams)) {
74 foreach ($acymailerParams as $domain => $domainParams) {
75 $acymailerParams[$domain]['domain'] = acym_strtolower($domainParams['domain']);
76 if (acym_strtolower($domain) === $domain) {
77 continue;
78 }
79
80 $acymailerParams[acym_strtolower($domain)] = $acymailerParams[$domain];
81 unset($acymailerParams[$domain]);
82 }
83 $config->saveConfig(['acymailer_domains' => json_encode($acymailerParams)]);
84 }
85
86 $this->updateQuery('ALTER TABLE `#__acym_field` DROP COLUMN `access`');
87 }
88
89 private function updateFor961(): void
90 {
91 if ($this->isPreviousVersionAtLeast('9.6.1')) {
92 return;
93 }
94
95 $this->updateQuery('ALTER TABLE `#__acym_mail` ADD INDEX `#__index_acym_mail2` (`type`)');
96 }
97
98 private function updateFor970(): void
99 {
100 if ($this->isPreviousVersionAtLeast('9.7.0')) {
101 return;
102 }
103
104 $this->updateQuery('ALTER TABLE `#__acym_user` ADD INDEX `#__index_acym_user1` (`cms_id`)');
105 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop` TINYINT(1) NOT NULL DEFAULT 0');
106 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop_delay` INT NULL');
107 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop_mail_skip` VARCHAR(255) NULL');
108 }
109
110 private function updateFor980(): void
111 {
112 if ($this->isPreviousVersionAtLeast('9.8.0')) {
113 return;
114 }
115
116 $this->updateQuery('UPDATE #__acym_plugin SET `type` = "CORE" WHERE `type` = "ADDON" AND `folder_name` = "contact"');
117 $this->updateQuery('ALTER TABLE #__acym_mail ADD COLUMN `bounce_email` VARCHAR(100) NULL');
118 }
119
120 private function updateFor990(): void
121 {
122 if ($this->isPreviousVersionAtLeast('9.9.0')) {
123 return;
124 }
125
126 $this->updateQuery(
127 'UPDATE #__acym_mail
128 SET `body` = REPLACE(`body`, "images/poweredby_", "images/editor/poweredby_")
129 WHERE `body` LIKE "%images/poweredby_%"'
130 );
131
132 $this->updateQuery(
133 'UPDATE #__acym_mail_archive
134 SET `body` = REPLACE(`body`, "images/poweredby_", "images/editor/poweredby_")
135 WHERE `body` LIKE "%images/poweredby_%"'
136 );
137 }
138
139 private function updateFor9101(): void
140 {
141 if ($this->isPreviousVersionAtLeast('9.10.1')) {
142 return;
143 }
144
145 // On some servers, there is a limit of 767 bytes for the index length, which corresponds to VARCHAR(191)
146 $this->updateQuery('ALTER TABLE #__acym_user DROP INDEX `email_UNIQUE`');
147 $this->updateQuery('ALTER TABLE #__acym_configuration CHANGE `name` `name` VARCHAR(190) NOT NULL');
148
149 $this->updateQuery('ALTER TABLE #__acym_mail_archive CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
150 $this->updateQuery('ALTER TABLE #__acym_mailbox_action CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
151 $this->updateQuery('ALTER TABLE #__acym_custom_zone CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
152 $this->updateQuery('ALTER TABLE #__acym_mail_override CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
153 $this->updateQuery('ALTER TABLE #__acym_followup_has_mail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
154 $this->updateQuery('ALTER TABLE #__acym_followup CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
155 $this->updateQuery('ALTER TABLE #__acym_segment CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
156 $this->updateQuery('ALTER TABLE #__acym_form CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
157 $this->updateQuery('ALTER TABLE #__acym_plugin CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
158 $this->updateQuery('ALTER TABLE #__acym_action CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
159 $this->updateQuery('ALTER TABLE #__acym_condition CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
160 $this->updateQuery('ALTER TABLE #__acym_history CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
161 $this->updateQuery('ALTER TABLE #__acym_rule CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
162 $this->updateQuery('ALTER TABLE #__acym_user_has_field CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
163 $this->updateQuery('ALTER TABLE #__acym_field CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
164 $this->updateQuery('ALTER TABLE #__acym_url_click CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
165 $this->updateQuery('ALTER TABLE #__acym_url CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
166 $this->updateQuery('ALTER TABLE #__acym_user_stat CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
167 $this->updateQuery('ALTER TABLE #__acym_mail_stat CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
168 $this->updateQuery('ALTER TABLE #__acym_queue CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
169 $this->updateQuery('ALTER TABLE #__acym_mail_has_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
170 $this->updateQuery('ALTER TABLE #__acym_tag CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
171 $this->updateQuery('ALTER TABLE #__acym_step CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
172 $this->updateQuery('ALTER TABLE #__acym_automation CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
173 $this->updateQuery('ALTER TABLE #__acym_user_has_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
174 $this->updateQuery('ALTER TABLE #__acym_campaign CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
175 $this->updateQuery('ALTER TABLE #__acym_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
176 $this->updateQuery('ALTER TABLE #__acym_mail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
177 $this->updateQuery('ALTER TABLE #__acym_configuration CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
178 $this->updateQuery('ALTER TABLE #__acym_user CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
179
180 $this->updateQuery('TRUNCATE TABLE #__acym_mail_archive');
181 }
182
183 private function updateFor9102(): void
184 {
185 if ($this->isPreviousVersionAtLeast('9.10.2')) {
186 return;
187 }
188
189 $duplicatedUsers = acym_loadObjectList(
190 'SELECT GROUP_CONCAT(`id` ORDER BY `creation_date` SEPARATOR "-") AS `concatenated_ids`, COUNT(*) AS `nb_duplicates`
191 FROM #__acym_user
192 GROUP BY `email`
193 HAVING `nb_duplicates` > 1'
194 );
195
196 if (!empty($duplicatedUsers)) {
197 $userIdsToDelete = [];
198
199 foreach ($duplicatedUsers as $duplicatedUser) {
200 $ids = explode('-', $duplicatedUser->concatenated_ids);
201 $userIdsToDelete = array_merge($userIdsToDelete, array_slice($ids, 1));
202 }
203
204 acym_arrayToInteger($userIdsToDelete);
205 $idsToDelete = implode(',', $userIdsToDelete);
206
207 $this->updateQuery('DELETE FROM #__acym_user_has_list WHERE user_id IN ('.$idsToDelete.')');
208 $this->updateQuery('DELETE FROM #__acym_queue WHERE user_id IN ('.$idsToDelete.')');
209 $this->updateQuery('DELETE FROM #__acym_user_has_field WHERE user_id IN ('.$idsToDelete.')');
210 $this->updateQuery('DELETE FROM #__acym_history WHERE user_id IN ('.$idsToDelete.')');
211 $this->updateQuery('DELETE FROM #__acym_user_stat WHERE user_id IN ('.$idsToDelete.')');
212 $this->updateQuery('DELETE FROM #__acym_user WHERE id IN ('.$idsToDelete.')');
213 }
214
215 $this->updateQuery('ALTER TABLE #__acym_user ADD UNIQUE INDEX `email_UNIQUE` (`email`(191) ASC)');
216 }
217
218 private function updateFor9110(): void
219 {
220 if ($this->isPreviousVersionAtLeast('9.11.0')) {
221 return;
222 }
223
224 $templateThumbnails = acym_loadResultArray('SELECT `thumbnail` FROM #__acym_mail WHERE `thumbnail` IS NOT NULL');
225 if (!empty($templateThumbnails)) {
226 $generatedThumbnails = acym_getFiles(ACYM_UPLOAD_FOLDER_THUMBNAIL, 'thumbnail_.*');
227 foreach ($generatedThumbnails as $generatedThumbnail) {
228 if (!in_array($generatedThumbnail, $templateThumbnails)) {
229 acym_deleteFile(ACYM_UPLOAD_FOLDER_THUMBNAIL.$generatedThumbnail);
230 }
231 }
232 }
233 }
234 }
235