| @@ -1,59 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Fallback; |
| 4 | 4 | |
| 5 | -use BitCode\BitForm\Core\Database\DB; | |
| 6 | 5 | use BitCode\BitForm\Core\Database\WorkFlowModel; |
| 7 | 6 | use BitCode\BitForm\Core\Util\IpTool; |
| 8 | 7 | |
| 9 | 8 | class WorkFlow |
| 10 | 9 | { |
| 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 | - // Runs on `init` (any request), but the `workflow_category` column is added by a migration gated | |
| 22 | - // behind an admin request. Ensure the column exists first (self-heal) so a non-admin/cron first | |
| 23 | - // request does not silently no-op and leave rows uncategorized. | |
| 24 | - global $wpdb; | |
| 25 | - $table = $wpdb->prefix . 'bitforms_workflows'; | |
| 26 | - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'workflow_category'")) { | |
| 27 | - DB::migrate(); | |
| 28 | - if (null === $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'workflow_category'")) { | |
| 29 | - return ''; | |
| 30 | - } | |
| 31 | - } | |
| 32 | - | |
| 33 | - $workFlowModel = new WorkFlowModel(); | |
| 34 | - $workFlows = $workFlowModel->get( | |
| 35 | - ['id', 'workflow_info', 'workflow_category'], | |
| 36 | - [], | |
| 37 | - null, | |
| 38 | - null, | |
| 39 | - 'id' | |
| 40 | - ); | |
| 41 | - if (is_wp_error($workFlows) || count($workFlows) <= 0) { | |
| 42 | - return ''; | |
| 43 | - } | |
| 44 | - foreach ($workFlows as $workflow) { | |
| 45 | - $info = !empty($workflow->workflow_info) ? \json_decode($workflow->workflow_info) : null; | |
| 46 | - $category = (!empty($info) && isset($info->type) && 'basic' === $info->type) ? 'basic' : 'classic'; | |
| 47 | - if ($category !== $workflow->workflow_category) { | |
| 48 | - $workFlowModel->update( | |
| 49 | - ['workflow_category' => $category], | |
| 50 | - ['id' => $workflow->id] | |
| 51 | - ); | |
| 52 | - } | |
| 53 | - } | |
| 54 | - } | |
| 55 | - | |
| 56 | 10 | public function conditionalLogic() |
| 57 | 11 | { |
| 58 | 12 | $workFlowUpdatedSatus = true; |
| 59 | 13 | $workFlowModel = new WorkFlowModel(); |
| @@ -62,9 +16,8 @@ | ||
| 62 | 16 | 'id', |
| 63 | 17 | 'workflow_behaviour', |
| 64 | 18 | 'workflow_condition', |
| 65 | 19 | 'workflow_action', |
| 66 | - 'workflow_status', | |
| 67 | 20 | ], |
| 68 | 21 | [], |
| 69 | 22 | null, |
| 70 | 23 | null, |
| @@ -109,9 +62,8 @@ | ||
| 109 | 62 | } |
| 110 | 63 | } |
| 111 | 64 | if ($workFlowUpdatedSatus) { |
| 112 | 65 | global $wpdb; |
| 113 | - // Schema migration: table name interpolation only. $wpdb->prepare() cannot parameterize DDL statements. | |
| 114 | 66 | $wpdb->query( |
| 115 | 67 | "ALTER TABLE `{$wpdb->prefix}bitforms_workflows` DROP `workflow_action`" |
| 116 | 68 | ); |
| 117 | 69 | } |