| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | use BitCode\BitForm\Admin\Form\AdminFormHandler; |
| 6 | 6 | use BitCode\BitForm\Core\Database\DB; |
| 7 | 7 | use BitCode\BitForm\Core\Database\FormModel; |
| 8 | 8 | use BitCode\BitForm\Core\Form\FormHandler; |
| 9 | +use BitCode\BitForm\Core\Form\FormManager; | |
| 9 | 10 | use BitCode\BitForm\Core\Migration\MigrateForms; |
| 10 | 11 | use BitCode\BitForm\Core\Migration\MigrationHelper; |
| 11 | 12 | |
| 12 | 13 | final class FormFallback |
| @@ -21,8 +22,43 @@ | ||
| 21 | 22 | [ |
| 22 | 23 | 'status' => 1 |
| 23 | 24 | ] |
| 24 | 25 | ); |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Name/Address children renamed with their parent before 3.3.2 kept the old prefix, so their | |
| 30 | + * inputs posted away from the parent and its entry value saved empty. Safe to re-run: only | |
| 31 | + * forms whose names actually change are written. | |
| 32 | + * | |
| 33 | + * @return void | |
| 34 | + */ | |
| 35 | + public function syncCompositeChildNames() | |
| 36 | + { | |
| 37 | + $formModel = new FormModel(); | |
| 38 | + $forms = $formModel->get( | |
| 39 | + ['id', 'form_content'], | |
| 40 | + [ | |
| 41 | + 'form_content' => ['operator' => 'LIKE', 'value' => '%"childFields"%'], | |
| 42 | + ] | |
| 43 | + ); | |
| 44 | + if (is_wp_error($forms) || !is_array($forms)) { | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + foreach ($forms as $form) { | |
| 48 | + $formContent = json_decode($form->form_content ?? ''); | |
| 49 | + if (!is_object($formContent) || !isset($formContent->fields)) { | |
| 50 | + continue; | |
| 51 | + } | |
| 52 | + if (!FormManager::syncCompositeChildNames($formContent->fields)) { | |
| 53 | + continue; | |
| 54 | + } | |
| 55 | + $encoded = wp_json_encode($formContent); | |
| 56 | + if (!is_string($encoded)) { | |
| 57 | + continue; | |
| 58 | + } | |
| 59 | + $formModel->update(['form_content' => $encoded], ['id' => $form->id]); | |
| 60 | + } | |
| 25 | 61 | } |
| 26 | 62 | |
| 27 | 63 | public function v1formMigragion() |
| 28 | 64 | { |