PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 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 All 138 releases
bit-form / includes / Core / Fallback / WorkFlow.php

WorkFlow.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.3.1, at includes/Core/Fallback/WorkFlow.php

113 lines 3.5 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\Fallback;
4
5 use BitCode\BitForm\Core\Database\DB;
6 use BitCode\BitForm\Core\Database\WorkFlowModel;
7 use BitCode\BitForm\Core\Util\IpTool;
8
9 class WorkFlow
10 {
11 /**
12 * Free/Pro conditional-logic separation: backfill workflow_category on existing rows.
13 *
14 * The DB migration adds the column with DEFAULT 'classic', so every pre-existing row is already
15 * classic (= keeps executing in Free exactly as before). Here we only retag rows that the basic
16 * field show/hide UI marked as info.type === 'basic'. Existing rows predate the advanced (Pro)
17 * feature, so nothing legitimately maps to 'advanced' during this one-time upgrade.
18 */
19 public function normalizeCategory()
20 {
21 // Self-heal `workflow_category` first, else this pass silently leaves rows uncategorized.
22 if (!DB::ensureWorkflowSchema()) {
23 return '';
24 }
25
26 $workFlowModel = new WorkFlowModel();
27 $workFlows = $workFlowModel->get(
28 ['id', 'workflow_info', 'workflow_category'],
29 [],
30 null,
31 null,
32 'id'
33 );
34 if (is_wp_error($workFlows) || count($workFlows) <= 0) {
35 return '';
36 }
37 foreach ($workFlows as $workflow) {
38 $info = !empty($workflow->workflow_info) ? \json_decode($workflow->workflow_info) : null;
39 $category = (!empty($info) && isset($info->type) && 'basic' === $info->type) ? 'basic' : 'classic';
40 if ($category !== $workflow->workflow_category) {
41 $workFlowModel->update(
42 ['workflow_category' => $category],
43 ['id' => $workflow->id]
44 );
45 }
46 }
47 }
48
49 public function conditionalLogic()
50 {
51 $workFlowUpdatedSatus = true;
52 $workFlowModel = new WorkFlowModel();
53 $workFlows = $workFlowModel->get(
54 [
55 'id',
56 'workflow_behaviour',
57 'workflow_condition',
58 'workflow_action',
59 'workflow_status',
60 ],
61 [],
62 null,
63 null,
64 'id'
65 );
66 if (is_wp_error($workFlows) || count($workFlows) <= 0) {
67 return '';
68 }
69 $ipTool = new IpTool();
70 $user_details = $ipTool->getUserDetail();
71
72 foreach ($workFlows as $index => $workflow) {
73 $decode = \json_decode($workflow->workflow_action);
74 $logic = \json_decode($workflow->workflow_condition);
75 $beheviour = $workflow->workflow_behaviour;
76 $cond = 'cond' === $beheviour ? 'if' : 'always';
77
78 $workFlows[$index]->workflow_condition = [
79 'cond_type' => $cond,
80 'actions' => [
81 'fields' => $decode->action ? $decode->action : [],
82 'success' => $decode->successAction ? $decode->successAction : [],
83 'failure' => $decode->validateMsg ? $decode->validateMsg : '',
84 ],
85 ];
86 if ('cond' === $beheviour) {
87 $workFlows[$index]->workflow_condition['logics'] = $logic;
88 }
89 $updatedWorkFlow = wp_json_encode([$workFlows[$index]->workflow_condition]);
90 $updated = $workFlowModel->update(
91 [
92 'workflow_condition' => $updatedWorkFlow,
93 'updated_at' => $user_details['time'],
94 ],
95 [
96 'id' => $workflow->id,
97 ]
98 );
99 if (is_wp_error($updated)) {
100 $workFlowUpdatedSatus = false;
101 break;
102 }
103 }
104 if ($workFlowUpdatedSatus) {
105 global $wpdb;
106 // Schema migration: table name interpolation only. $wpdb->prepare() cannot parameterize DDL statements.
107 $wpdb->query(
108 "ALTER TABLE `{$wpdb->prefix}bitforms_workflows` DROP `workflow_action`"
109 );
110 }
111 }
112 }
113