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