Plugins

  • A plugin is the highest level when starting a component

  • Depending on the required functionality, it is necessary to implement a plugin

  • In many cases, it is not necessary to implement a plugin because the subject or observer level already covers the essential requirements

When do I need a plugin?

A plugin is needed if:
  • You want to interact before or after the primary import step?

  • You are implementing business logic that needs access to all important artifacts at the same time?

  • You want to process files of all artifacts at once, both before and after an import?

    • The Artifact plugin compresses all import artifacts to one ZIP compressed file and then moves it to a configurable folder processed or after they are processed

  • Do you want to load some data from the database or file system that will be needed later in your subjects or observers while processing the files?

    • The Global Data plugin loads the available global data and attributes from the database and adds them to the registry so that any other plugin can access them

  • You need to pre-initialize some data before the primary import process starts?

  • You need to manipulate data after the import is complete?

Out of the box Plug-Ins

Our default plugins are part of the Pacemaker Import Community core and can be used out of the box.

If you need to implement custom components, the preferred approach is to use the SubjectPlugin and provide your functionality as subjects, observers, and services.

It is helpful to consider the implementation of one of the following plugins for the listed cases:

How to implement a plugin?

An excellent example of how to implement a plugin is the Global Data plugin TechDivision\Import\Plugins\GlobalDataPlugin, which is also part of the Pacemaker Import Community core.

A plugin does not need to get written from scratch; instead, extend the existing TechDivision\Import\Plugins\AbstractPlugin class, which implements the TechDivision\Import\Plugins\PluginInterface, since it must be implemented by any other plugin.

The interface defines the setPluginConfiguration() method, which expects a plugin configuration with the optional parameters.

{
  "id": "import.plugin.global.data"
}
  • The process() method implements the plugin main functionality

  • The TechDivision\Import\Plugins\GlobalDataPlugin loads the global data, e.g., entity types from the Import processor and injects them into the registry

The plugin is now available for all following plugins, subjects, and observers and helps to avoid unnecessary database accesses.

TechDivision/Import/Plugins/GlobalDataPlugin.php
<?php

namespace TechDivision\Import\Plugins;

use TechDivision\Import\Utils\RegistryKeys;

class GlobalDataPlugin extends AbstractPlugin
{
    /**
     * Process the plugin functionality.
     *
     * @return void
     * @throws \Exception Is thrown, if the plugin can not be processed
     */
    public function process()
    {
        // load the global data from the import processor
        $globalData = $this->getImportProcessor()->getGlobalData();

        // add the status with the global data
        $this->getRegistryProcessor()->mergeAttributesRecursive(
            RegistryKeys::STATUS,
            array(RegistryKeys::GLOBAL_DATA => $globalData)
        );
    }
}