PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.0.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.0.1
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 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 All 134 releases
jetformbuilder / modules / gateways / migrate-legacy-data.php

migrate-legacy-data.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.0.1, at modules/gateways/migrate-legacy-data.php

89 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Gateways;
5
6 use Jet_Form_Builder\Actions\Events\Default_Process\Default_Process_Event;
7 use Jet_Form_Builder\Actions\Events\Gateway_Failed\Gateway_Failed_Event;
8 use Jet_Form_Builder\Actions\Events\Gateway_Success\Gateway_Success_Event;
9 use Jet_Form_Builder\Actions\Events_List;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 class Migrate_Legacy_Data {
17
18 protected $gateways;
19
20 public function __construct( array $gateways ) {
21 $this->gateways = $gateways;
22 }
23
24 public static function migrate( array $gateways ) {
25 if ( ! empty( $gateways['last_migrate'] ) ) {
26 return;
27 }
28 $self = new static( $gateways );
29
30 jet_fb_action_handler()->merge_events(
31 $self->get_actions_ids()
32 );
33 }
34
35 protected function get_actions_ids(): array {
36 $on_success = $this->get_active_actions( $this->gateways['notifications_success'] ?? array() );
37 $on_failed = $this->get_active_actions( $this->gateways['notifications_failed'] ?? array() );
38 $on_before = $this->get_active_actions( $this->gateways['notifications_before'] ?? array() );
39 $use_redirect = $this->gateways['use_success_redirect'] ?? false;
40
41 $has_redirect = false;
42
43 if ( ! $on_success && ! $on_failed && ! $on_before && ! $use_redirect ) {
44 return array();
45 }
46
47 $response = array();
48
49 foreach ( jet_fb_action_handler()->get_all() as $action ) {
50 $events = new Events_List();
51
52 if ( in_array( $action->_id, $on_success, true ) ) {
53 $events->push( Gateway_Success_Event::class );
54 }
55 if ( in_array( $action->_id, $on_failed, true ) ) {
56 $events->push( Gateway_Failed_Event::class );
57 }
58 if ( in_array( $action->_id, $on_before, true ) ) {
59 $events->push( Default_Process_Event::class );
60 }
61 if ( $use_redirect && ! $has_redirect && 'redirect_to_page' === $action->get_id() ) {
62 $events->push( Gateway_Success_Event::class );
63 $has_redirect = true;
64 }
65
66 if ( ! $events ) {
67 continue;
68 }
69
70 $response[ $action->_id ] = $events;
71 }
72
73 return $response;
74 }
75
76 protected function get_active_actions( $actions ): array {
77 $response = array();
78
79 foreach ( $actions as $id => $settings ) {
80 if ( ! empty( $settings['active'] ) ) {
81 $response[] = $id;
82 }
83 }
84
85 return $response;
86 }
87
88 }
89