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

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

379 lines 13.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\FormClass;
6 use AcyMailing\Classes\MailClass;
7 use AcyMailing\Classes\RuleClass;
8
9 trait Patchv8
10 {
11 private function updateFor800($config)
12 {
13 if ($this->isPreviousVersionAtLeast('8.0.0')) {
14 return;
15 }
16
17 $secretKey = $config->get('smtp_secret');
18 $config->save(['smtp_type' => empty($secretKey) ? 'password' : 'oauth']);
19
20 $this->updateQuery(
21 'CREATE TABLE IF NOT EXISTS `#__acym_mailbox_action` (
22 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
23 `name` varchar(255) DEFAULT NULL,
24 `frequency` int(10) UNSIGNED NOT NULL DEFAULT 0,
25 `nextdate` int(10) UNSIGNED NOT NULL DEFAULT 0,
26 `description` text DEFAULT NULL,
27 `server` varchar(255) NULL,
28 `port` varchar(50) NULL,
29 `connection_method` ENUM(\'imap\', \'pop3\', \'pear\') NULL,
30 `secure_method` ENUM(\'ssl\', \'tls\') NULL,
31 `self_signed` tinyint(4) NULL,
32 `username` varchar(255) NULL,
33 `password` varchar(50) NULL,
34 `conditions` text DEFAULT NULL,
35 `actions` text DEFAULT NULL,
36 `report` text DEFAULT NULL,
37 `delete_wrong_emails` tinyint(4) NOT NULL DEFAULT 0,
38 `senderfrom` tinyint(4) NOT NULL DEFAULT 0,
39 `senderto` tinyint(4) NOT NULL DEFAULT 0,
40 `active` tinyint(4) NOT NULL DEFAULT 0,
41 PRIMARY KEY (`id`),
42 INDEX `index_#__acym_mailbox_action1`(`name` ASC)
43 )
44 ENGINE = InnoDB;'
45 );
46 }
47
48 private function updateFor810()
49 {
50 if ($this->isPreviousVersionAtLeast('8.1.0')) {
51 return;
52 }
53
54 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `settings` TEXT');
55 $this->updateQuery('ALTER TABLE `#__acym_form` ADD `display_languages` VARCHAR(255)');
56
57 $formClass = new FormClass();
58 $forms = $formClass->getAll();
59
60 foreach ($forms as $oneForm) {
61 $oneForm->settings = [];
62 foreach ($oneForm as $key => $value) {
63 $optionsPos = strpos($key, '_options');
64 if (empty($value) || ($key !== 'cookie' && $optionsPos === false)) {
65 continue;
66 }
67
68 $category = $key === 'cookie' ? 'cookie' : substr($key, 0, $optionsPos);
69 $oneForm->settings[$category] = json_decode($value, true);
70 }
71
72 $oneForm->settings = json_encode($oneForm->settings);
73 $formClass->save($oneForm);
74 }
75
76 $this->updateQuery(
77 'ALTER TABLE `#__acym_form`
78 DROP `lists_options`,
79 DROP `fields_options`,
80 DROP `style_options`,
81 DROP `button_options`,
82 DROP `image_options`,
83 DROP `termspolicy_options`,
84 DROP `cookie`,
85 DROP `redirection_options`,
86 DROP `display_options`,
87 DROP `message_options`'
88 );
89
90 $this->updateQuery('ALTER TABLE `#__acym_user` CHANGE `key` `key` VARCHAR(40) NULL');
91 }
92
93 private function updateFor811()
94 {
95 if ($this->isPreviousVersionAtLeast('8.1.1')) {
96 return;
97 }
98
99 $formClass = new FormClass();
100 $forms = $formClass->getAll();
101
102 foreach ($forms as $oneForm) {
103 if (!empty($oneForm->display_languages)) {
104 continue;
105 }
106 $oneForm->display_languages = '["all"]';
107 $formClass->save($oneForm);
108 }
109 }
110
111 private function updateFor850()
112 {
113 if ($this->isPreviousVersionAtLeast('8.5.0')) {
114 return;
115 }
116
117 $aclPages = [
118 'forms',
119 'users',
120 'fields',
121 'lists',
122 'segments',
123 'campaigns',
124 'mails',
125 'override',
126 'automation',
127 'queue',
128 'plugins',
129 'bounces',
130 'stats',
131 'configuration',
132 ];
133
134 $config = acym_config();
135 $groups = array_keys(acym_getGroups());
136
137 foreach ($aclPages as $page) {
138 $aclConfig = $config->get('acl_'.$page, 'all');
139
140 if ($aclConfig === 'all') {
141 continue;
142 }
143
144 $groupsAuthorized = [];
145
146 foreach ($groups as $group) {
147 if ($config->get('acl_'.$page.'_'.$group, 1) == 1) {
148 $groupsAuthorized[] = $group;
149 }
150 }
151
152 $config->save(['acl_'.$page => implode(',', $groupsAuthorized)]);
153 }
154
155 $queries = file_get_contents(ACYM_BACK.'tables.sql');
156 $tables = explode('CREATE TABLE IF NOT EXISTS ', $queries);
157 $tableNames = [];
158 $indexes = [];
159 $constraints = [];
160
161 foreach ($tables as $oneTable) {
162 if (strpos($oneTable, '`#__') !== 0) {
163 continue;
164 }
165 $tableName = substr($oneTable, 1, strpos($oneTable, '`', 1) - 1);
166 $tableNames[] = $tableName;
167
168 $fields = explode("\n", $oneTable);
169 foreach ($fields as $key => $oneField) {
170 $oneField = rtrim(trim($oneField), ',');
171 if (strpos($oneField, 'INDEX') === 0) {
172 $firstBackquotePos = strpos($oneField, '`');
173 $indexName = substr($oneField, $firstBackquotePos + 1, strpos($oneField, '`', $firstBackquotePos + 1) - $firstBackquotePos - 1);
174
175 $indexes[$tableName][$indexName] = $oneField;
176 } elseif (strpos($oneField, 'FOREIGN KEY') !== false) {
177 preg_match('/(#__fk.*)\`/Uis', $fields[$key - 1], $matchesConstraints);
178 preg_match('/(#__.*)\`\(`(.*)`\)/Uis', $fields[$key + 1], $matchesTable);
179 preg_match('/\`(.*)\`/Uis', $oneField, $matchesColumn);
180 if (!empty($matchesConstraints) && !empty($matchesTable) && !empty($matchesColumn)) {
181 if (empty($constraints[$tableName])) $constraints[$tableName] = [];
182 $constraints[$tableName][$matchesConstraints[1]] = [
183 'table' => $matchesTable[1],
184 'column' => $matchesColumn[1],
185 'table_column' => $matchesTable[2],
186 ];
187 }
188 }
189 }
190 }
191
192 foreach ($tableNames as $tableName) {
193 if (!empty($indexes[$tableName])) {
194 foreach ($indexes[$tableName] as $newName => $query) {
195 $oldName = str_replace('#__index_', 'index_#__', $newName);
196 preg_match('#\(.*\)#U', $query, $matches);
197 try {
198 acym_query('ALTER TABLE `'.$tableName.'` DROP INDEX `'.$oldName.'`, ADD INDEX `'.$newName.'`'.$matches[0]);
199 } catch (\Exception $exception) {
200 if (function_exists('acym_logError')) {
201 acym_logError('Error while renaming index '.$oldName.', with the error '.$exception->getMessage());
202 }
203 }
204 }
205 }
206
207 if (!empty($constraints[$tableName])) {
208 acym_query('SET FOREIGN_KEY_CHECKS=0;');
209 foreach ($constraints[$tableName] as $newName => $constraintInfo) {
210 $oldName = str_replace('#__fk_', 'fk_#__', $newName);
211 $query = 'ALTER TABLE '.$tableName.' DROP FOREIGN KEY `'.$oldName.'`,ADD CONSTRAINT `'.$newName.'` FOREIGN KEY (`'.$constraintInfo['column'].'`) REFERENCES `'.$constraintInfo['table'].'` (`'.$constraintInfo['table_column'].'`) ON DELETE NO ACTION ON UPDATE NO ACTION;';
212 try {
213 acym_query($query);
214 } catch (\Exception $exception) {
215 if (function_exists('acym_logError')) {
216 acym_logError('Error while renaming foreign key '.$oldName.', with the error '.$exception->getMessage());
217 }
218 }
219 }
220 acym_query('SET FOREIGN_KEY_CHECKS=1;');
221 }
222 }
223 }
224
225 private function updateFor860()
226 {
227 if ($this->isPreviousVersionAtLeast('8.6.0')) {
228 return;
229 }
230
231 $ruleClass = new RuleClass();
232
233 $rule = new \stdClass();
234 $rule->name = 'ACYM_SUPPRESSION_LIST';
235 $rule->ordering = 2;
236 $rule->regex = 'suppression list';
237 $rule->executed_on = '["body"]';
238 $rule->action_message = '["delete_message"]';
239 $rule->action_user = '["unsubscribe_user","block_user","empty_queue_user"]';
240 $rule->active = 1;
241 $rule->increment_stats = 1;
242 $rule->execute_action_after = 0;
243 $ruleClass->save($rule);
244
245 $rule = new \stdClass();
246 $rule->name = 'ACYM_REJECTED';
247 $rule->ordering = 9;
248 $rule->regex = 'rejected *your *message|email *provider *rejected *it';
249 $rule->executed_on = '["body"]';
250 $rule->action_message = '["delete_message"]';
251 $rule->action_user = '[]';
252 $rule->active = 1;
253 $rule->increment_stats = 1;
254 $rule->execute_action_after = 0;
255 $ruleClass->save($rule);
256
257 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_sent_date` DATETIME NULL');
258 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_open_date` DATETIME NULL');
259 $this->updateQuery('ALTER TABLE #__acym_user ADD COLUMN `last_click_date` DATETIME NULL');
260
261 $this->updateQuery(
262 'CREATE TABLE IF NOT EXISTS `#__acym_mail_archive` (
263 `id` INT NOT NULL AUTO_INCREMENT,
264 `mail_id` INT NOT NULL,
265 `date` INT(10) UNSIGNED NOT NULL,
266 `body` LONGTEXT NOT NULL,
267 `subject` VARCHAR(255) NULL,
268 `settings` TEXT NULL,
269 `stylesheet` TEXT NULL,
270 `attachments` TEXT NULL,
271 PRIMARY KEY (`id`),
272 CONSTRAINT `#__fk_acym_mail_archive1`
273 FOREIGN KEY (`mail_id`)
274 REFERENCES `#__acym_mail`(`id`)
275 ON DELETE NO ACTION
276 ON UPDATE NO ACTION
277 )
278 ENGINE = InnoDB;'
279 );
280 }
281
282 private function updateFor862()
283 {
284 if ($this->isPreviousVersionAtLeast('8.6.2')) {
285 return;
286 }
287
288 $this->updateQuery('DELETE FROM #__acym_campaign WHERE mail_id IS NULL');
289
290 $mailsToClean = acym_loadResultArray(
291 'SELECT mail.id
292 FROM `#__acym_mail` AS mail
293 LEFT JOIN #__acym_campaign AS campaign
294 ON mail.id = campaign.mail_id
295 WHERE campaign.mail_id IS NULL
296 AND mail.parent_id IS NULL
297 AND mail.type = '.acym_escapeDB(MailClass::TYPE_STANDARD)
298 );
299
300 if (!empty($mailsToClean)) {
301 $this->updateQuery('DELETE FROM #__acym_mail_archive WHERE mail_id IN ('.implode(',', $mailsToClean).')');
302 $mailClass = new MailClass();
303 $mailClass->delete($mailsToClean);
304 }
305 }
306
307 private function updateFor870()
308 {
309 if ($this->isPreviousVersionAtLeast('8.7.0')) {
310 return;
311 }
312
313 $this->updateQuery('ALTER TABLE #__acym_plugin DROP `features`');
314 }
315
316 private function updateFor872($config)
317 {
318 if ($this->isPreviousVersionAtLeast('8.7.2')) {
319 return;
320 }
321
322 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
323 if (empty($socialIcons['X'])) {
324 $socialIcons['X'] = ACYM_IMAGES.'logo/x.png';
325
326 $newConfig = new \stdClass();
327 $newConfig->social_icons = json_encode($socialIcons);
328 $config->save($newConfig);
329 }
330 }
331
332 private function updateFor873($config)
333 {
334 if ($this->isPreviousVersionAtLeast('8.7.3')) {
335 return;
336 }
337
338 $socialIcons = json_decode($config->get('social_icons', '{}'), true);
339
340 if (!empty($socialIcons['X'])) {
341 unset($socialIcons['X']);
342
343 $newConfig = new \stdClass();
344 $newConfig->social_icons = json_encode($socialIcons);
345 $config->save($newConfig);
346 }
347
348 if (empty($socialIcons['x'])) {
349 $socialIcons['x'] = ACYM_IMAGES.'logo/x.png';
350
351 $newConfig = new \stdClass();
352 $newConfig->social_icons = json_encode($socialIcons);
353 $config->save($newConfig);
354 }
355 }
356
357 private function updateFor874($config)
358 {
359 if ($this->isPreviousVersionAtLeast('8.7.4') || ACYM_CMS !== 'joomla') {
360 return;
361 }
362
363 $config->save(['malicious_scan' => 1]);
364 }
365
366 private function updateFor881($config)
367 {
368 if ($this->isPreviousVersionAtLeast('8.7.0')) {
369 return;
370 }
371
372 $uploadFolder = $config->get('uploadfolder');
373 if (!empty($uploadFolder) && strpos($uploadFolder, '\\') !== false) {
374 $uploadFolder = str_replace('\\', '/', $uploadFolder);
375 $config->save(['uploadfolder' => $uploadFolder]);
376 }
377 }
378 }
379