Fix import issue with conditonal logic#2472
Conversation
WalkthroughExtends FrmFieldsHelper::switch_field_ids to include additional string replacement rules for conditional logic references, mapping occurrences of _field":"<old_id>"," to _field":"<new_id>", alongside existing replacements for [if], [foreach], and field_id patterns. No signature or control-flow changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.17)Note: Using configuration file /phpstan.neon. Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
classes/helpers/FrmFieldsHelper.php (2)
1602-1605: Also handle end-of-object and escaped-quote casesRight now this only matches when the
_fieldproperty is followed by a comma and uses unescaped quotes. It can miss:
- last property in an object:
"_field":"<id>"}- strings that have been escaped once:
_field\":\"<id>\",\"or_field\":\"<id>\"}Add a few more targeted patterns to cover those without switching to regex.
// This covers conditional logic. $replace[] = '_field":"' . $old . '","'; $replace_with[] = '_field":"' . $new . '","'; + // Handle end-of-object as well. + $replace[] = '_field":"' . $old . '"}'; + $replace_with[] = '_field":"' . $new . '"}'; + // Handle escaped quotes (content embedded in another JSON/string layer). + $replace[] = '_field\":\"' . $old . '\",\"'; + $replace_with[] = '_field\":\"' . $new . '\",\"'; + $replace[] = '_field\":\"' . $old . '\"}'; + $replace_with[] = '_field\":\"' . $new . '\"}';
1602-1605: Consider numeric JSON values for _field (if any)If any stored conditional logic uses numeric IDs without quotes (e.g.,
"_field":123,), the current replacements won’t fire. If that exists in the wild, add numeric variants. If everything is consistently strings, ignore this.+ // Optional: numeric JSON values (only if we ever store IDs as numbers). + $replace[] = '_field":' . $old . ','; + $replace_with[] = '_field":' . $new . ','; + $replace[] = '_field":' . $old . '}'; + $replace_with[] = '_field":' . $new . '}';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
classes/helpers/FrmFieldsHelper.php(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: PHP 8 tests in WP trunk
- GitHub Check: PHP 7.4 tests in WP trunk
- GitHub Check: Cypress
- GitHub Check: Cypress
- GitHub Check: Run PHP Syntax inspection (8.3)
- GitHub Check: PHP 7.4 tests in WP trunk
- GitHub Check: PHP 8 tests in WP trunk
🔇 Additional comments (2)
classes/helpers/FrmFieldsHelper.php (2)
1602-1605: Good catch: cover conditional-logic references ending with_fieldThe added replacement safely targets JSON-encoded conditional logic references like
"..._field":"<id>",and plugs an obvious hole that caused unmapped fields on import. Nicely localized and consistent with existing replacement strategy.
1602-1605: Please add targeted PHPUnit tests for conditional‐logic JSON and quiz‐outcome payloadsBased on the scan results, we didn’t find any existing tests or code paths that cover all of these edge cases for the
_fieldremapping inswitch_field_ids:• JSON blobs where
_fieldappears mid-object with a trailing comma (covered by your replacement on lines 1602–1604)
• JSON blobs where_fieldis the last property in an object (no trailing comma)
• Double-encoded or escaped-quote variants (e.g._field\":\"…)
• Quiz-outcome payloads that include unmapped fieldsWe should ensure each of these scenarios is exercised by a regression test in
tests/phpunit/fields/test_FrmFieldsHelper.php. I can help draft sample payloads and assertions if that’s useful.
I noticed that quiz outcomes weren't importing properly. The fields were all unmapped.
This update adds another substring that should be safe to replace when importing data, that could possibly catch other similar issues - not just conditional logic.