diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-31 10:06:48 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-31 10:06:48 +0100 |
| commit | cef2bbde0cbaa042a545f432865de11e0bc51d03 (patch) | |
| tree | 53315ea10db725ec3b99ca31c7c016b0b60f89f6 /includes | |
| parent | 693acd68d2dcdbfd700a3aab6c49251552cc9be0 (diff) | |
| download | stock-cef2bbde0cbaa042a545f432865de11e0bc51d03.tar.gz stock-cef2bbde0cbaa042a545f432865de11e0bc51d03.tar.bz2 stock-cef2bbde0cbaa042a545f432865de11e0bc51d03.zip | |
Remove stock_component table — use liberty_content directly
stock_component was a pure alias (component_id ↔ content_id with no
other data). All queries now target liberty_content WHERE
content_type_guid = STOCKCOMPONENT_CONTENT_TYPE_GUID directly.
- StockComponent: drop mComponentId, constructor takes content_id only
- All component_id URL params changed to content_id
- Import files, edit_movement, sitemap updated to match
- BOM xref templates updated (xref column migrated from component_id
to content_id in live DB — 130 rows)
- StockAssembly loadXrefList/enrichXrefDisplay join liberty_content
directly; loadComponents drops stock_component LEFT JOIN
- StockBase: previous/next keys renamed to _content_id
stock_component table left in schema_inc.php pending DB reset.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
| -rwxr-xr-x | includes/classes/StockAssembly.php | 19 | ||||
| -rwxr-xr-x | includes/classes/StockBase.php | 6 | ||||
| -rwxr-xr-x | includes/classes/StockComponent.php | 122 | ||||
| -rwxr-xr-x | includes/component_lookup_inc.php | 27 |
4 files changed, 49 insertions, 125 deletions
diff --git a/includes/classes/StockAssembly.php b/includes/classes/StockAssembly.php index 59e946c..2b628eb 100755 --- a/includes/classes/StockAssembly.php +++ b/includes/classes/StockAssembly.php @@ -78,10 +78,9 @@ class StockAssembly extends StockBase { if( !empty( $pXrefInfo['xref'] ) ) { if( $comp = $this->mDb->getRow( "SELECT lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext` - FROM `".BIT_DB_PREFIX."stock_component` sc - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = sc.`content_id` - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = sc.`content_id` AND pck.`item` = 'PCK' - WHERE sc.`component_id` = ?", + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = lc.`content_id` AND pck.`item` = 'PCK' + WHERE lc.`content_id` = ?", [ (int)$pXrefInfo['xref'] ] ) ) { $pXrefInfo['xref_title'] = $comp['title']; @@ -101,11 +100,10 @@ class StockAssembly extends StockBase { if( $componentIds ) { $placeholders = implode( ',', array_fill( 0, count( $componentIds ), '?' ) ); $components = $this->mDb->getAssoc( - "SELECT sc.`component_id`, lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext` - FROM `".BIT_DB_PREFIX."stock_component` sc - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = sc.`content_id` - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = sc.`content_id` AND pck.`item` = 'PCK' - WHERE sc.`component_id` IN ($placeholders)", + "SELECT lc.`content_id`, lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext` + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = lc.`content_id` AND pck.`item` = 'PCK' + WHERE lc.`content_id` IN ($placeholders)", $componentIds ); foreach( $this->mInfo['quantity'] as &$row ) { @@ -309,11 +307,10 @@ class StockAssembly extends StockBase { $this->mItems = []; - $query = "SELECT lc.`content_id` AS `has_key`, fgim.*, lc.*, lct.*, fi.`component_id`, ufm.`favorite_content_id` AS is_favorite $selectSql + $query = "SELECT lc.`content_id` AS `has_key`, fgim.*, lc.*, lct.*, ufm.`favorite_content_id` AS is_favorite $selectSql FROM `".BIT_DB_PREFIX."stock_assembly_component_map` fgim INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id`=fgim.`item_content_id` ) INNER JOIN `".BIT_DB_PREFIX."liberty_content_types` lct ON ( lct.`content_type_guid`=lc.`content_type_guid` ) - LEFT OUTER JOIN `".BIT_DB_PREFIX."stock_component` fi ON ( fgim.`item_content_id`=fi.`content_id` ) $joinSql LEFT OUTER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON ( ufm.`favorite_content_id`=lc.`content_id` AND lc.`user_id`=ufm.`user_id` ) WHERE fgim.`assembly_content_id` = ? $whereSql diff --git a/includes/classes/StockBase.php b/includes/classes/StockBase.php index 8519f99..a6b6e9c 100755 --- a/includes/classes/StockBase.php +++ b/includes/classes/StockBase.php @@ -103,12 +103,12 @@ abstract class StockBase extends LibertyContent if ( $parents['pre_t'] == 'stockassembly' ) { $ret['previous_gallery_id'] = $parents['previous']; } else { - $ret['previous_component_id'] = $parents['previous']; + $ret['previous_content_id'] = $parents['previous']; } if ( $parents['next_t'] == 'stockassembly' ) { $ret['next_gallery_id'] = $parents['next']; - }else { - $ret['next_component_id'] = $parents['previous']; + } else { + $ret['next_content_id'] = $parents['next']; } } } diff --git a/includes/classes/StockComponent.php b/includes/classes/StockComponent.php index 3bff170..211e1e7 100755 --- a/includes/classes/StockComponent.php +++ b/includes/classes/StockComponent.php @@ -17,13 +17,11 @@ define('STOCKCOMPONENT_CONTENT_TYPE_GUID', 'stockcomponent'); * @package stock */ class StockComponent extends StockBase { - public $mComponentId; protected $mXrefTypeKey = 'stockcomponent_types'; - public function __construct($pComponentId = null, $pContentId = null) { + public function __construct($pContentId = null) { parent::__construct(); $this->mContentTypeGuid = STOCKCOMPONENT_CONTENT_TYPE_GUID; - $this->mComponentId = (int)$pComponentId; $this->mContentId = (int)$pContentId; $this->registerContentType( @@ -44,32 +42,14 @@ class StockComponent extends StockBase { $this->mAdminContentPerm = 'p_stock_admin'; } - public function __sleep() { - return array_merge( parent::__sleep(), [ 'mComponentId' ] ); - } - public static function lookup( $pLookupHash ) { - global $gBitDb; $ret = null; - $lookupContentId = null; - if( !empty($pLookupHash['component_id']) && is_numeric($pLookupHash['component_id']) ) { - if( $lookup = $gBitDb->getRow( - "SELECT lc.`content_id`, lc.`content_type_guid` FROM `".BIT_DB_PREFIX."stock_component` fi - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id`=fi.`content_id`) - WHERE `component_id`=?", - [ $pLookupHash['component_id'] ] - ) ) { - $lookupContentId = $lookup['content_id']; - $lookupContentGuid = $lookup['content_type_guid']; - } - } elseif( !empty($pLookupHash['content_id']) && is_numeric($pLookupHash['content_id']) ) { - $lookupContentId = $pLookupHash['content_id']; - $lookupContentGuid = null; + if( !empty($pLookupHash['content_id']) && is_numeric($pLookupHash['content_id']) ) { + $lookupContentId = (int)$pLookupHash['content_id']; } - if( static::verifyId( $lookupContentId ) ) { - $ret = static::getLibertyObject( $lookupContentId, $lookupContentGuid ); + $ret = static::getLibertyObject( $lookupContentId, STOCKCOMPONENT_CONTENT_TYPE_GUID ); } return $ret; } @@ -79,26 +59,19 @@ class StockComponent extends StockBase { $selectSql = $joinSql = $whereSql = ''; $bindVars = []; - if( @$this->verifyId( $this->mComponentId ) ) { - $whereSql = " WHERE fi.`component_id` = ?"; - $bindVars[] = $this->mComponentId; - } elseif( @$this->verifyId( $this->mContentId ) ) { - $whereSql = " WHERE fi.`content_id` = ?"; - $bindVars[] = $this->mContentId; - } + $whereSql = " WHERE lc.`content_id` = ? AND lc.`content_type_guid` = '".STOCKCOMPONENT_CONTENT_TYPE_GUID."'"; + $bindVars[] = $this->mContentId; $this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars ); - $sql = "SELECT fi.*, lc.* $selectSql + $sql = "SELECT lc.* $selectSql , uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name` , uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name` - FROM `".BIT_DB_PREFIX."stock_component` fi - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id` = fi.`content_id`) + FROM `".BIT_DB_PREFIX."liberty_content` lc LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`) LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON (uuc.`user_id` = lc.`user_id`) $joinSql $whereSql"; if( $this->mInfo = $this->mDb->getRow( $sql, $bindVars ) ) { - $this->mComponentId = $this->mInfo['component_id']; $this->mContentId = $this->mInfo['content_id']; $this->mContentTypeGuid = $this->mInfo['content_type_guid']; $this->mInfo['creator'] = $this->mInfo['creator_real_name'] ?? $this->mInfo['creator_user']; @@ -126,16 +99,8 @@ class StockComponent extends StockBase { if( $this->verifyComponentData( $pParamHash ) ) { $this->StartTrans(); if( LibertyContent::store( $pParamHash ) ) { - $this->mContentId = $pParamHash['content_id']; + $this->mContentId = $pParamHash['content_id']; $this->mInfo['content_id'] = $this->mContentId; - if( !$this->componentExistsInDatabase() ) { - $this->mComponentId = $this->mDb->GenID('stock_component_id_seq'); - $this->mInfo['component_id'] = $this->mComponentId; - $this->mDb->getOne( - "INSERT INTO `".BIT_DB_PREFIX."stock_component` (`component_id`, `content_id`) VALUES (?,?)", - [ $this->mComponentId, $this->mContentId ] - ); - } $this->CompleteTrans(); } else { $this->mDb->RollbackTrans(); @@ -148,12 +113,9 @@ class StockComponent extends StockBase { if( $this->isValid() ) { $this->StartTrans(); $this->mDb->getOne( "DELETE FROM `".BIT_DB_PREFIX."stock_assembly_component_map` WHERE `item_content_id` = ?", [ $this->mContentId ] ); - $this->mDb->getOne( "UPDATE `".BIT_DB_PREFIX."stock_assembly` SET `preview_content_id`=null WHERE `preview_content_id` = ?", [ $this->mContentId ] ); - $this->mDb->getOne( "DELETE FROM `".BIT_DB_PREFIX."stock_component` WHERE `content_id` = ?", [ $this->mContentId ] ); if( LibertyContent::expunge() ) { $this->CompleteTrans(); - $this->mComponentId = null; - $this->mContentId = null; + $this->mContentId = null; } else { $this->mDb->RollbackTrans(); } @@ -162,28 +124,7 @@ class StockComponent extends StockBase { } public function isValid() { - return @$this->verifyId( $this->mComponentId ) || @$this->verifyId( $this->mContentId ); - } - - public function isLocked(): bool { - $ret = false; - if( $this->verifyId( $this->mComponentId ) ) { - if( empty( $this->mInfo ) ) { - $this->load(); - } - $ret = (bool)$this->getField( 'flag', false ); - } - return $ret; - } - - public function componentExistsInDatabase(): bool { - if( $this->isValid() && $this->mComponentId ) { - return $this->mDb->getOne( - "SELECT COUNT(`component_id`) FROM `".BIT_DB_PREFIX."stock_component` WHERE `component_id` = ?", - [ $this->mComponentId ] - ) > 0; - } - return false; + return @$this->verifyId( $this->mContentId ); } public function getList( &$pListHash ) { @@ -193,14 +134,16 @@ class StockComponent extends StockBase { $ret = $bindVars = []; $selectSql = $whereSql = $joinSql = ''; + $whereSql .= " AND lc.`content_type_guid` = '".STOCKCOMPONENT_CONTENT_TYPE_GUID."'"; + if( @$this->verifyId( $pListHash['user_id'] ?? 0 ) ) { $whereSql .= " AND lc.`user_id` = ? "; $bindVars[] = (int)$pListHash['user_id']; } - if( @$this->verifyId( $pListHash['assembly_id'] ?? 0 ) ) { - $whereSql .= " AND fg.`assembly_id` = ? "; - $bindVars[] = (int)$pListHash['assembly_id']; + if( @$this->verifyId( $pListHash['assembly_content_id'] ?? 0 ) ) { + $whereSql .= " AND tfgim2.`assembly_content_id` = ? "; + $bindVars[] = (int)$pListHash['assembly_content_id']; } if( !empty( $pListHash['search'] ) ) { @@ -221,27 +164,22 @@ class StockComponent extends StockBase { } $pListHash['cant'] = (int)$this->mDb->getOne( - "SELECT COUNT(DISTINCT fi.`component_id`) - FROM `".BIT_DB_PREFIX."stock_component` fi - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (fi.`content_id` = lc.`content_id`) + "SELECT COUNT(DISTINCT lc.`content_id`) + FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (uu.`user_id` = lc.`user_id`) $joinSql LEFT OUTER JOIN `".BIT_DB_PREFIX."stock_assembly_component_map` tfgim2 ON (tfgim2.`item_content_id`=lc.`content_id`) - LEFT OUTER JOIN `".BIT_DB_PREFIX."stock_assembly` fg ON (fg.`content_id`=tfgim2.`assembly_content_id`) $whereSql", $bindVars ); - $query = "SELECT fi.`component_id` AS `hash_key`, fi.*, lc.*, fg.`assembly_id`, uu.`login`, uu.`real_name` $selectSql - FROM `".BIT_DB_PREFIX."stock_component` fi - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (fi.`content_id` = lc.`content_id`) + $query = "SELECT lc.`content_id` AS `hash_key`, lc.*, uu.`login`, uu.`real_name` $selectSql + FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (uu.`user_id` = lc.`user_id`) $joinSql LEFT OUTER JOIN `".BIT_DB_PREFIX."stock_assembly_component_map` tfgim2 ON (tfgim2.`item_content_id`=lc.`content_id`) - LEFT OUTER JOIN `".BIT_DB_PREFIX."stock_assembly` fg ON (fg.`content_id`=tfgim2.`assembly_content_id`) $whereSql $orderby"; if( $rows = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ) ) { foreach( $rows as $row ) { - $row['hash_key'] = $row['component_id']; - $row['display_url'] = static::getDisplayUrlFromHash( $row ); + $row['display_url'] = static::getDisplayUrlFromHash( $row ); $ret[$row['hash_key']] = $row; } } @@ -256,25 +194,19 @@ class StockComponent extends StockBase { public static function getDisplayUrlFromHash( &$pParamHash ) { global $gBitSystem; $ret = ''; - if( BitBase::verifyId( $pParamHash['component_id'] ?? 0 ) ) { - $ret = $gBitSystem->isFeatureActive( 'pretty_urls' ) - ? STOCK_PKG_URL.'component/'.$pParamHash['component_id'] - : STOCK_PKG_URL.'view_component.php?component_id='.$pParamHash['component_id']; - } elseif( BitBase::verifyId( $pParamHash['content_id'] ?? 0 ) ) { + if( BitBase::verifyId( $pParamHash['content_id'] ?? 0 ) ) { $ret = STOCK_PKG_URL.'view_component.php?content_id='.$pParamHash['content_id']; } return $ret; } public function getDisplayUrl() { - $info = &$this->mInfo; - $info['component_id'] = $this->mComponentId; - return static::getDisplayUrlFromHash( $info ); + return static::getDisplayUrlFromHash( $this->mInfo ); } public function getEditUrl( $pContentId = null, $pMixed = null ): string { - if( $this->verifyId( $this->mComponentId ) ) { - return STOCK_PKG_URL.'edit_component.php?component_id='.$this->mComponentId; + if( $this->verifyId( $this->mContentId ) ) { + return STOCK_PKG_URL.'edit_component.php?content_id='.$this->mContentId; } return STOCK_PKG_URL.'edit_component.php'; } @@ -297,8 +229,8 @@ class StockComponent extends StockBase { if( empty( $ret ) && $pDefault ) { global $gLibertySystem; $ret = $gLibertySystem->getContentTypeName( $pHash['content_type_guid'] ?? 'empty' ); - if( !empty( $pHash['component_id'] ) ) { - $ret .= ' '.$pHash['component_id']; + if( !empty( $pHash['content_id'] ) ) { + $ret .= ' '.$pHash['content_id']; } } return $ret; diff --git a/includes/component_lookup_inc.php b/includes/component_lookup_inc.php index b6391df..c3d02c6 100755 --- a/includes/component_lookup_inc.php +++ b/includes/component_lookup_inc.php @@ -1,6 +1,5 @@ <?php /** - * @version $Header$ * @package stock * @subpackage functions */ @@ -8,35 +7,31 @@ global $gContent, $gGallery; use \Bitweaver\Stock\StockComponent; use \Bitweaver\Stock\StockAssembly; + $gContent = new StockComponent( - !empty( $_REQUEST['component_id'] ) ? (int)$_REQUEST['component_id'] : null, - !empty( $_REQUEST['content_id'] ) ? (int)$_REQUEST['content_id'] : null + !empty( $_REQUEST['content_id'] ) ? (int)$_REQUEST['content_id'] : null ); $gContent->load(); if( !empty( $_REQUEST['gallery_path'] ) ) { $_REQUEST['gallery_path'] = rtrim( $_REQUEST['gallery_path'], '/' ); $gContent->setGalleryPath( $_REQUEST['gallery_path'] ); - $matches = []; $tail = strrpos( $_REQUEST['gallery_path'], '/' ); - $_REQUEST['assembly_id'] = substr( $_REQUEST['gallery_path'], $tail + 1 ); + $_REQUEST['assembly_content_id'] = substr( $_REQUEST['gallery_path'], $tail + 1 ); } -if( empty( $_REQUEST['assembly_id'] ) ) { +if( empty( $_REQUEST['assembly_content_id'] ) ) { if( $parents = $gContent->getParentAssemblies() ) { $gal = current( $parents ); - $gContent->setGalleryPath( '/'.$gal['assembly_id'] ); - $_REQUEST['assembly_id'] = $gal['assembly_id']; + $gContent->setGalleryPath( '/'.$gal['content_id'] ); + $_REQUEST['assembly_content_id'] = $gal['content_id']; } } -// the image is considered the primary content, however the gallery is useful -if( !empty($_REQUEST['assembly_id']) && is_numeric($_REQUEST['assembly_id']) ) { - $gGallery = StockAssembly::lookup( $_REQUEST ); -$gBitSmarty->assign('gGallery', $gGallery); - $gBitSmarty->assign('assemblyId', $_REQUEST['assembly_id']); +if( !empty($_REQUEST['assembly_content_id']) && is_numeric($_REQUEST['assembly_content_id']) ) { + $gGallery = StockAssembly::lookup( [ 'content_id' => (int)$_REQUEST['assembly_content_id'] ] ); + $gBitSmarty->assign( 'gGallery', $gGallery ); + $gBitSmarty->assign( 'assemblyContentId', $_REQUEST['assembly_content_id'] ); } -// This user does not own this gallery and they have not been granted the permission to edit this gallery $gContent->verifyViewPermission(); -$gBitSmarty->assign('gContent', $gContent); -$gBitSmarty->assign('imageId', $gContent->mComponentId ); +$gBitSmarty->assign( 'gContent', $gContent ); |
