| 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 |
$elementToMigrate = acym_getVar('string', 'element', ''); |
| 13 |
$helperMigration = new MigrationHelper(); |
| 14 |
|
| 15 |
$result = $helperMigration->preMigration($elementToMigrate); |
| 16 |
|
| 17 |
if (!empty($result['isOk'])) { |
| 18 |
echo $result['count']; |
| 19 |
} else { |
| 20 |
$this->errorHandling($result); |
| 21 |
} |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
public function migrate(): void |
| 26 |
{ |
| 27 |
$elementToMigrate = acym_getVar('string', 'element'); |
| 28 |
$helperMigration = new MigrationHelper(); |
| 29 |
$functionName = 'do'.ucfirst($elementToMigrate).'Migration'; |
| 30 |
|
| 31 |
$result = $helperMigration->$functionName($elementToMigrate); |
| 32 |
|
| 33 |
if (!empty($result['isOk'])) { |
| 34 |
echo json_encode($result); |
| 35 |
} else { |
| 36 |
$this->errorHandling($result); |
| 37 |
} |
| 38 |
exit; |
| 39 |
} |
| 40 |
|
| 41 |
public function migrationDone(): void |
| 42 |
{ |
| 43 |
$this->config->saveConfig(['migration' => 1]); |
| 44 |
|
| 45 |
$updateHelper = new UpdateHelper(); |
| 46 |
$updateHelper->installNotifications(); |
| 47 |
$updateHelper->installTemplates(); |
| 48 |
$updateHelper->installOverrideEmails(); |
| 49 |
|
| 50 |
$this->listing(); |
| 51 |
} |
| 52 |
|
| 53 |
private function errorHandling(array $result): void |
| 54 |
{ |
| 55 |
echo 'ERROR : '; |
| 56 |
if (!empty($result['errorInsert'])) { |
| 57 |
echo strtoupper(acym_translation('ACYM_INSERT_ERROR')); |
| 58 |
} |
| 59 |
if (!empty($result['errorClean'])) { |
| 60 |
echo strtoupper(acym_translation('ACYM_CLEAN_ERROR')); |
| 61 |
} |
| 62 |
|
| 63 |
if (!empty($result['errors'])) { |
| 64 |
echo '<br>'; |
| 65 |
|
| 66 |
foreach ($result['errors'] as $key => $oneError) { |
| 67 |
echo '<br>'.$key.' : '.$oneError; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
public function migration(): bool |
| 73 |
{ |
| 74 |
if ($this->config->get('migration') == 0 && acym_existsAcyMailing59()) { |
| 75 |
acym_setVar('layout', 'migrate'); |
| 76 |
parent::display(); |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
$this->config->saveConfig(['migration' => 1]); |
| 82 |
|
| 83 |
return false; |
| 84 |
} |
| 85 |
} |
| 86 |
|