Skip to content

Save company custom fields and sources on limited field updates - #100

Merged
tellyworth merged 2 commits into
trunkfrom
fix/company-limited-update-custom-fields
Nov 10, 2026
Merged

tellyworth merged 2 commits into
trunkfrom
fix/company-limited-update-custom-fields

Conversation

@tellyworth

@tellyworth tellyworth commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What

addUpdateCompany() only saved custom fields and external sources on its full update path, so a limited field update silently dropped both. An update becomes a limited field update when "Overwrite Option" (fieldoverride) is on and it comes from an external source: CSV Importer, forms, the API and the sync extensions. Callers that pass limitedFields directly hit it too.

What users see, with Overwrite Option on:

  • A CSV import mapping a company custom field (e.g. a "Company Website" text field) leaves the old value in place.
  • The import/API source is never recorded against an existing company.

Contacts don't have this problem. They have saved custom fields on both paths since 2.98.1 (skipping blanks under do_not_update_blanks), and #34 moved their external sources out of the same check. This PR gives companies the same handling, following the contacts code.

Also fixed

getCompany() / getCompanies() with withExternalSources passed their args array as getExternalSources()'s $id, so they always returned false. The grouped variant and every other caller pass -1 first. I found it because the new test needed to read the source back.

Not changed

  • Contact links and tags passed in data are still applied only on full updates. Contacts behave the same way, and changing that for both is a broader decision.
  • Same bug in Events, Quotes, Transactions and Invoices. Each saves custom fields and external sources only inside the same limitedFields guard (Events ~1471, Quotes ~1639, Transactions ~1814, Invoices ~1883). The general fix is a shared ObjectLayer helper called by all six DALs, but that touches four more large DALs with their own semantics, so it's left for a follow-up: JETCRM-1466.
  • Default behaviour (Overwrite Option off) is unchanged. That path already saved custom fields.

Testing

  • New tests/php/entities/Company_Limited_Update_Test.php. All 4 tests fail on trunk and pass here:
    • fieldoverride + external source saves the custom field it sends
    • …and doesn't blank a custom field (or column) it sends empty
    • …and records the external source
    • an explicit limitedFields update saves a custom field it names, and leaves the others alone
  • Full suite: OK (188 tests, 605 assertions), including on a freshly reset tests DB.
  • phpcs-changed clean. The moved block keeps its legacy camelCase names under a scoped phpcs:disable, as in Stop forms clearing contact details, and updates clearing the owner #34.
  • Also checked end to end against CRM 6.8.5 + CSV Importer Pro while verifying JETCRM-1465 (Automattic/jetpack-crm-extensions#908). That's where the custom-field half showed up.

Not scheduled for a release yet.

🤖 Generated with Claude Code

tellyworth and others added 2 commits November 10, 2026 15:04
addUpdateCompany() saves custom fields and external sources after the
columns, but only on the full update path. A limited field update skipped
both without a word.

An update becomes a limited field update when "Overwrite Option"
(fieldoverride) is on and it comes from an external source: the CSV
importer, forms, the API and the sync extensions. So on those sites a CSV
import mapping a company custom field left the old value in place, and the
source was never recorded against an existing company. A caller passing
limitedFields directly fared no better: the custom field keys it named were
moved out of the column update "for separate update", which then never ran.

Contacts have saved custom fields on either path since 2.98.1, skipping
blanks under do_not_update_blanks, and #34 moved their external sources out
of the same check. Companies now do the same, from the same shapes.

Also fix getCompany() and getCompanies() with withExternalSources: both
passed their args as getExternalSources()'s $id, so they always returned
false. The grouped variant and every other caller pass -1 first.

Found while testing JETCRM-1465 (Automattic/jetpack-crm-extensions#908).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From a /simplify review: the three near-identical addUpdateCustomField()
blocks (custom fields, addr_ and secaddr_ address fields) become one list
of keys and one loop, with the blank rule stated once. Same behaviour.

The test no longer resets the CRM tables twice per test (the base
integration test case already does), and fetches through get_company().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tellyworth
tellyworth force-pushed the fix/company-limited-update-custom-fields branch from 03b2ca5 to fbcea70 Compare November 10, 2026 04:04
@tellyworth
tellyworth merged commit 51f7f45 into trunk Nov 10, 2026
4 checks passed
@tellyworth tellyworth added this to the 6.8.6 milestone Nov 11, 2026
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.

1 participant