| @@ -11,19 +11,47 @@ | ||
| 11 | 11 | { |
| 12 | 12 | $v1FormContents = get_transient('bitforms_v1_form_contents'); |
| 13 | 13 | $newFormContents = []; |
| 14 | 14 | foreach ($v1FormContents as $formContents) { |
| 15 | - $migrationHandler = new Migration(json_decode(wp_json_encode($formContents))); | |
| 15 | + $migrationHandler = new Migration(json_decode(json_encode($formContents))); | |
| 16 | 16 | $newFormContents[] = $migrationHandler->migrate(); |
| 17 | 17 | } |
| 18 | 18 | self::migratePaypal(); |
| 19 | 19 | $config = (object) []; |
| 20 | 20 | $config->delete_table = true; |
| 21 | + $this->duplicateV1StyleFiles(); | |
| 21 | 22 | update_option('bitform_app_config', $config); |
| 22 | - set_transient('bitforms_v1_form_contents', $newFormContents); | |
| 23 | 23 | return $newFormContents; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | + public function rollbackToV1() | |
| 27 | + { | |
| 28 | + $this->dropTableAndRename('form', 'form_v1'); | |
| 29 | + $this->dropTableAndRename('workflows', 'workflows_v1'); | |
| 30 | + $this->dropTableAndRename('success_messages', 'success_messages_v1'); | |
| 31 | + $source = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'; | |
| 32 | + MigrationHelper::recursiveDeleteFiles($source); | |
| 33 | + $destination = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'; | |
| 34 | + MigrationHelper::recursiveCopyFiles($destination, $source); | |
| 35 | + MigrationHelper::recursiveDeleteFiles($destination); | |
| 36 | + if (file_exists($destination)) { | |
| 37 | + rmdir($destination); | |
| 38 | + } | |
| 39 | + delete_option('bitforms_migrating_to_v2'); | |
| 40 | + delete_option('bitforms_migrated_to_v2'); | |
| 41 | + } | |
| 42 | + | |
| 43 | + private function duplicateV1StyleFiles() | |
| 44 | + { | |
| 45 | + $source = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'; | |
| 46 | + $destination = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'; | |
| 47 | + if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1')) { | |
| 48 | + wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'); | |
| 49 | + } | |
| 50 | + MigrationHelper::recursiveCopyFiles($source, $destination); | |
| 51 | + MigrationHelper::recursiveDeleteFiles($source); | |
| 52 | + } | |
| 53 | + | |
| 26 | 54 | private static function migratePaypal() |
| 27 | 55 | { |
| 28 | 56 | $integrationHandler = new IntegrationHandler(0); |
| 29 | 57 | $formIntegrations = $integrationHandler->getAllIntegration('app', 'payments'); |
| @@ -37,9 +65,9 @@ | ||
| 37 | 65 | if ('PayPal' === $integrationDetails->type) { |
| 38 | 66 | $integrationDetails->mode = 'live'; |
| 39 | 67 | $integrationDetails->clientSecret = ''; |
| 40 | 68 | $integrationModel->update([ |
| 41 | - 'integration_details' => wp_json_encode($integrationDetails), | |
| 69 | + 'integration_details' => json_encode($integrationDetails), | |
| 42 | 70 | ], [ |
| 43 | 71 | 'id' => $payment->id, |
| 44 | 72 | ]); |
| 45 | 73 | } |
| @@ -51,9 +79,8 @@ | ||
| 51 | 79 | { |
| 52 | 80 | global $wpdb; |
| 53 | 81 | $deleteTable = "{$wpdb->prefix}bitforms_{$deletedTableName}"; |
| 54 | 82 | $renameTable = "{$wpdb->prefix}bitforms_{$renamedTableName}"; |
| 55 | - // Schema migration: table name interpolation only. $wpdb->prepare() cannot parameterize DDL statements. | |
| 56 | - $wpdb->query("DROP TABLE IF EXISTS `{$deleteTable}`"); | |
| 57 | - $wpdb->query("RENAME TABLE `{$renameTable}` TO `{$deleteTable}`"); | |
| 83 | + $wpdb->query("DROP TABLE IF EXISTS $deleteTable"); | |
| 84 | + $wpdb->query("RENAME TABLE $renameTable TO $deleteTable"); | |
| 58 | 85 | } |
| 59 | 86 | } |