From 53bb19704b1e99245b755caf2d573a4406066902 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Thu, 18 Jun 2026 21:25:38 +0100 Subject: Fix P01 name xref being wiped when saving type checkboxes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bulk DELETE of P*/B* xrefs was removing P01 (which carries the pipe-encoded name) whenever contact_types were saved. P01 is implied for all persons and never submitted as a checkbox, so it was never re-inserted. Fix handles P01 separately — always delete/rewrite it from pParamHash['name'] — and excludes it from the checkbox cycle. Co-Authored-By: Claude Sonnet 4.6 --- includes/classes/Contact.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/includes/classes/Contact.php b/includes/classes/Contact.php index 43ae07f..3423c0d 100755 --- a/includes/classes/Contact.php +++ b/includes/classes/Contact.php @@ -262,15 +262,25 @@ class Contact extends LibertyContent { $result = $this->mDb->associateInsert( $atable, $pParamHash['contact_store'] ); } if( !empty( $pParamHash['contact_types'] ) ) { - $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND (`item` STARTING WITH 'P' OR `item` STARTING WITH 'B')"; - $result = $this->mDb->query($query, [ $this->mContentId ] ); - foreach ( $pParamHash['contact_types'] as $key => $source ) { - if ( $source === 'P01' ) { - $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `xkey_ext`, `last_update_date`) VALUES ( ?, ?, ?, ?, NULL )"; - $result = $this->mDb->query($query, [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source, $pParamHash['name'] ] ); - } else { - $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `last_update_date`) VALUES ( ?, ?, ?, NULL )"; - $result = $this->mDb->query($query, [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source ] ); + // P01 carries the pipe-encoded name — always rewrite it independently of the checkbox set + $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND `item` = 'P01'", [ $this->mContentId ] ); + if( !empty( $pParamHash['name'] ) ) { + $this->mDb->query( + "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `xkey_ext`, `last_update_date`) VALUES (?, ?, 'P01', ?, NULL)", + [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $pParamHash['name'] ] + ); + } + // Optional type tags (P02+, B01+) come from the form checkboxes + $this->mDb->query( + "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND (`item` STARTING WITH 'P' OR `item` STARTING WITH 'B') AND `item` <> 'P01'", + [ $this->mContentId ] + ); + foreach ( $pParamHash['contact_types'] as $source ) { + if ( $source !== 'P01' ) { + $this->mDb->query( + "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `last_update_date`) VALUES (?, ?, ?, NULL)", + [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source ] + ); } } } -- cgit v1.3