| @@ -1,13 +1,54 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Fallback; |
| 4 | 4 | |
| 5 | +use BitCode\BitForm\Core\Database\DB; | |
| 5 | 6 | use BitCode\BitForm\Core\Database\WorkFlowModel; |
| 6 | 7 | use BitCode\BitForm\Core\Util\IpTool; |
| 7 | 8 | |
| 8 | -class WorkFlow { | |
| 9 | - public function conditionalLogic() { | |
| 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 | + { | |
| 10 | 51 | $workFlowUpdatedSatus = true; |
| 11 | 52 | $workFlowModel = new WorkFlowModel(); |
| 12 | 53 | $workFlows = $workFlowModel->get( |
| 13 | 54 | [ |
| @@ -14,8 +55,9 @@ | ||
| 14 | 55 | 'id', |
| 15 | 56 | 'workflow_behaviour', |
| 16 | 57 | 'workflow_condition', |
| 17 | 58 | 'workflow_action', |
| 59 | + 'workflow_status', | |
| 18 | 60 | ], |
| 19 | 61 | [], |
| 20 | 62 | null, |
| 21 | 63 | null, |
| @@ -43,9 +85,9 @@ | ||
| 43 | 85 | ]; |
| 44 | 86 | if ('cond' === $beheviour) { |
| 45 | 87 | $workFlows[$index]->workflow_condition['logics'] = $logic; |
| 46 | 88 | } |
| 47 | - $updatedWorkFlow = json_encode([$workFlows[$index]->workflow_condition]); | |
| 89 | + $updatedWorkFlow = wp_json_encode([$workFlows[$index]->workflow_condition]); | |
| 48 | 90 | $updated = $workFlowModel->update( |
| 49 | 91 | [ |
| 50 | 92 | 'workflow_condition' => $updatedWorkFlow, |
| 51 | 93 | 'updated_at' => $user_details['time'], |
| @@ -60,8 +102,9 @@ | ||
| 60 | 102 | } |
| 61 | 103 | } |
| 62 | 104 | if ($workFlowUpdatedSatus) { |
| 63 | 105 | global $wpdb; |
| 106 | + // Schema migration: table name interpolation only. $wpdb->prepare() cannot parameterize DDL statements. | |
| 64 | 107 | $wpdb->query( |
| 65 | 108 | "ALTER TABLE `{$wpdb->prefix}bitforms_workflows` DROP `workflow_action`" |
| 66 | 109 | ); |
| 67 | 110 | } |