| @@ -4,51 +4,28 @@ | ||
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Database\IntegrationModel; |
| 6 | 6 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 7 | 7 | |
| 8 | -final class MigrateForms { | |
| 9 | - public function migrateToV2() { | |
| 8 | +final class MigrateForms | |
| 9 | +{ | |
| 10 | + public function migrateToV2() | |
| 11 | + { | |
| 10 | 12 | $v1FormContents = get_transient('bitforms_v1_form_contents'); |
| 11 | 13 | $newFormContents = []; |
| 12 | 14 | foreach ($v1FormContents as $formContents) { |
| 13 | - $migrationHandler = new Migration(json_decode(json_encode($formContents))); | |
| 15 | + $migrationHandler = new Migration(json_decode(wp_json_encode($formContents))); | |
| 14 | 16 | $newFormContents[] = $migrationHandler->migrate(); |
| 15 | 17 | } |
| 16 | 18 | self::migratePaypal(); |
| 17 | 19 | $config = (object) []; |
| 18 | 20 | $config->delete_table = true; |
| 19 | - $this->duplicateV1StyleFiles(); | |
| 20 | - add_option('bitform_app_config', $config); | |
| 21 | + update_option('bitform_app_config', $config); | |
| 22 | + set_transient('bitforms_v1_form_contents', $newFormContents); | |
| 21 | 23 | return $newFormContents; |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | - public function rollbackToV1() { | |
| 25 | - $this->dropTableAndRename('form', 'form_v1'); | |
| 26 | - $this->dropTableAndRename('workflows', 'workflows_v1'); | |
| 27 | - $this->dropTableAndRename('success_messages', 'success_messages_v1'); | |
| 28 | - $source = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'; | |
| 29 | - MigrationHelper::recursiveDeleteFiles($source); | |
| 30 | - $destination = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'; | |
| 31 | - MigrationHelper::recursiveCopyFiles($destination, $source); | |
| 32 | - MigrationHelper::recursiveDeleteFiles($destination); | |
| 33 | - if (file_exists($destination)) { | |
| 34 | - rmdir($destination); | |
| 35 | - } | |
| 36 | - delete_option('bitforms_migrating_to_v2'); | |
| 37 | - delete_option('bitforms_migrated_to_v2'); | |
| 38 | - } | |
| 39 | - | |
| 40 | - private function duplicateV1StyleFiles() { | |
| 41 | - $source = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'; | |
| 42 | - $destination = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'; | |
| 43 | - if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1')) { | |
| 44 | - wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'); | |
| 45 | - } | |
| 46 | - MigrationHelper::recursiveCopyFiles($source, $destination); | |
| 47 | - MigrationHelper::recursiveDeleteFiles($source); | |
| 48 | - } | |
| 49 | - | |
| 50 | - private static function migratePaypal() { | |
| 26 | + private static function migratePaypal() | |
| 27 | + { | |
| 51 | 28 | $integrationHandler = new IntegrationHandler(0); |
| 52 | 29 | $formIntegrations = $integrationHandler->getAllIntegration('app', 'payments'); |
| 53 | 30 | if (!is_wp_error($formIntegrations)) { |
| 54 | 31 | return false; |
| @@ -60,9 +37,9 @@ | ||
| 60 | 37 | if ('PayPal' === $integrationDetails->type) { |
| 61 | 38 | $integrationDetails->mode = 'live'; |
| 62 | 39 | $integrationDetails->clientSecret = ''; |
| 63 | 40 | $integrationModel->update([ |
| 64 | - 'integration_details' => json_encode($integrationDetails), | |
| 41 | + 'integration_details' => wp_json_encode($integrationDetails), | |
| 65 | 42 | ], [ |
| 66 | 43 | 'id' => $payment->id, |
| 67 | 44 | ]); |
| 68 | 45 | } |
| @@ -69,12 +46,14 @@ | ||
| 69 | 46 | } |
| 70 | 47 | return true; |
| 71 | 48 | } |
| 72 | 49 | |
| 73 | - private function dropTableAndRename($deletedTableName, $renamedTableName) { | |
| 50 | + private function dropTableAndRename($deletedTableName, $renamedTableName) | |
| 51 | + { | |
| 74 | 52 | global $wpdb; |
| 75 | 53 | $deleteTable = "{$wpdb->prefix}bitforms_{$deletedTableName}"; |
| 76 | 54 | $renameTable = "{$wpdb->prefix}bitforms_{$renamedTableName}"; |
| 77 | - $wpdb->query("DROP TABLE IF EXISTS $deleteTable"); | |
| 78 | - $wpdb->query("RENAME TABLE $renameTable TO $deleteTable"); | |
| 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}`"); | |
| 79 | 58 | } |
| 80 | 59 | } |