diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-06 17:22:44 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-06 17:22:44 +0100 |
| commit | 85add8e6c0fa75baeeee342e6e36051faf923e5c (patch) | |
| tree | 7340f76fa36f98e0be0837873aa4e3875cb8270f /import/ImportAssembly.php | |
| parent | 4f2819cc35eaa740dd1b806b038cf95d50d9052f (diff) | |
| download | stock-85add8e6c0fa75baeeee342e6e36051faf923e5c.tar.gz stock-85add8e6c0fa75baeeee342e6e36051faf923e5c.tar.bz2 stock-85add8e6c0fa75baeeee342e6e36051faf923e5c.zip | |
import: cull legacy importers; move data to storage/stock/
Remove old ImportAssembly/Component classes, load_stock, load_components,
load_assemblies, load_kitlocker_assemblies/groups (one-off imports).
Add STOCK_IMPORT_PATH = STORAGE_PKG_PATH.'stock/' to bit_setup_inc.
Update load_simple_assemblies/components/components_2 to use
STOCK_IMPORT_PATH instead of __DIR__.'/data/'.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'import/ImportAssembly.php')
| -rw-r--r-- | import/ImportAssembly.php | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/import/ImportAssembly.php b/import/ImportAssembly.php deleted file mode 100644 index a42e320..0000000 --- a/import/ImportAssembly.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -/** - * Stock assembly / BOM CSV import record loader. - * - * CSV column layout (0-based): - * 0 assembly_title Kit / assembly name - * 1 component_title Component name (must already exist as a stockcomponent content item) - * 2 quantity_value Numeric quantity in BOM (optional, default 1) - * 3 quantity_item SGL / PCK / SHT / VOL (optional, default SGL) - * 4 item_position Float position (e.g. 1.1, 1.2, 2.1) (optional) - * - * Rows are grouped by assembly_title. The assembly record is created once - * the first time a new title is seen; subsequent rows with the same title - * add further BOM lines to it. - * - * @package stock - */ - -use Bitweaver\Stock\StockAssembly; -use Bitweaver\Liberty\LibertyContent; - -/** - * Process a batch of rows for a single assembly. - * $pRows is an array of raw CSV row arrays, all sharing the same assembly_title. - */ -function StockAssemblyBatchLoad( string $assemblyTitle, array $pRows ): array { - $result = [ 'loaded' => 0, 'skipped' => 0, 'errors' => [] ]; - - // Create or find the assembly - $assembly = new StockAssembly(); - $pHash = [ - 'title' => $assemblyTitle, - 'format_guid' => 'plain', - 'rows_per_page'=> 5, - 'cols_per_page'=> 3, - ]; - if( !$assembly->store( $pHash ) ) { - $result['errors'][] = "Failed to create assembly: $assemblyTitle"; - $result['skipped'] += count( $pRows ); - return $result; - } - - foreach( $pRows as $rowNum => $data ) { - $componentTitle = trim( $data[1] ?? '' ); - if( empty( $componentTitle ) ) { - $result['skipped']++; - $result['errors'][] = "Row $rowNum: empty component title."; - continue; - } - - // Look up component by title - $componentContentId = _stockImportFindComponent( $componentTitle ); - if( !$componentContentId ) { - $result['skipped']++; - $result['errors'][] = "Row $rowNum: component not found — '$componentTitle'"; - continue; - } - - $qtyValue = isset( $data[2] ) && is_numeric( trim($data[2]) ) ? (float)trim( $data[2] ) : 1.0; - $qtySrc = strtoupper( trim( $data[3] ?? 'SGL' ) ); - if( !in_array( $qtySrc, [ 'SGL', 'PCK', 'SHT', 'VOL' ] ) ) { - $qtySrc = 'SGL'; - } - $position = isset( $data[4] ) && is_numeric( trim($data[4]) ) ? (float)trim( $data[4] ) : null; - - // Insert BOM row directly — addItem() handles the assembly_content_id reference - $assembly->addItem( $componentContentId, $position ); - - // Update quantity_value and quantity_item on the map row just inserted - global $gBitDb; - $gBitDb->query( - "UPDATE `".BIT_DB_PREFIX."stock_assembly_map` - SET `quantity_value` = ?, `quantity_item` = ? - WHERE `assembly_content_id` = ? AND `item_content_id` = ?", - [ $qtyValue, $qtySrc, $assembly->mContentId, $componentContentId ] - ); - - $result['loaded']++; - } - - return $result; -} - -/** Finds a component's content_id by exact title match. */ -function _stockImportFindComponent( string $title ): ?int { - global $gBitDb; - $contentId = $gBitDb->getOne( - "SELECT lc.`content_id` - FROM `".BIT_DB_PREFIX."liberty_content` lc - WHERE lc.`content_type_guid` = '".STOCKCOMPONENT_CONTENT_TYPE_GUID."' AND lc.`title` = ?", - [ $title ] - ); - return $contentId ? (int)$contentId : null; -} |
