PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.2
JetFormBuilder — Dynamic Blocks Form Builder v3.1.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / package / migrations / migrate.gateways.settings.js
jetformbuilder / assets / src / package / migrations Last commit date
migrate.conditional.block.js 2 years ago migrate.gateways.settings.js 2 years ago
migrate.gateways.settings.js
115 lines
1 const getMeta = () => {
2 const { select } = wp.data;
3 return select( 'core/editor' ).getEditedPostAttribute( 'meta' );
4 };
5
6 const editMeta = ( name, objectValue ) => {
7 const { dispatch } = wp.data;
8
9 const { editPost } = dispatch( 'core/editor' );
10 const formBuilderMeta = getMeta();
11
12 editPost( {
13 meta: (
14 {
15 ...formBuilderMeta,
16 [ name ]: JSON.stringify( objectValue ),
17 }
18 ),
19 } );
20 };
21
22 const getActiveActions = actions => {
23 const response = [];
24
25 for ( const [ action_id, { active = false } ] of Object.entries( actions ) ) {
26 if ( ! active ) {
27 continue;
28 }
29 response.push( + action_id );
30 }
31
32 return response;
33 };
34
35 const getGatewaysActions = () => {
36 const formBuilderMeta = getMeta();
37
38 let gateways = {},
39 actions = [];
40
41 try {
42 gateways = JSON.parse( formBuilderMeta[ '_jf_gateways' ] );
43 } catch ( error ) {
44 return [];
45 }
46
47 if ( 1 === gateways.last_migrate ) {
48 throw 'migrated';
49 }
50
51 try {
52 actions = JSON.parse( formBuilderMeta[ '_jf_actions' ] );
53 } catch ( error ) {
54 return [ gateways ];
55 }
56
57 return [ gateways, actions ];
58 };
59
60 const migrate = ( gateways, actions ) => {
61 const on_success = getActiveActions( gateways[ 'notifications_success' ] ?? {} );
62 const on_failed = getActiveActions( gateways[ 'notifications_failed' ] ?? {} );
63 const on_before = getActiveActions( gateways[ 'notifications_before' ] ?? {} );
64 const use_redirect = gateways[ 'use_success_redirect' ] ?? false;
65
66 let has_redirect = false;
67
68 if ( ! on_success.length && ! on_failed.length && ! on_before.length && ! use_redirect ) {
69 throw 'nothing_to_migrate';
70 }
71
72 return actions.map( action => {
73 action.events = action.events ?? [];
74
75 if ( on_success.includes( action.id ) ) {
76 action.events.push( 'GATEWAY.SUCCESS' );
77 }
78 if ( on_failed.includes( action.id ) ) {
79 action.events.push( 'GATEWAY.FAILED' );
80 }
81 if ( on_before.includes( action.id ) ) {
82 action.events.push( 'DEFAULT.PROCESS' );
83 }
84 if ( use_redirect && ! has_redirect && 'redirect_to_page' === action.type ) {
85 action.events.push( 'GATEWAY.SUCCESS' );
86 has_redirect = true;
87 }
88
89 return action;
90 } );
91 };
92
93 const runEvent = () => {
94 let gateways = {}, actions = [];
95
96 try {
97 [ gateways = {}, actions = [] ] = getGatewaysActions();
98 } catch ( error ) {
99 return;
100 }
101
102 gateways.last_migrate = 1;
103 editMeta( '_jf_gateways', gateways );
104
105 const withConditions = [];
106 try {
107 withConditions.push( ...migrate( gateways, actions ) );
108 } catch ( error ) {
109 return;
110 }
111
112 editMeta( '_jf_actions', withConditions );
113 };
114
115 wp.domReady( () => setTimeout( runEvent, 0 ) );