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

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

467 lines 16.8 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\AutomationClass;
7 use AcyMailing\Classes\CampaignClass;
8 use AcyMailing\Classes\ConditionClass;
9 use AcyMailing\Classes\ConfigurationClass;
10 use AcyMailing\Classes\FieldClass;
11 use AcyMailing\Classes\FormClass;
12 use AcyMailing\Classes\MailClass;
13 use AcyMailing\Classes\MailStatClass;
14 use AcyMailing\Classes\RuleClass;
15 use AcyMailing\Classes\SegmentClass;
16 use AcyMailing\Controllers\ConfigurationController;
17
18 trait Patchv7
19 {
20 private function updateFor700(ConfigurationClass $config): void
21 {
22 if ($this->isPreviousVersionAtLeast('7.0.0')) {
23 return;
24 }
25
26 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
27 $socialMedias = acym_getSocialMedias();
28 foreach ($socialIcons as $oneSocial => $imagePath) {
29 if (!in_array($oneSocial, $socialMedias)) {
30 unset($socialIcons[$oneSocial]);
31 }
32 }
33
34 $config->saveConfig(['social_icons' => json_encode($socialIcons)]);
35
36 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `redirection_options` TEXT');
37 $formClass = new FormClass();
38 $forms = $formClass->getAll();
39 if (!empty($forms)) {
40 foreach ($forms as $oneForm) {
41 $oneForm->redirection_options = json_encode(['after_subscription' => '', 'confirmation_message' => '']);
42 $formClass->save($oneForm);
43 }
44 }
45
46 if (!empty($config->get('active_cron', 0))) {
47 $licenseKey = $config->get('license_key', '');
48 if (!empty($licenseKey)) {
49 $configurationController = new ConfigurationController();
50 $configurationController->modifyCron('activateCron', $licenseKey);
51 }
52 }
53
54 $segmentClass = new SegmentClass();
55 $segmentClass->updateSegments();
56 }
57
58 private function updateFor710(): void
59 {
60 if ($this->isPreviousVersionAtLeast('7.1.0')) {
61 return;
62 }
63
64 // Welcome and unsubscribe emails have template = 1 for some reason
65 $this->updateQuery(
66 'UPDATE #__acym_mail
67 SET `type` = '.acym_escapeDB(MailClass::TYPE_TEMPLATE).'
68 WHERE `template` = 1
69 AND `type` = '.acym_escapeDB(MailClass::TYPE_STANDARD)
70 );
71
72 $this->updateQuery('ALTER TABLE #__acym_mail DROP `template`');
73
74 $fieldClass = new FieldClass();
75 $fieldClass->insertLanguageField();
76 }
77
78 private function updateFor720(ConfigurationClass $config): void
79 {
80 if ($this->isPreviousVersionAtLeast('7.2.0')) {
81 return;
82 }
83
84 $config->saveConfig(['built_by_update' => 1]);
85 $config->saveConfig(['display_built_by' => 0]);
86 $this->updateQuery('ALTER TABLE #__acym_user CHANGE `language` `language` VARCHAR(20) NOT NULL DEFAULT ""');
87 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `language` `language` VARCHAR(20) NOT NULL DEFAULT ""');
88 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `links_language` `links_language` VARCHAR(20) NOT NULL DEFAULT ""');
89
90 $this->updateQuery('ALTER TABLE #__acym_list ADD `translation` LONGTEXT NULL');
91 $this->updateQuery('ALTER TABLE #__acym_field ADD `translation` LONGTEXT NULL');
92 $this->updateQuery('ALTER TABLE #__acym_mail ADD `translation` TEXT NULL');
93 }
94
95 private function updateFor721(): void
96 {
97 if ($this->isPreviousVersionAtLeast('7.2.1')) {
98 return;
99 }
100
101 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `translation` `translation` TEXT NULL');
102 }
103
104 private function updateFor740(ConfigurationClass $config): void
105 {
106 if ($this->isPreviousVersionAtLeast('7.4.0')) {
107 return;
108 }
109
110 $actionClass = new ActionClass();
111 $actions = $actionClass->getAll();
112 foreach ($actions as $action) {
113 if (strpos($action->filters, 'hikareminder')) {
114 $action->filters = preg_replace_callback(
115 '/"hikareminder":{"days":"(\d+)"/',
116 [$this, 'replaceHikaReminder'],
117 $action->filters
118 );
119 $actionClass->save($action);
120 }
121 }
122
123 $conditionClass = new ConditionClass();
124 $conditions = $conditionClass->getAll();
125 foreach ($conditions as $condition) {
126 if (strpos($condition->conditions, 'hikareminder')) {
127 $condition->conditions = preg_replace_callback(
128 '/"hikareminder":{"days":"(\d+)"/',
129 [$this, 'replaceHikaReminder'],
130 $condition->conditions
131 );
132 $conditionClass->save($condition);
133 }
134 }
135
136 $segmentClass = new SegmentClass();
137 $segments = $segmentClass->getAll();
138 foreach ($segments as $segment) {
139 if (strpos($segment->filters, 'hikareminder')) {
140 $segment->filters = preg_replace_callback(
141 '/"hikareminder":{"days":"(\d+)"/',
142 [$this, 'replaceHikaReminder'],
143 $segment->filters
144 );
145 $segmentClass->save($segment);
146 }
147 }
148
149 $campaignClass = new CampaignClass();
150 $campaigns = $campaignClass->getAll();
151 foreach ($campaigns as $campaign) {
152 $campaign->sending_params = json_encode($campaign->sending_params);
153 if (strpos($campaign->sending_params, 'hikareminder')) {
154 $campaign->sending_params = preg_replace_callback(
155 '/"hikareminder":{"days":"(\d+)"/',
156 [$this, 'replaceHikaReminder'],
157 $campaign->sending_params
158 );
159 $campaign->sending_params = json_decode($campaign->sending_params);
160 $campaignClass->save($campaign);
161 }
162 }
163
164 $rule = new \stdClass();
165 $rule->name = 'ACYM_LIST_UNSUBSCRIBE_HANDLING';
166 $rule->ordering = 1;
167 $rule->regex = 'Please unsubscribe user ID \\d+';
168 $rule->executed_on = '["body"]';
169 $rule->action_message = '["delete_message"]';
170 $rule->action_user = '["unsubscribe_user"]';
171 $rule->active = 1;
172 $rule->increment_stats = 0;
173 $rule->execute_action_after = 0;
174
175 $ruleClass = new RuleClass();
176 $ruleClass->save($rule);
177
178 $captchaOption = $config->get('captcha', 0);
179 $config->saveConfig([
180 'captcha' => intval($captchaOption) === 1 ? 'acym_ireCaptcha' : 'none',
181 ]);
182
183 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `from_name` `from_name` VARCHAR(100) NULL');
184 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `from_email` `from_email` VARCHAR(100) NULL');
185 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `reply_to_name` `reply_to_name` VARCHAR(100) NULL');
186 $this->updateQuery('ALTER TABLE #__acym_mail CHANGE `reply_to_email` `reply_to_email` VARCHAR(100) NULL');
187 }
188
189 private function updateFor750(ConfigurationClass $config): void
190 {
191 if ($this->isPreviousVersionAtLeast('7.5.0')) {
192 return;
193 }
194
195 $languageFieldId = $config->get(FieldClass::LANGUAGE_FIELD_ID_KEY, 0);
196 if (!empty($languageFieldId)) {
197 $this->updateQuery('UPDATE `#__acym_field` SET `namekey` = "acym_language" WHERE `id` = '.intval($languageFieldId));
198 }
199
200 $news = $config->get('last_news', '');
201 if (!empty($news)) {
202 $config->saveConfig(
203 [
204 'last_news' => base64_encode($news),
205 ],
206 false
207 );
208 }
209
210 $this->updateQuery('ALTER TABLE `#__acym_user_has_list` ADD INDEX `index_#__acym_user_has_list3` (`subscription_date` ASC)');
211 $this->updateQuery('ALTER TABLE `#__acym_user_has_list` ADD INDEX `index_#__acym_user_has_list4` (`unsubscribe_date` ASC)');
212 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD `tracking_sale` FLOAT NULL');
213 $this->updateQuery('ALTER TABLE #__acym_mail_stat ADD `currency` VARCHAR(5) NULL');
214
215 $mailStatsClass = new MailStatClass();
216 $mailStatsClass->migrateTrackingSale();
217 }
218
219 private function updateFor755(): void
220 {
221 if ($this->isPreviousVersionAtLeast('7.5.5')) {
222 return;
223 }
224
225 $actionClass = new ActionClass();
226 $automationClass = new AutomationClass();
227 $adminAutomations = $automationClass->getAutomationsAdmin();
228
229 if (empty($adminAutomations)) {
230 return;
231 }
232
233 $mailClass = new MailClass();
234 foreach ($adminAutomations as $oneAutomation) {
235 $actions = $actionClass->getActionsByAutomationId($oneAutomation->id);
236 foreach ($actions as $oneAction) {
237 $oneAction->actions = json_decode($oneAction->actions, true);
238 foreach ($oneAction->actions as $action) {
239 if (empty($action['acy_add_queue']['mail_id'])) continue;
240
241 $mail = $mailClass->getOneById($action['acy_add_queue']['mail_id']);
242 $mail->body = str_replace('{subtag:', '{subscriber:', $mail->body);
243
244 $mailClass->save($mail);
245 }
246 }
247 }
248 }
249
250 private function updateFor759(): void
251 {
252 if ($this->isPreviousVersionAtLeast('7.5.9')) {
253 return;
254 }
255
256 $fieldClass = new FieldClass();
257 $fields = $fieldClass->getAll();
258 foreach ($fields as $field) {
259 if (empty($field->option)) continue;
260
261 $field->option = json_decode($field->option, true);
262 $options = array_keys($field->option);
263 if (in_array('editable_user_creation', $options) || in_array('editable_user_modification', $options)) {
264 unset($field->option['editable_user_creation']);
265 unset($field->option['editable_user_modification']);
266
267 $field->option = json_encode($field->option);
268 $fieldClass->save($field);
269 }
270 }
271 }
272
273 private function updateFor7510(): void
274 {
275 if ($this->isPreviousVersionAtLeast('7.5.10') || ACYM_CMS !== 'joomla') {
276 return;
277 }
278
279 $dynamicsToDelete = [
280 'gravityforms',
281 'page',
282 'post',
283 'theeventscalendar',
284 'ultimatemember',
285 'woocommerce',
286 'jomsocial',
287 ];
288
289 foreach ($dynamicsToDelete as $dynamicFolder) {
290 if (file_exists(ACYM_BACK.'dynamics'.DS.$dynamicFolder)) {
291 acym_deleteFolder(ACYM_BACK.'dynamics'.DS.$dynamicFolder);
292 }
293 }
294 }
295
296 private function updateFor760(): void
297 {
298 if ($this->isPreviousVersionAtLeast('7.6.0')) {
299 return;
300 }
301
302 $this->updateQuery('ALTER TABLE #__acym_user CHANGE `key` `key` VARCHAR(30) NULL');
303 $this->updateQuery('ALTER TABLE #__acym_mail DROP `library`');
304 $this->updateQuery('ALTER TABLE #__acym_user_has_list ADD `unsubscribe_reason` TEXT NULL');
305 }
306
307 private function updateFor761(): void
308 {
309 if ($this->isPreviousVersionAtLeast('7.6.1')) {
310 return;
311 }
312
313 $this->updateQuery('ALTER TABLE #__acym_user_has_list DROP COLUMN `unsubscribe_reason`');
314 $this->updateQuery('ALTER TABLE #__acym_history ADD `unsubscribe_reason` TEXT NULL');
315
316 $fieldClass = new FieldClass();
317 $dateCustomFields = $fieldClass->getFieldsByType(['date']);
318
319 // Convert the already saved data into the new format
320 foreach ($dateCustomFields as $oneField) {
321 $oneField->option = json_decode($oneField->option);
322
323 $formatToDisplay = explode('%', $oneField->option->format);
324 unset($formatToDisplay[0]);
325
326 $values = $fieldClass->getFieldsValueByFieldId($oneField->id);
327 foreach ($values as $oneValue) {
328 $userDate = explode('/', $oneValue->value);
329 $year = '0000';
330 $month = '00';
331 $day = '00';
332 $i = 0;
333 foreach ($formatToDisplay as $one) {
334 // This is a value stored when the format was "%m%y" for example and the format changed to something else
335 if (!isset($userDate[$i])) continue 2;
336
337 if ($one === 'd') {
338 $day = $userDate[$i];
339 }
340 if ($one === 'm') {
341 $month = $userDate[$i];
342 }
343 if ($one === 'y') {
344 $year = $userDate[$i];
345 }
346 $i++;
347 }
348
349 acym_query(
350 'UPDATE #__acym_user_has_field
351 SET `value` = '.acym_escapeDB($year.'-'.$month.'-'.$day).'
352 WHERE `field_id` = '.intval($oneValue->field_id).' AND `user_id` = '.intval($oneValue->user_id)
353 );
354 }
355 }
356
357 $this->updateQuery('ALTER TABLE #__acym_user CHANGE `automation` `automation` VARCHAR(50) NOT NULL DEFAULT ""');
358 }
359
360 private function updateFor762(): void
361 {
362 if ($this->isPreviousVersionAtLeast('7.6.2')) {
363 return;
364 }
365
366 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `message_options` TEXT');
367 $this->updateQuery('ALTER TABLE `#__acym_history` CHANGE `ip` `ip` VARCHAR(50)');
368 $this->updateQuery('ALTER TABLE `#__acym_user` CHANGE `confirmation_ip` `confirmation_ip` VARCHAR(50)');
369 }
370
371 private function updateFor776(): void
372 {
373 if ($this->isPreviousVersionAtLeast('7.7.6')) {
374 return;
375 }
376
377 $this->updateQuery('ALTER TABLE `#__acym_list` ADD `display_name` VARCHAR(255) NULL');
378 }
379
380 private function updateFor781(): void
381 {
382 if ($this->isPreviousVersionAtLeast('7.8.1')) {
383 return;
384 }
385
386 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `display_options` TEXT');
387 $popupDelays = acym_loadObjectList('SELECT id, delay FROM #__acym_form WHERE `type` = "popup"', 'id');
388 if (!empty($popupDelays)) {
389 foreach ($popupDelays as $formId => $formDelay) {
390 $newData = json_encode(['delay' => (int)$formDelay->delay, 'scroll' => 0]);
391 $this->updateQuery('UPDATE `#__acym_form` SET display_options = '.acym_escapeDB($newData).' WHERE id = '.(int)$formId);
392 }
393 }
394 $this->updateQuery('ALTER TABLE `#__acym_form` DROP `delay`');
395
396 $this->updateQuery(
397 'CREATE TABLE IF NOT EXISTS `#__acym_custom_zone` (
398 `id` INT NOT NULL AUTO_INCREMENT,
399 `name` VARCHAR(255) NOT NULL,
400 `content` TEXT NOT NULL,
401 PRIMARY KEY (`id`)
402 )'
403 );
404 }
405
406 private function updateFor792(): void
407 {
408 if ($this->isPreviousVersionAtLeast('7.9.2')) {
409 return;
410 }
411
412 $zones = acym_loadObjectList('SELECT `id`, `content` FROM #__acym_custom_zone');
413 if (!empty($zones)) {
414 foreach ($zones as $oneZone) {
415 $oneZone->content = base64_encode(acym_utf8Decode($oneZone->content));
416 $this->updateQuery('UPDATE `#__acym_custom_zone` SET `content` = '.acym_escapeDB($oneZone->content).' WHERE `id` = '.intval($oneZone->id));
417 }
418 }
419 }
420
421 private function updateFor793(): void
422 {
423 if ($this->isPreviousVersionAtLeast('7.9.3')) {
424 return;
425 }
426
427 $automationClass = new AutomationClass();
428 $automations = $automationClass->getAll();
429 if (!empty($automations)) {
430 foreach ($automations as $oneAutomation) {
431 $translated = acym_translation($oneAutomation->name);
432 if ($translated === $oneAutomation->name) continue;
433
434 $oneAutomation->name = $translated;
435 $oneAutomation->description = acym_translation($oneAutomation->description);
436 $automationClass->save($oneAutomation);
437 }
438 }
439 }
440
441 private function updateFor794(): void
442 {
443 if ($this->isPreviousVersionAtLeast('7.9.4')) {
444 return;
445 }
446
447 $this->updateQuery('ALTER TABLE `#__acym_custom_zone` ADD `image` VARCHAR(255) NULL');
448 }
449
450 private function updateFor796(): void
451 {
452 if ($this->isPreviousVersionAtLeast('7.9.6') || !file_exists(ACYM_ADDONS_FOLDER_PATH.'couryeah')) {
453 return;
454 }
455
456 acym_deleteFile(ACYM_ADDONS_FOLDER_PATH.'couryeah');
457 $this->updateQuery('UPDATE #__acym_configuration SET `name` = "acymailer_domains" WHERE `name` = "couryeah_domains"');
458 }
459
460 private function replaceHikaReminder(array $matches): string
461 {
462 $val = (int)$matches[1] * 86400;
463
464 return '"hikareminder":{"days":"'.$val.'"';
465 }
466 }
467