How to Create a New Connector

We’ll implement here a very minimalist Connector, it will do nothing but allow us to understand the main concepts and the overall architecture.

Create our Connector

Create a new Symfony bundle:

1
2
3
4
5
6
7
8
9
<?php

namespace Acme\Bundle\DummyConnectorBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeDummyConnectorBundle extends Bundle
{
}

Register the bundle in AppKernel:

public function registerBundles()
{
    // ...
        new Acme\Bundle\DummyConnectorBundle\AcmeDummyConnectorBundle(),
    // ...
}

Create our Job

Create a file Resources/config/batch_jobs.yml in our Bundle to configure a new job:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
connector:
    name: Dummy Connector
    jobs:
        dummy_job:
            title: acme_dummy_connector.jobs.dummy_job.title
            type:  export
            steps:
                dummy_step:
                    title:         acme_dummy_connector.jobs.dummy_job.export.title
                    services:
                        reader:    pim_connector.reader.dummy_item
                        processor: pim_connector.processor.dummy_item
                        writer:    pim_connector.writer.dummy_item

Here we use an existing dummy reader, a processor and a writer (they implement relevant interfaces and are usable but they do nothing with data).

The reader is implemented in the class Pim\Component\Connector\Reader\DummyItemReader, it’s defined as a service in the ConnectorBundle with the alias pim_connector.reader.dummy_item in the file Resources\config\readers.yml.

The processor is implemented in the class Pim\Component\Connector\Processor\DummyItemProcessor, it’s defined as a service in the ConnectorBundle with the alias pim_connector.processor.dummy_item in the file Resources\config\processors.yml.

The writer is implemented in the class Pim\Component\Connector\Writer\DummyItemWriter, it’s defined as a service in the ConnectorBundle with the alias pim_connector.writer.dummy_item in the file Resources\config\writers.yml.

We’ll explain in next cookbook chapters how to create your own elements with real logic inside.

Translate Job and Step titles

Create a file Resources/translations/messages.en.yml in our Bundle to translate title keys.

1
2
3
4
5
acme_dummy_connector:
    jobs:
        dummy_job:
            title: Dummy Job
            dummy.title: Dummy Step

Create a Job Instance

Each Job can be configured through a JobInstance, an instance of the Job.

It means we can define a job and several instances of it, with different configurations.

Please note that this job instance does not take any configuration.

We can create an instance with the following command:

# akeneo:batch:create-job <connector> <job> <type> <code> <config> [<label>]
php app/console akeneo:batch:create-job 'Dummy Connector' dummy_job export my_job_instance '[]'

You can also list the existing job instances with the following command:

php app/console akeneo:batch:list-jobs

Execute our new Job Instance

You can run the job with the following command:

php app/console akeneo:batch:job my_job_instance

Note

This job is not configurable through the PIM UI, we’ll see in the next chapters how to write configurable jobs.