定制 draw/sonata-import-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

draw/sonata-import-bundle

Composer 安装命令:

composer require draw/sonata-import-bundle

包简介

Generic customisable import system for sonata

README 文档

README

This bundle add a basic import from csv system of entities in Sonata.

It's currently only support update of existing entities.

Base on a configuration you can set which entity can be imported.

When uploading a csv file the system will detect the list of attribute base on a header column. It will then try to detect the identifier and the mutator to update the entities.

Configuration

Here is an example of the configuration:

draw_sonata_import:
  skip_value: '_SKIP_' # Optional, defaults to "_SKIP_". See "Preserving existing values" below.
  classes:
    App\Entity\User:
      alias: 'User' #The alias will be used instead of the full class name in the dropdown and database
    App\Entity\Product:
      alias: 'Product'

This tell the system that it support import for App\Entity\User and App\Entity\Product.

Preserving existing values on partial imports

When updating existing entities, an empty cell or any other value is normally written to the entity. This is a problem for partial imports — for example, updating only one locale of a translatable field while leaving the other locales untouched.

To opt out of writing a given cell, use the skip value (default _SKIP_):

id,translation#en.title,translation#fr.title,translation#pl.title
42,Ocean kingdom,Royaume océanique,_SKIP_

For row id=42, the English and French titles are updated and the Polish title is left exactly as it is in the database. The check happens in Importer::assignValue() before any type coercion, so the marker also works on date columns, boolean columns, etc.

You can change the marker per project via the skip_value configuration key. The marker only makes sense on update — on insert (insertWhenNotFound: true) a skipped column simply leaves the field at its default value.

An empty cell is not a skip — it still clears the field. Use the marker explicitly when you want to keep the stored value.

Sonata admin

A new menu Import will be available on the lef menu to create a new import. A dropdown to specify which entity you are importing is available base on the configuration. There is also an action Import on the list view of the entities that will link directly to this page with the entity selected in the dropdown.

You must select a csv file from which the system will detect the header and will try to fill the column information. You can then adjust it manually and select to Process the file.

Column Information Extraction

The system try to extract column information base on a Draw\Bundle\SonataImportBundle\Column\ColumnBuilder\ColumnBuilderInterface. There is two extractor provider with the system, one that will set if a column is the identifier base on it's name (id only), another one that will check if there is a setter base on the header to assign the mutator.

Import

When importing data a event Draw\Bundle\SonataImportBundle\Event\AttributeImportEvent is dispatch for every entity/column. Listening to this event let you do custom import logic of the data. If you did process the event you need to stop is propagation. If the event was not stop, the import logic will fall back on the column mutator that was set.

The setter just do a simple set of the raw value in the column (that is always a string) so if it's a reference to another object you must implement a listener to do have a custom logic.

draw/sonata-import-bundle 适用场景与选型建议

draw/sonata-import-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.67k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「draw」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 draw/sonata-import-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 draw/sonata-import-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 draw/sonata-import-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-17