| @@ -1,13 +1,52 @@ | ||
| 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 | 9 | class WorkFlow |
| 9 | 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 | + | |
| 10 | 49 | public function conditionalLogic() |
| 11 | 50 | { |
| 12 | 51 | $workFlowUpdatedSatus = true; |
| 13 | 52 | $workFlowModel = new WorkFlowModel(); |