Skip to content

Support New DT-Import Non-Overwrite Setting#2668

Merged
corsacca merged 27 commits into
DiscipleTools:developfrom
kodinkat:dt-import-43-overwrite-support
Jul 16, 2025
Merged

Support New DT-Import Non-Overwrite Setting#2668
corsacca merged 27 commits into
DiscipleTools:developfrom
kodinkat:dt-import-43-overwrite-support

Conversation

@kodinkat
Copy link
Copy Markdown
Collaborator

@kodinkat kodinkat commented Apr 9, 2025

No description provided.

@corsacca corsacca requested a review from Copilot April 10, 2025 13:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (3)
  • dt-posts/dt-posts-endpoints.php: Language not supported
  • dt-posts/dt-posts-hooks.php: Language not supported
  • dt-posts/dt-posts.php: Language not supported

@corsacca
Copy link
Copy Markdown
Member

@kodinkat does dt_ignore_duplicated_post_fields check if the 2 values are different or if any value exists on the existing record? I'm having trouble following the logic.
The previous behavior is that all fields are updated.
The new behavior:

  • for single values fields: we don't update the field if it already has a value
  • for multiple value fields: we only add new values if they don't already exist

Does that sound right?

@corsacca
Copy link
Copy Markdown
Member

I'm curious about adding this feature to the update_post function. Something like do_not_overwrite_exsting_fields param is past in, then it does the check there.

We'll also need to write some unit tests for this. AI should be good at this part.

@kodinkat
Copy link
Copy Markdown
Collaborator Author

@kodinkat does dt_ignore_duplicated_post_fields check if the 2 values are different or if any value exists on the existing record? I'm having trouble following the logic. The previous behavior is that all fields are updated. The new behavior:

  • for single values fields: we don't update the field if it already has a value
  • for multiple value fields: we only add new values if they don't already exist

Does that sound right?

This is correct, as new logic only updates/adds value if field does not already contain it. Therefore, ignoring any duplicates.

@kodinkat
Copy link
Copy Markdown
Collaborator Author

I'm curious about adding this feature to the update_post function. Something like do_not_overwrite_exsting_fields param is past in, then it does the check there.

We'll also need to write some unit tests for this. AI should be good at this part.

Sounds good, maybe tackle as a new ticket, once functionality has been merged in?

@corsacca
Copy link
Copy Markdown
Member

On this one lets go slower.
Lets move the do not overwrite to the update post
and lets create unit tests to check that things are working as expected.

@kodinkat
Copy link
Copy Markdown
Collaborator Author

@corsacca pls see latest shape and let me know if this holds up for you...

@corsacca
Copy link
Copy Markdown
Member

corsacca commented Jun 2, 2025

@kodinkat can you make sure there are tests for each field type?

@corsacca
Copy link
Copy Markdown
Member

corsacca commented Jun 18, 2025

@kodinkat

A clarification.

$original = [
"name" => "bob",
"phone" => "1234"
]
$update = [
"name" => "Fred",
"phone" => "2903",
"email" => "test@test.com"
]

The results should be

[
"name" => "bob",
"phone" => "1234",
"email" => "test@test.com"
]

Because we have the "dont_overwrite_existing_fields" set to true.

Right now the result is

[
"name" => "Fred",
"phone" => "2903",
"email" => "test@test.com"
]

@kodinkat
Copy link
Copy Markdown
Collaborator Author

@corsacca see latest updates; which should now produce the desired shape.

@corsacca
Copy link
Copy Markdown
Member

@kodinkat The same thing applies for all the other fields too. For example date is being updated even if original has a date.
Please have a look at each field

@kodinkat
Copy link
Copy Markdown
Collaborator Author

@corsacca Below is a summary of the logic now adopted across the different field types, when do_not_overwrite_existing_fields flag is enabled.

The following field types, will only be allowed to update, if no existing values are detected.

  • text
  • textarea
  • number
  • boolean
  • date
  • key_select

The following field types, will only be allowed to update, if no matching options are detected. However, non-matching options could also exist.

  • tags
  • multi_select
  • location
  • location_meta
  • communication_channel

Also, just to highlight, as the do_not_overwrite_existing_fields flag is enabled by default on both create_post & update_post endpoints; the above conditions will prevent some direct manual record field updates.

…lect fields are not overwritten during post creation
@corsacca
Copy link
Copy Markdown
Member

@kodinkat Missing tests for multi_select, user_select, connection.
I started the multi_select and user_select to the create, but it is getting on error.
Also a couple fixes.
Would you be able to add the missing ones please?

cursor[bot]

This comment was marked as outdated.

@corsacca
Copy link
Copy Markdown
Member

Thank you @kodinkat!

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

corsacca added 2 commits July 16, 2025 11:22
… format

The dt_ignore_duplicated_post_fields function now correctly handles both direct array format [['value' => 'xxx']] and wrapped format ['values' => [['value' => 'xxx']]] for communication_channel fields.

- Added logic to detect if field_value has a 'values' key and extract the correct array to iterate over
- Preserves the original format (wrapped or direct) when returning updated fields
- Fixes bug where wrapped format was not being processed correctly, leading to incorrect duplicate detection

This ensures that duplicate detection works consistently regardless of the field format received.
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

corsacca added 2 commits July 16, 2025 11:47
All multi-value field types (tags, link, connection, multi_select, location, location_meta, communication_channel) now consistently:
- Accept both direct array format [['value' => 'xxx']] and wrapped format ['values' => [['value' => 'xxx']]]
- Always return wrapped format ['values' => ] for consistency

This ensures uniform behavior across all field types and eliminates format inconsistencies that could cause issues when fields are provided in different formats.
…d formats

Modified the unit tests for create and update post functionalities to use the new wrapped format for contact_phone and contact_email fields. This change ensures consistency with the recent updates to field handling across the codebase.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Field Overwrite Bug in `dt_ignore_duplicated_post_fields`

The dt_ignore_duplicated_post_fields function incorrectly uses empty() to determine if existing field values should be preserved. This causes valid falsy values (e.g., boolean false, number 0, or string '0' for key_select fields) to be treated as empty and overwritten, even when do_not_overwrite_existing_fields is enabled. The check should verify if the field is unset or null instead.

dt-posts/posts.php#L3179-L3182

case 'user_select':
if ( empty( $existing_fields[ $field_key ] ) ) {
$updated_fields[ $field_key ] = $field_value;
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@corsacca corsacca merged commit 417db1b into DiscipleTools:develop Jul 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants