@prefix sioc: <http://rdfs.org/sioc/ns#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix content: <http://purl.org/rss/1.0/modules/content/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://lhero.org/portfolio/lh-crm/>
  a sioc:Post ;
  dc:title "People table" ;
  dcterms:identifier 154902 ;
  dc:modified "2026-11-17T13:34:16Z"^^xsd:dateTime ;
  dc:created "2026-11-17T13:34:16Z"^^xsd:dateTime ;
  sioc:link <https://lhero.org/portfolio/lh-crm/people-table/> ;
  sioc:has_creator <https://lhero.org/author/1/#account> ;
  sioc:has_container <https://lhero.org/#posts> ;
  content:encoded """<ul class="lh_portfolio-meta"><li><strong>Part of:</strong> <a href="https://lhero.org/portfolio/lh-crm/">LH Customer Relationship Management</a></li></ul>
<p class="wp-block-paragraph">Since 2.0.0, LH CRM keeps one network-wide table linking posts to the people they concern: <code>{base_prefix}lh_crm_people</code> (<code>lhero_lh_crm_people</code> on LocalHero). It records who an enquiry is from, and is the planned home for the members a committee note is about. The code is in <code>includes/lh-crm-people-class.php</code> (<code>LH_Crm_people_class</code>).</p>



<h2 class="wp-block-heading">Schema</h2>



<figure class="wp-block-table"><table><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>blog_id</code></td><td>bigint unsigned</td><td>Site the post belongs to</td></tr><tr><td><code>post_id</code></td><td>bigint unsigned</td><td>The post on that site</td></tr><tr><td><code>user_id</code></td><td>bigint unsigned</td><td>The person</td></tr><tr><td><code>relation</code></td><td>varchar(20)</td><td><code>enquirer</code> (enquiries) or <code>subject</code> (member notes). Filterable via <code>lh_crm_return_relations</code>.</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Primary key <code>(blog_id, post_id, user_id, relation)</code>, plus a <code>user_site (user_id, blog_id, relation)</code> index for &#8220;everything about this person on this site&#8221;. A post can have several people for one relation.</p>



<h2 class="wp-block-heading">Site scoping</h2>



<p class="wp-block-paragraph">Every row carries its <code>blog_id</code>, and every method of the API reads and writes for the current site only; code that needs another site switches to it first. This is what stops one organisation seeing another&#8217;s records. Reads are cached in the <code>lh_crm_people</code> group, invalidated by a last-changed key on every write.</p>



<ul class="wp-block-list"><li><code>LH_Crm_people_class::add( $post_id, $user_id, $relation )</code> and <code>set( $post_id, $user_ids, $relation )</code> (replaces the list; empty clears it)</li><li><code>get_user_ids( $post_id, $relation )</code> and <code>get_post_ids( $user_id, $relation )</code></li><li>For enquiries: <code>LH_Crm_enquiry_post_type_class::get_enquirer_id()</code>, <code>set_enquirer_id()</code> and <code>get_enquiry_ids_for_enquirer()</code></li></ul>



<h2 class="wp-block-heading">Install and backfill</h2>



<p class="wp-block-paragraph">The table is created with <code>dbDelta()</code> on <code>init</code> (and the hourly <code>lh_crm_wakeup</code> cron) whenever the network option <code>lh_crm_people_schema_version</code> differs from <code>LH_Crm_people_class::schema_version()</code>, never keyed on the plugin version. On each site, a one-off backfill then copies every existing enquiry&#8217;s <code>post_author</code> into the table as its enquirer (auto-drafts excluded) and records <code>lh_crm_people_backfill_version</code>. Until a site&#8217;s backfill has run, enquiry code there falls back to <code>post_author</code>, which is what it meant before 2.0.0. On LocalHero the backfill ran on 17 November 2026 for the four sites with enquiries.</p>



<h2 class="wp-block-heading">Cleanup and account merges</h2>



<figure class="wp-block-table"><table><thead><tr><th>Event</th><th>Hook</th><th>Effect</th></tr></thead><tbody><tr><td>Post deleted (not trashed)</td><td><code>before_delete_post</code></td><td>Its rows on that site are removed</td></tr><tr><td>Site deleted</td><td><code>wp_delete_site</code></td><td>All the site&#8217;s rows are removed</td></tr><tr><td>User removed from a site</td><td><code>deleted_user</code></td><td>Their rows on that site move to the user their content was reassigned to, or are removed</td></tr><tr><td>User deleted from the network</td><td><code>wpmu_delete_user</code></td><td>All their rows are removed</td></tr><tr><td>Accounts merged with LH User Identity</td><td><code>lh_user_identity_merge_handlers</code> (handler <code>lh_crm_people</code>)</td><td>One network-wide update moves the secondary account&#8217;s rows to the primary; where both were on the same post the duplicate is removed. The merge plan reports the number of rows.</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Why a table</h2>



<p class="wp-block-paragraph"><code>post_author</code> can only hold one person and also has to mean who created the post, so an enquiry entered by staff for someone else showed the wrong enquirer. Post meta cannot be queried efficiently per person across a network. A single network table keeps every link to a person in one place, which makes account merges one update and allows a per-person view across enquiries and notes.</p>
"""^^rdf:XMLLiteral ;
  sioc:content """Part of: LH Customer Relationship Management
Since 2.0.0, LH CRM keeps one network-wide table linking posts to the people they concern: {base_prefix}lh_crm_people (lhero_lh_crm_people on LocalHero). It records who an enquiry is from, and is the planned home for the members a committee note is about. The code is in includes/lh-crm-people-class.php (LH_Crm_people_class).



Schema



ColumnTypeDescriptionblog_idbigint unsignedSite the post belongs topost_idbigint unsignedThe post on that siteuser_idbigint unsignedThe personrelationvarchar(20)enquirer (enquiries) or subject (member notes). Filterable via lh_crm_return_relations.



Primary key (blog_id, post_id, user_id, relation), plus a user_site (user_id, blog_id, relation) index for &#8220;everything about this person on this site&#8221;. A post can have several people for one relation.



Site scoping



Every row carries its blog_id, and every method of the API reads and writes for the current site only; code that needs another site switches to it first. This is what stops one organisation seeing another&#8217;s records. Reads are cached in the lh_crm_people group, invalidated by a last-changed key on every write.



LH_Crm_people_class::add( $post_id, $user_id, $relation ) and set( $post_id, $user_ids, $relation ) (replaces the list; empty clears it)get_user_ids( $post_id, $relation ) and get_post_ids( $user_id, $relation )For enquiries: LH_Crm_enquiry_post_type_class::get_enquirer_id(), set_enquirer_id() and get_enquiry_ids_for_enquirer()



Install and backfill



The table is created with dbDelta() on init (and the hourly lh_crm_wakeup cron) whenever the network option lh_crm_people_schema_version differs from LH_Crm_people_class::schema_version(), never keyed on the plugin version. On each site, a one-off backfill then copies every existing enquiry&#8217;s post_author into the table as its enquirer (auto-drafts excluded) and records lh_crm_people_backfill_version. Until a site&#8217;s backfill has run, enquiry code there falls back to post_author, which is what it meant before 2.0.0. On LocalHero the backfill ran on 17 November 2026 for the four sites with enquiries.



Cleanup and account merges



EventHookEffectPost deleted (not trashed)before_delete_postIts rows on that site are removedSite deletedwp_delete_siteAll the site&#8217;s rows are removedUser removed from a sitedeleted_userTheir rows on that site move to the user their content was reassigned to, or are removedUser deleted from the networkwpmu_delete_userAll their rows are removedAccounts merged with LH User Identitylh_user_identity_merge_handlers (handler lh_crm_people)One network-wide update moves the secondary account&#8217;s rows to the primary; where both were on the same post the duplicate is removed. The merge plan reports the number of rows.



Why a table



post_author can only hold one person and also has to mean who created the post, so an enquiry entered by staff for someone else showed the wrong enquirer. Post meta cannot be queried efficiently per person across a network. A single network table keeps every link to a person in one place, which makes account merges one update and allows a per-person view across enquiries and notes.
""" ;
  sioc:topic <https://lhero.org/?taxonomy=author&term=cap-1> .

<https://lhero.org/author/1/#account> rdfs:seeAlso <https://lhero.org/author/1/?feed=lhrdf&format=turtle> .
<https://lhero.org/?taxonomy=author&term=cap-1> rdfs:seeAlso <https://lhero.org/?taxonomy=author&term=cap-1&feed=lhrdf&format=turtle> .
