summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-22 14:20:29 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-22 14:20:29 +0100
commite0eebe88f2213f65353ec7045a8188738a15f428 (patch)
treec4714d8fe9d682e47e73a721e5e8601c30582b18
parente22c4ac772181cd7caab88b349b1ab6ae0ca8eb4 (diff)
downloadliberty-e0eebe88f2213f65353ec7045a8188738a15f428.tar.gz
liberty-e0eebe88f2213f65353ec7045a8188738a15f428.tar.bz2
liberty-e0eebe88f2213f65353ec7045a8188738a15f428.zip
Add mContentTypeGuid scoping to LibertyXref for multi-package isolation
LibertyXref gains a $mContentTypeGuid property (default empty) used to filter the liberty_xref_source JOIN in load() and the multi-check in verify(). Subclasses set it to scope queries to their content type without duplicating any logic. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--includes/classes/LibertyXref.php13
-rw-r--r--includes/classes/LibertyXrefType.php6
2 files changed, 12 insertions, 7 deletions
diff --git a/includes/classes/LibertyXref.php b/includes/classes/LibertyXref.php
index 244f93a..44e874c 100644
--- a/includes/classes/LibertyXref.php
+++ b/includes/classes/LibertyXref.php
@@ -15,6 +15,7 @@ class LibertyXref extends LibertyBase {
public $mXrefId;
public $mContentId;
public $mDate;
+ protected $mContentTypeGuid = '';
public function __construct( $iXrefId = NULL ) {
$this->mXrefId = NULL;
@@ -34,6 +35,8 @@ class LibertyXref extends LibertyBase {
public function load( $pXrefId = NULL ) {
if( BitBase::verifyId( $pXrefId ) ) {
+ $guidFilter = !empty( $this->mContentTypeGuid ) ? "AND s.`content_type_guid` = ?" : '';
+ $bindVars = !empty( $this->mContentTypeGuid ) ? [ $this->mContentTypeGuid, $pXrefId ] : [ $pXrefId ];
$sql = "SELECT x.*, CASE
WHEN x.`xorder` = 0 THEN s.`cross_ref_title`
ELSE s.`cross_ref_title` || '-' || x.`xorder` END
@@ -42,10 +45,10 @@ class LibertyXref extends LibertyBase {
CASE WHEN x.`end_date` IS NULL THEN 'y' ELSE 'n' END AS `ignore_end_date`,
s.`cross_ref_title` AS `template_title`, s.`template`
FROM `".BIT_DB_PREFIX."liberty_xref` x
- JOIN `".BIT_DB_PREFIX."liberty_xref_source` s ON s.`source` = x.`source`
+ JOIN `".BIT_DB_PREFIX."liberty_xref_source` s ON s.`source` = x.`source` $guidFilter
WHERE x.`xref_id` = ?
ORDER BY x.`xorder`";
- $result = $this->mDb->getRow( $sql, [ $pXrefId ] );
+ $result = $this->mDb->getRow( $sql, $bindVars );
if( $result['content_id'] ) {
$this->mXrefId = $pXrefId;
$this->mContentId = $result['content_id'];
@@ -74,8 +77,10 @@ class LibertyXref extends LibertyBase {
if( isset( $pParamHash['fAddXref'] ) ) {
$pParamHash['xref_store']['source'] = isset( $pParamHash['Array_xref_type_list'] ) ? $pParamHash['Array_xref_type_list']['Array.source'] : $pParamHash['source'];
$pParamHash['xref_store']['content_id'] = $pParamHash['content_id'];
- $sql = "SELECT x.`multi` FROM `".BIT_DB_PREFIX."liberty_xref_source` x WHERE x.`source` = ?";
- $next = $this->mDb->getOne( $sql, [ $pParamHash['xref_store']['source'] ] );
+ $guidWhere = !empty( $this->mContentTypeGuid ) ? "AND x.`content_type_guid` = ?" : '';
+ $guidBind = !empty( $this->mContentTypeGuid ) ? [ $pParamHash['xref_store']['source'], $this->mContentTypeGuid ] : [ $pParamHash['xref_store']['source'] ];
+ $sql = "SELECT x.`multi` FROM `".BIT_DB_PREFIX."liberty_xref_source` x WHERE x.`source` = ? $guidWhere";
+ $next = $this->mDb->getOne( $sql, $guidBind );
if( $next > 0 ) {
$sql = "SELECT COALESCE( MAX(x.`xorder`) + 1, 1 ) FROM `".BIT_DB_PREFIX."liberty_xref` x WHERE x.`content_id` = ? AND x.`source` = ?";
$next = $this->mDb->getOne( $sql, [ $pParamHash['xref_store']['content_id'], $pParamHash['xref_store']['source'] ] );
diff --git a/includes/classes/LibertyXrefType.php b/includes/classes/LibertyXrefType.php
index 28ff4bb..321db07 100644
--- a/includes/classes/LibertyXrefType.php
+++ b/includes/classes/LibertyXrefType.php
@@ -20,9 +20,9 @@ class LibertyXrefType extends LibertyBase {
$where = '';
$bindVars = [];
- if( !empty( $pOptionHash['package'] ) ) {
- $where = " WHERE cxs.`package` = ? ";
- $bindVars[] = $pOptionHash['package'];
+ if( !empty( $pOptionHash['content_type_guid'] ) ) {
+ $where = " WHERE cxs.`content_type_guid` = ? ";
+ $bindVars[] = $pOptionHash['content_type_guid'];
}
if( !empty( $pOptionHash['active_role'] ) ) {
$where = " WHERE cxs.`role_id` = ? ";