| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Migration; |
| 4 |
|
| 5 |
// create class for migration |
| 6 |
final class Migration |
| 7 |
{ |
| 8 |
private $_formData; |
| 9 |
|
| 10 |
public function __construct($data) |
| 11 |
{ |
| 12 |
$this->_formData = $data; |
| 13 |
} |
| 14 |
|
| 15 |
// create function for migration |
| 16 |
public function migrate() |
| 17 |
{ |
| 18 |
$formData = $this->_formData; |
| 19 |
|
| 20 |
$formData->form_content = self::convertFormContent($formData->form_content); |
| 21 |
$formData->workFlows = WorkFlows::migrate($formData->workFlows); |
| 22 |
$formData->formSettings = self::convertFormSettings($formData->formSettings); |
| 23 |
return $formData; |
| 24 |
} |
| 25 |
|
| 26 |
public function convertFormContent($formContentV1) |
| 27 |
{ |
| 28 |
$formContenV2 = $formContentV1; |
| 29 |
|
| 30 |
if (isset($formContentV1->fields)) { |
| 31 |
$formContenV2->fields = MigrationHelper::convertFields($formContentV1->fields); |
| 32 |
} |
| 33 |
if (isset($formContentV1->layout)) { |
| 34 |
$formContenV2->layout = MigrationHelper::convertLayout($formContentV1->layout); |
| 35 |
} |
| 36 |
|
| 37 |
return $formContenV2; |
| 38 |
} |
| 39 |
|
| 40 |
public function convertFormSettings($formSettingsV1) |
| 41 |
{ |
| 42 |
$formSettingsV2 = $formSettingsV1; |
| 43 |
if (isset($formSettingsV1->confirmation->type->successMsg)) { |
| 44 |
$formSettingsV2->confirmation->type->successMsg = MigrationHelper::convertSuccessMessage($formSettingsV1->confirmation->type->successMsg); |
| 45 |
} |
| 46 |
return $formSettingsV2; |
| 47 |
} |
| 48 |
} |
| 49 |
|