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

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

233 lines 11.1 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 $acymailerParams = $config->get('acymailer_domains', '[]');
71 $acymailerParams = @json_decode($acymailerParams, true);
72 if (!empty($acymailerParams)) {
73 foreach ($acymailerParams as $domain => $domainParams) {
74 $acymailerParams[$domain]['domain'] = acym_strtolower($domainParams['domain']);
75 if (acym_strtolower($domain) === $domain) {
76 continue;
77 }
78
79 $acymailerParams[acym_strtolower($domain)] = $acymailerParams[$domain];
80 unset($acymailerParams[$domain]);
81 }
82 $config->saveConfig(['acymailer_domains' => json_encode($acymailerParams)]);
83 }
84
85 $this->updateQuery('ALTER TABLE `#__acym_field` DROP COLUMN `access`');
86 }
87
88 private function updateFor961(): void
89 {
90 if ($this->isPreviousVersionAtLeast('9.6.1')) {
91 return;
92 }
93
94 $this->updateQuery('ALTER TABLE `#__acym_mail` ADD INDEX `#__index_acym_mail2` (`type`)');
95 }
96
97 private function updateFor970(): void
98 {
99 if ($this->isPreviousVersionAtLeast('9.7.0')) {
100 return;
101 }
102
103 $this->updateQuery('ALTER TABLE `#__acym_user` ADD INDEX `#__index_acym_user1` (`cms_id`)');
104 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop` TINYINT(1) NOT NULL DEFAULT 0');
105 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop_delay` INT NULL');
106 $this->updateQuery('ALTER TABLE #__acym_followup ADD COLUMN `loop_mail_skip` VARCHAR(255) NULL');
107 }
108
109 private function updateFor980(): void
110 {
111 if ($this->isPreviousVersionAtLeast('9.8.0')) {
112 return;
113 }
114
115 $this->updateQuery('UPDATE #__acym_plugin SET `type` = "CORE" WHERE `type` = "ADDON" AND `folder_name` = "contact"');
116 $this->updateQuery('ALTER TABLE #__acym_mail ADD COLUMN `bounce_email` VARCHAR(100) NULL');
117 }
118
119 private function updateFor990(): void
120 {
121 if ($this->isPreviousVersionAtLeast('9.9.0')) {
122 return;
123 }
124
125 $this->updateQuery(
126 'UPDATE #__acym_mail
127 SET `body` = REPLACE(`body`, "images/poweredby_", "images/editor/poweredby_")
128 WHERE `body` LIKE "%images/poweredby_%"'
129 );
130
131 $this->updateQuery(
132 'UPDATE #__acym_mail_archive
133 SET `body` = REPLACE(`body`, "images/poweredby_", "images/editor/poweredby_")
134 WHERE `body` LIKE "%images/poweredby_%"'
135 );
136 }
137
138 private function updateFor9101(): void
139 {
140 if ($this->isPreviousVersionAtLeast('9.10.1')) {
141 return;
142 }
143
144 $this->updateQuery('ALTER TABLE #__acym_user DROP INDEX `email_UNIQUE`');
145 $this->updateQuery('ALTER TABLE #__acym_configuration CHANGE `name` `name` VARCHAR(190) NOT NULL');
146
147 $this->updateQuery('ALTER TABLE #__acym_mail_archive CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
148 $this->updateQuery('ALTER TABLE #__acym_mailbox_action CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
149 $this->updateQuery('ALTER TABLE #__acym_custom_zone CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
150 $this->updateQuery('ALTER TABLE #__acym_mail_override CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
151 $this->updateQuery('ALTER TABLE #__acym_followup_has_mail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
152 $this->updateQuery('ALTER TABLE #__acym_followup CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
153 $this->updateQuery('ALTER TABLE #__acym_segment CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
154 $this->updateQuery('ALTER TABLE #__acym_form CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
155 $this->updateQuery('ALTER TABLE #__acym_plugin CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
156 $this->updateQuery('ALTER TABLE #__acym_action CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
157 $this->updateQuery('ALTER TABLE #__acym_condition CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
158 $this->updateQuery('ALTER TABLE #__acym_history CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
159 $this->updateQuery('ALTER TABLE #__acym_rule CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
160 $this->updateQuery('ALTER TABLE #__acym_user_has_field CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
161 $this->updateQuery('ALTER TABLE #__acym_field CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
162 $this->updateQuery('ALTER TABLE #__acym_url_click CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
163 $this->updateQuery('ALTER TABLE #__acym_url CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
164 $this->updateQuery('ALTER TABLE #__acym_user_stat CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
165 $this->updateQuery('ALTER TABLE #__acym_mail_stat CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
166 $this->updateQuery('ALTER TABLE #__acym_queue CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
167 $this->updateQuery('ALTER TABLE #__acym_mail_has_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
168 $this->updateQuery('ALTER TABLE #__acym_tag CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
169 $this->updateQuery('ALTER TABLE #__acym_step CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
170 $this->updateQuery('ALTER TABLE #__acym_automation CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
171 $this->updateQuery('ALTER TABLE #__acym_user_has_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
172 $this->updateQuery('ALTER TABLE #__acym_campaign CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
173 $this->updateQuery('ALTER TABLE #__acym_list CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
174 $this->updateQuery('ALTER TABLE #__acym_mail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
175 $this->updateQuery('ALTER TABLE #__acym_configuration CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
176 $this->updateQuery('ALTER TABLE #__acym_user CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
177
178 $this->updateQuery('TRUNCATE TABLE #__acym_mail_archive');
179 }
180
181 private function updateFor9102(): void
182 {
183 if ($this->isPreviousVersionAtLeast('9.10.2')) {
184 return;
185 }
186
187 $duplicatedUsers = acym_loadObjectList(
188 'SELECT GROUP_CONCAT(`id` ORDER BY `creation_date` SEPARATOR "-") AS `concatenated_ids`, COUNT(*) AS `nb_duplicates`
189 FROM #__acym_user
190 GROUP BY `email`
191 HAVING `nb_duplicates` > 1'
192 );
193
194 if (!empty($duplicatedUsers)) {
195 $userIdsToDelete = [];
196
197 foreach ($duplicatedUsers as $duplicatedUser) {
198 $ids = explode('-', $duplicatedUser->concatenated_ids);
199 $userIdsToDelete = array_merge($userIdsToDelete, array_slice($ids, 1));
200 }
201
202 acym_arrayToInteger($userIdsToDelete);
203 $idsToDelete = implode(',', $userIdsToDelete);
204
205 $this->updateQuery('DELETE FROM #__acym_user_has_list WHERE user_id IN ('.$idsToDelete.')');
206 $this->updateQuery('DELETE FROM #__acym_queue WHERE user_id IN ('.$idsToDelete.')');
207 $this->updateQuery('DELETE FROM #__acym_user_has_field WHERE user_id IN ('.$idsToDelete.')');
208 $this->updateQuery('DELETE FROM #__acym_history WHERE user_id IN ('.$idsToDelete.')');
209 $this->updateQuery('DELETE FROM #__acym_user_stat WHERE user_id IN ('.$idsToDelete.')');
210 $this->updateQuery('DELETE FROM #__acym_user WHERE id IN ('.$idsToDelete.')');
211 }
212
213 $this->updateQuery('ALTER TABLE #__acym_user ADD UNIQUE INDEX `email_UNIQUE` (`email`(191) ASC)');
214 }
215
216 private function updateFor9110(): void
217 {
218 if ($this->isPreviousVersionAtLeast('9.11.0')) {
219 return;
220 }
221
222 $templateThumbnails = acym_loadResultArray('SELECT `thumbnail` FROM #__acym_mail WHERE `thumbnail` IS NOT NULL');
223 if (!empty($templateThumbnails)) {
224 $generatedThumbnails = acym_getFiles(ACYM_UPLOAD_FOLDER_THUMBNAIL, 'thumbnail_.*');
225 foreach ($generatedThumbnails as $generatedThumbnail) {
226 if (!in_array($generatedThumbnail, $templateThumbnails)) {
227 acym_deleteFile(ACYM_UPLOAD_FOLDER_THUMBNAIL.$generatedThumbnail);
228 }
229 }
230 }
231 }
232 }
233