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