bagisto-data-transfer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseData Transfer
数据传输
packages/Webkul/DataTransferImport only. There is no exporter here; a DataGrid's own export handles
outbound data — see the skill.
bagisto-datagrid-developmentpackages/Webkul/DataTransfer仅支持导入。此包不包含导出功能;数据导出由 DataGrid 自身的导出功能处理——详情请参考 技能文档。
bagisto-datagrid-developmentReference files
参考文件
| File | Load when |
|---|---|
| importers.md | Writing or changing an Importer — the contract, validation, batches |
| pipeline.md | The state machine, queued jobs, and debugging a stuck import |
| 文件 | 适用场景 |
|---|---|
| importers.md | 编写或修改 Importer 类——包括契约、验证、批量处理逻辑 |
| pipeline.md | 状态机、队列任务,以及调试卡住的导入流程 |
The registry
注册表
An importer is registered in , merged into the top-level
key (not ):
Config/importers.phpimportersdata_transfer.importersphp
'tax_rates' => [
'title' => 'data_transfer::app.importers.tax-rates.title',
'importer' => 'Webkul\DataTransfer\Helpers\Importers\TaxRate\Importer',
'sample_paths' => [
'csv' => 'bagisto-data-transfer/samples/csv/tax-rates.csv',
'xls' => 'bagisto-data-transfer/samples/xls/tax-rates.xls',
'xlsx' => 'bagisto-data-transfer/samples/xlsx/tax-rates.xlsx',
'xml' => 'bagisto-data-transfer/samples/xml/tax-rates.xml',
],
],The admin create/edit screens iterate directly, so a new
entry appears in the type dropdown with no view change. resolves the
class with — the array key is the
stored on the import record, so renaming a key orphans existing imports.
config('importers')Importconfig('importers.'.$type.'.importer')typeProvide all four sample paths. The UI offers a sample download per format, and a
missing file is a broken link rather than a graceful fallback.
导入器需在 中注册,并合并到顶层的 键下(而非 ):
Config/importers.phpimportersdata_transfer.importersphp
'tax_rates' => [
'title' => 'data_transfer::app.importers.tax-rates.title',
'importer' => 'Webkul\DataTransfer\Helpers\Importers\TaxRate\Importer',
'sample_paths' => [
'csv' => 'bagisto-data-transfer/samples/csv/tax-rates.csv',
'xls' => 'bagisto-data-transfer/samples/xls/tax-rates.xls',
'xlsx' => 'bagisto-data-transfer/samples/xlsx/tax-rates.xlsx',
'xml' => 'bagisto-data-transfer/samples/xml/tax-rates.xml',
],
],后台的创建/编辑页面会直接遍历 ,因此新增的条目会直接显示在类型下拉菜单中,无需修改视图。 类通过 解析对应的导入器类——数组的键会作为导入记录的 字段存储,因此修改键名会导致现有导入记录失效。
config('importers')Importconfig('importers.'.$type.'.importer')type需提供全部四种格式的示例文件路径。UI 会为每种格式提供示例文件下载链接,若文件缺失会导致链接失效,而非优雅降级。
The importer contract
导入器契约
Extend and implement exactly two methods:
Helpers\Importers\AbstractImporterphp
abstract public function validateRow(array $rowData, int $rowNumber): bool;
abstract public function importBatch(ImportBatchContract $importBatchContract): bool;Everything else is declared as properties — ,
, , — or overridden as
hooks. See importers.md.
$validColumnNames$masterAttributeCode$permanentAttributes$messages需继承 并实现以下两个方法:
Helpers\Importers\AbstractImporterphp
abstract public function validateRow(array $rowData, int $rowNumber): bool;
abstract public function importBatch(ImportBatchContract $importBatchContract): bool;其余逻辑均通过属性声明——如 、、、——或重写钩子方法实现。详情请参考 importers.md。
$validColumnNames$masterAttributeCode$permanentAttributes$messagesSources
数据源
Helpers\Sources\CSVXLSXLSXXMLAbstractSourcegenerateErrorReport(array $errors)$this->sourceHelpers\Sources\CSVXLSXLSXXMLAbstractSourcegenerateErrorReport(array $errors)$this->sourceNon-negotiables
硬性要求
- Rows are validated before anything is written. must be free of side effects: it runs over the whole file, and on
validateRow()the import may never reachstop-on-errors.importBatch() - Work in batches, never row-by-row over the whole file.
is 100 and the pipeline dispatches one job per batch. An importer that loads the file into memory defeats the design and fails on the file sizes this feature exists for.
AbstractImporter::BATCH_SIZE - Go through repositories for writes, as everywhere else in Bagisto.
- Every message goes through in the
trans()namespace, in all 22 locales.data_transfer:: - Declare /
isLinkingRequired()honestly. Returning true adds a queued stage per batch; returning false when linking is needed leaves records half-related with no error.isIndexingRequired() - The queue must be running for anything past validation. With
the whole import runs inline in the request and will time out on a real file.
QUEUE_CONNECTION=sync
REQUIRED SUB-SKILL: Use bagisto-change-verification before calling any change done.
- 写入数据前必须先验证所有行。方法不得产生副作用:它会遍历整个文件,若开启
validateRow()模式,导入流程可能永远不会执行到stop-on-errors。importBatch() - 必须批量处理,绝不能逐行遍历整个文件。的默认值为 100,处理流程会为每个批次分配一个队列任务。若导入器将整个文件加载到内存中,会违背设计初衷,且在处理大文件时会失败。
AbstractImporter::BATCH_SIZE - 写入操作必须通过仓库(repositories)完成,与 Bagisto 中的其他模块保持一致。
- 所有提示信息必须通过 方法从
trans()命名空间获取,并支持全部22种语言环境。data_transfer:: - 必须如实声明 /
isLinkingRequired()。返回isIndexingRequired()会为每个批次添加一个队列处理阶段;若实际需要关联操作却返回true,会导致记录关联不完整且无错误提示。false - 队列服务必须处于运行状态,才能完成验证之后的所有操作。若设置 ,整个导入流程会在请求内同步执行,处理真实文件时会超时。
QUEUE_CONNECTION=sync
必备子技能: 在执行任何变更前,请使用 bagisto-change-verification 技能。