mutoco/silverstripe-mplus-import

从 MuseumPlus 导入数据记录到 SilverStripe。

安装: 142

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 0

开放问题: 0

类型:silverstripe-vendormodule

dev-main / 1.x-dev 2022-06-20 08:26 UTC

This package is auto-updated.

Last update: 2024-09-20 13:23:25 UTC


README

Code Coverage Build Status Latest Stable Version Monthly Downloads

这是一个导入器,用于将 zetcom 的 museumplus 中的数据记录导入。它作为 QueuedJobs 模块的一个排队作业实现。

要求

安装

使用 composer 安装

composer require mutoco/silverstripe-mplus-import 1.x-dev

许可

查看 许可

项目状态

这不是一个稳定版本(尚未)。API 可能会更改,并且仍然有一些待办事项 待办

API 配置

使用注入器设置 Mplus API 的凭据。

SilverStripe\Core\Injector\Injector:
  Mutoco\Mplus\Api\Client:
    properties:
      BaseUrl: 'https://example.com/endpoint'
      Username: 'username'
      Password: '`MPLUS_PASSWORD`'

在这里,使用名为 MPLUS_PASSWORD 的环境变量用于实际密码。请确保在您的系统或 .env 文件中设置此环境变量。

配置数据映射

ImportEngine 类负责将 Mplus 数据记录导入到 SilverStripe 数据对象。您必须通过添加以下内容到您的配置中(理想情况下,这存储在 app/_config/mplus.yml 或类似位置)来配置从远程 "模块" 到数据对象的映射

Mutoco\Mplus\Import\ImportEngine:
  modules:
    ModuleName:
      modelClass: DataObjectClass
      fields:
        Field: Path
      relations:
        RelationName:
          name: Path
          type: ModuleName
          fields:
            RelationField: Path
      attachment: RelationName

在此简化示例中,ModuleName 代表 Mplus 中的模块名称,例如 PersonExhibitionObject 等。然后您指定此模块的映射。每个模块允许的键如下

  • modelClass:SilverStripe DataObject 的完全限定类名
  • fields:从 SilverStripe 字段名称(通常是您为 $db 配置的内容)到 Mplus 中的路径的映射。这些必须从 "根" 级别开始,例如,嵌套路径需要使用点符号编写。例如:AdrContactGrp.ValueTxt
  • relations:从 SilverStripe 关系到 Mplus 中的集合的映射。通常,Mplus 中的集合是 repeatableGroupmoduleReference 节点。RelationName 是 SilverStripe ORM 中关系的名称。然后您设置名称(路径)和类型(引用模块的名称)以及可选的 fields,这些应与关系一起存储(例如,对于 many_many_extraFields 或类似)。
  • attachment:如果设置,将在此关系中存储附件。例如,如果您设置:attachment: Image,则附件将存储为数据对象上的 Image 关系。

假设您有一个表示 SilverStripe 中 Person 的数据对象,其 FQCN 为 MyProject\Person,那么您的配置可能如下所示

Mutoco\Mplus\Import\ImportEngine:
  modules:
    Person:
      modelClass: MyProject\Person
      fields:
        Firstname: PerFirstNameTxt
        Lastname: PerLastNameTxt
        PlaceOfBirth: PerPlaceBirthTxt
        PlaceOfDeath: PerPlaceDeathTxt
        DateOfBirth: PerDateFromBeginDat
        DateOfDeath: PerDateToEndDat

当然,modules 可以包含多个条目,这对于具有关系的更复杂设置是必要的。以下是一个示例

Mutoco\Mplus\Import\ImportEngine:
  modules:
    Person:
      modelClass: MyProjectPerson
      fields:
        Firstname: PerFirstNameTxt
        Lastname: PerLastNameTxt
        PlaceOfBirth: PerPlaceBirthTxt
        PlaceOfDeath: PerPlaceDeathTxt
        DateOfBirth: PerDateFromBeginDat
        DateOfDeath: PerDateToEndDat
    TextBlock:
      modelClass: MyProject\TextBlock
      fields:
        Text: TextClb
        Author: AuthorTxt
    Exhibition:
      modelClass: MyProject\Exhibition
      fields:
        Title: ExhTitleTxt
      relations:
        Texts:
          name: ExhTextGrp
          type: TextBlock
        Person:
          name: ExhPersonRef
          type: Person

在此示例中,您可以导入 "展览",这将导入所有相关的人员和文本块(TextBlock 不是 Mplus 中的模块,而是一个任意命名的模型,因此可以在关系中进行映射)。

配置导入作业

为了告诉 ImportJob 要导入哪些记录,配置一个初始搜索以获取要导入的记录。以下配置将导入 ID 为 12 的展览。

search 配置基本上是 Mplus 搜索 API 的 YML 到 XML 映射。

Mutoco\Mplus\Job\ImportJob:
  imports:
    Exhibition:
      search:
        or:
          - type: equalsField
            fieldPath: __id
            operand: 1
          - type: equalsField
            fieldPath: __id
            operand: 2

维护者

缺陷跟踪器

缺陷在此存储库的问题部分进行跟踪。在提交问题之前,请阅读现有问题以确保您的独特性。

如果问题看起来像是一个新的缺陷

  • 创建一个新的问题
  • 描述重现您问题的步骤以及预期的结果。单元测试、屏幕截图和屏幕录制在这里可能会有所帮助。
  • 尽可能详细地描述您的环境:SilverStripe版本、浏览器、PHP版本、操作系统、任何已安装的SilverStripe模块。

请直接向模块维护者报告安全问题。请不要在缺陷跟踪器中提交安全问题。

开发和贡献

如果您想对该模块做出贡献,请确保您发起一个拉取请求并与模块维护者讨论。