| @@ -1,112 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Controllers\Dashboard; | |
| 4 | - | |
| 5 | -use AcyMailing\Helpers\MigrationHelper; | |
| 6 | -use AcyMailing\Helpers\UpdateHelper; | |
| 7 | - | |
| 8 | -trait Migration | |
| 9 | -{ | |
| 10 | - public function preMigration(): void | |
| 11 | - { | |
| 12 | - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 13 | - | |
| 14 | - if (!acym_isAllowed('configuration') || !acym_existsAcyMailing59()) { | |
| 15 | - return; | |
| 16 | - } | |
| 17 | - | |
| 18 | - $elementToMigrate = acym_getVar('string', 'element', ''); | |
| 19 | - $helperMigration = new MigrationHelper(); | |
| 20 | - | |
| 21 | - $result = $helperMigration->preMigration($elementToMigrate); | |
| 22 | - | |
| 23 | - if (!empty($result['isOk'])) { | |
| 24 | - echo esc_html($result['count']); | |
| 25 | - } else { | |
| 26 | - $this->errorHandling($result); | |
| 27 | - } | |
| 28 | - exit; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function migrate(): void | |
| 32 | - { | |
| 33 | - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 34 | - | |
| 35 | - if (!acym_isAllowed('configuration')) { | |
| 36 | - return; | |
| 37 | - } | |
| 38 | - | |
| 39 | - $elementToMigrate = acym_getVar('string', 'element', ''); | |
| 40 | - $helperMigration = new MigrationHelper(); | |
| 41 | - $functionName = 'do'.ucfirst($elementToMigrate).'Migration'; | |
| 42 | - | |
| 43 | - if (!is_callable([$helperMigration, $functionName])) { | |
| 44 | - echo 'ERROR : '.esc_html(acym_translation('ACYM_NON_EXISTING_PAGE')); | |
| 45 | - exit; | |
| 46 | - } | |
| 47 | - | |
| 48 | - $result = $helperMigration->$functionName($elementToMigrate); | |
| 49 | - | |
| 50 | - if (!empty($result['isOk'])) { | |
| 51 | - echo json_encode($result); | |
| 52 | - } else { | |
| 53 | - $this->errorHandling($result); | |
| 54 | - } | |
| 55 | - exit; | |
| 56 | - } | |
| 57 | - | |
| 58 | - public function migrationDone(): void | |
| 59 | - { | |
| 60 | - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 61 | - | |
| 62 | - if (!acym_isAllowed('configuration')) { | |
| 63 | - return; | |
| 64 | - } | |
| 65 | - | |
| 66 | - $this->config->saveConfig(['migration' => 1]); | |
| 67 | - | |
| 68 | - $updateHelper = new UpdateHelper(); | |
| 69 | - $updateHelper->installNotifications(); | |
| 70 | - $updateHelper->installTemplates(); | |
| 71 | - $updateHelper->installOverrideEmails(); | |
| 72 | - | |
| 73 | - $this->listing(); | |
| 74 | - } | |
| 75 | - | |
| 76 | - private function errorHandling(array $result): void | |
| 77 | - { | |
| 78 | - echo 'ERROR : '; | |
| 79 | - if (!empty($result['errorInsert'])) { | |
| 80 | - echo esc_html(strtoupper(acym_translation('ACYM_INSERT_ERROR'))); | |
| 81 | - } | |
| 82 | - if (!empty($result['errorClean'])) { | |
| 83 | - echo esc_html(strtoupper(acym_translation('ACYM_CLEAN_ERROR'))); | |
| 84 | - } | |
| 85 | - | |
| 86 | - if (!empty($result['errors'])) { | |
| 87 | - echo '<br>'; | |
| 88 | - | |
| 89 | - foreach ($result['errors'] as $key => $oneError) { | |
| 90 | - echo '<br>'.esc_html($key.' : '.$oneError); | |
| 91 | - } | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - private function migration(): bool | |
| 96 | - { | |
| 97 | - if (!acym_isAllowed('configuration')) { | |
| 98 | - return false; | |
| 99 | - } | |
| 100 | - | |
| 101 | - if ($this->config->get('migration') == 0 && acym_existsAcyMailing59()) { | |
| 102 | - acym_setVar('layout', 'migrate'); | |
| 103 | - parent::display(); | |
| 104 | - | |
| 105 | - return true; | |
| 106 | - } | |
| 107 | - | |
| 108 | - $this->config->saveConfig(['migration' => 1]); | |
| 109 | - | |
| 110 | - return false; | |
| 111 | - } | |
| 112 | -} | |