summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-03 12:32:21 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-03 12:32:21 +0100
commit505aee3fe652577cd7fd2a62e3563446228133af (patch)
treedbe9bf18f5e2ea1d820424187e3523b6800acadd
parent390f1533a283a584048ecc2a17a110d818af69ea (diff)
downloadstock-505aee3fe652577cd7fd2a62e3563446228133af.tar.gz
stock-505aee3fe652577cd7fd2a62e3563446228133af.tar.bz2
stock-505aee3fe652577cd7fd2a62e3563446228133af.zip
stock: look up kitlocker parent by title, not hardcoded ID
Hardcoded assembly_id=21 breaks on any DB rebuild. Look up the 'kitlocker' assembly by title so re-running the import on any server wires up the parent links correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--import/load_kitlocker_groups.php24
1 files changed, 14 insertions, 10 deletions
diff --git a/import/load_kitlocker_groups.php b/import/load_kitlocker_groups.php
index 202b917..96333e7 100644
--- a/import/load_kitlocker_groups.php
+++ b/import/load_kitlocker_groups.php
@@ -23,20 +23,24 @@ $gBitSystem->verifyPermission( 'p_stock_admin' );
require_once STOCK_PKG_CLASS_PATH.'StockAssembly.php';
-$csvFile = __DIR__.'/data/KitlockerGroups.csv';
-$parentAssemblyId = 21;
-$loaded = $skipped = $linked = 0;
-$errors = [];
+$csvFile = __DIR__.'/data/KitlockerGroups.csv';
+$loaded = $skipped = $linked = 0;
+$errors = [];
-// Load parent assembly and verify it actually exists in the DB
-$parent = new StockAssembly( $parentAssemblyId, null );
-$parent->load();
-if( !$parent->isValid() || empty( $parent->mContentId ) ) {
- $errors[] = "Parent assembly $parentAssemblyId not found or has no content_id.";
+// Find the kitlocker parent assembly by title
+$parentContentId = (int)$gBitDb->getOne(
+ "SELECT lc.content_id FROM `".BIT_DB_PREFIX."liberty_content` lc
+ WHERE lc.content_type_guid='stockassembly' AND LOWER(lc.title)='kitlocker'"
+);
+
+$parent = $parentContentId ? new StockAssembly( null, $parentContentId ) : new StockAssembly();
+if( $parentContentId ) $parent->load();
+
+if( !$parentContentId || !$parent->isValid() || empty( $parent->mContentId ) ) {
+ $errors[] = "Parent assembly 'kitlocker' not found — create it first.";
} elseif( !file_exists( $csvFile ) ) {
$errors[] = "File not found: $csvFile";
} else {
- $parentContentId = $parent->mContentId;
$fh = fopen( $csvFile, 'r' );
$rowNum = 0;
while( ($cols = fgetcsv( $fh, 0, ',', '"', '' )) !== false ) {