webfactory/content-mapping-bundle

webfactory/content-mapping的Symfony包。

1.7.0 2024-04-22 12:37 UTC

This package is auto-updated.

Last update: 2024-09-22 13:26:08 UTC


README

webfactory/content-mapping提供的Symfony包。如果您将同步器配置为服务,可以使用提供的控制台命令列出和启动它们。这在例如cron作业中很有用。

安装

使用composer安装包

composer require webfactory/content-mapping-bundle

并在您的应用内核中启用该包

<?php
// app/AppKernel.php

public function registerBundles()
{
    // ...
    $bundles[] = new Webfactory\ContentMappingBundle\WebfactoryContentMappingBundle();
    // ...
}

用法

首先,在services.xml中将您的同步器注册为服务,例如:

<!-- Synchronizer for MyEntity --->
<service class="Webfactory\ContentMapping\Synchronizer">
    <!-- SourceAdapter -->
    <argument type="service">
        <service class="Webfactory\ContentMapping\SourceAdapter\Doctrine\GenericDoctrineSourceAdapter">
            <!-- Doctrine Repository -->
            <argument type="service">
                <service class="MyVendor\MyBundle\Entity\MyEntityRepository" factory-service="doctrine.orm.entity_manager" factory-method="getRepository">
                    <argument>MyVendorMyEntityBundle:MyEntity</argument>
                </service>
            </argument>
            <!-- Name of the repository method to query -->
            <argument type="string">findForSolrIndex</argument>
        </service>
    </argument>

    <!-- Mapper -->
    <argument type="service">
        <service class="MyVendor\MyBundle\ContentMapping\MyEntityMapper" />
    </argument>

    <!-- DestinationAdapter -->
    <argument type="service" id="contentmapping.destinationadapter.solarium"/>

    <!-- PSR3-logger -->
    <argument type="service" id="logger" />
    <tag name="monolog.logger" channel="solr" />
    
    <!-- Tag to mark the service as a Synchronizer -->
    <tag name="contentmapping.synchronizer" objectclass="\JugendFuerEuropa\Bundle\JugendInAktionBundle\Entity\Mitarbeiter" />
</service>

<!-- other Synchronizers --->

如果您已像示例中那样标记了您的服务,可以使用控制台命令

app/console content-mapping:list-synchronizers

列出您注册的同步器,通过它们的对象类标识,并且

app/console content-mapping:synchronize

启动它们。使用-o objectclass仅启动具有指定objectclass的同步器,并使用-f强制在目标系统中更新,即使没有检测到更改。请注意,objectclass不是您要同步的实体类的名称,而是您在服务定义中定义的值(见上文)。请注意,您的objectclass中的反斜杠需要转义(使用反斜杠)。

致谢,版权和许可证

该项目始于webfactory GmbH,波恩。

版权所有 2015-2022 webfactory GmbH,波恩。代码在MIT许可证下发布。