PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Migration / MigrateForms.php

MigrateForms.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Migration/MigrateForms.php

81 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Migration;
4
5 use BitCode\BitForm\Core\Database\IntegrationModel;
6 use BitCode\BitForm\Core\Integration\IntegrationHandler;
7
8 final class MigrateForms {
9 public function migrateToV2() {
10 $v1FormContents = get_transient('bitforms_v1_form_contents');
11 $newFormContents = [];
12 foreach ($v1FormContents as $formContents) {
13 $migrationHandler = new Migration(json_decode(json_encode($formContents)));
14 $newFormContents[] = $migrationHandler->migrate();
15 }
16 self::migratePaypal();
17 $config = (object) [];
18 $config->delete_table = true;
19 $this->duplicateV1StyleFiles();
20 add_option('bitform_app_config', $config);
21 return $newFormContents;
22 }
23
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() {
51 $integrationHandler = new IntegrationHandler(0);
52 $formIntegrations = $integrationHandler->getAllIntegration('app', 'payments');
53 if (!is_wp_error($formIntegrations)) {
54 return false;
55 }
56 $integrationModel = new IntegrationModel();
57
58 foreach ($formIntegrations as $payment) {
59 $integrationDetails = json_decode($payment->integration_details);
60 if ('PayPal' === $integrationDetails->type) {
61 $integrationDetails->mode = 'live';
62 $integrationDetails->clientSecret = '';
63 $integrationModel->update([
64 'integration_details' => json_encode($integrationDetails),
65 ], [
66 'id' => $payment->id,
67 ]);
68 }
69 }
70 return true;
71 }
72
73 private function dropTableAndRename($deletedTableName, $renamedTableName) {
74 global $wpdb;
75 $deleteTable = "{$wpdb->prefix}bitforms_{$deletedTableName}";
76 $renameTable = "{$wpdb->prefix}bitforms_{$renamedTableName}";
77 $wpdb->query("DROP TABLE IF EXISTS $deleteTable");
78 $wpdb->query("RENAME TABLE $renameTable TO $deleteTable");
79 }
80 }
81