Skip to content

Commit

Permalink
* Fixes bug to add more listener when event name has already some lis…
Browse files Browse the repository at this point in the history
…tener

* Add #PAC-96: Define new constands for FileUploadConfiguration
    * #181
  • Loading branch information
Mardl committed Mar 26, 2021
1 parent 73c9d5d commit d07a45b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixed #PAC-206: Prevent finder mappings of different libraries to be overwritten
* Fixed #PAC-317: Remove UTF-8 BOM from windows generated csv file
* Fixes #PAC-244: bug with crash in date conversion with standard date format
* Fixes bug to add more listener when event name has already some listener

## Features

Expand All @@ -21,6 +22,8 @@
* Add #PAC-326: Cross-entity import of URLs (rewrites + redirects)
* Add #PAC-89: Add debug email command + DebugSendPlugin
* Add #PAC-57: Deleting dedicated attribute values via import by setting a configurable value
* Add #PAC-96: Define new constands for FileUploadConfiguration
* https://github.com/techdivision/import/issues/181

# Version 16.5.3

Expand Down
35 changes: 31 additions & 4 deletions src/Events/EmitterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

namespace TechDivision\Import\Events;

use Doctrine\Common\Collections\Collection;
use League\Event\Emitter;
use League\Event\EmitterInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use TechDivision\Import\ConfigurationManagerInterface;
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface;
use TechDivision\Import\SystemLoggerTrait;

/**
* A factory implementation to create a new event emitter instance.
Expand All @@ -38,6 +40,13 @@
class EmitterFactory implements EmitterFactoryInterface
{

/**
* The trait that provides basic filesystem handling functionality.
*
* @var \TechDivision\Import\SystemLoggerTrait
*/
use SystemLoggerTrait;

/**
* The configuration instance.
*
Expand All @@ -64,11 +73,16 @@ class EmitterFactory implements EmitterFactoryInterface
*
* @param \TechDivision\Import\ConfigurationManagerInterface $configurationManager The configuration instance
* @param \Symfony\Component\DependencyInjection\TaggedContainerInterface $container The container instance
* @param \Doctrine\Common\Collections\Collection $systemLoggers The array with the system logger instances
*/
public function __construct(ConfigurationManagerInterface $configurationManager, TaggedContainerInterface $container)
{
public function __construct(
ConfigurationManagerInterface $configurationManager,
TaggedContainerInterface $container,
Collection $systemLoggers
) {
$this->container = $container;
$this->configurationManager = $configurationManager;
$this->systemLoggers = $systemLoggers;
}

/**
Expand Down Expand Up @@ -124,8 +138,21 @@ protected function loadListeners(ListenerAwareConfigurationInterface $configurat

// prepare the listeners with the even names as key and the DI ID as value
foreach ($listenerConfigurations as $listeners) {
foreach ($listeners as $key => $name) {
$this->listeners[$parentName == null ? $key : sprintf('%s.%s', $parentName, $key)] = $name;
foreach ($listeners as $key => $listenerArray) {
$uniqueKeyForListener = $parentName == null ? $key : sprintf('%s.%s', $parentName, $key);
// no registert listener for the unique key? Simply add to optimise speed
if (!isset($this->listeners[$uniqueKeyForListener])) {
$this->listeners[$uniqueKeyForListener] = $listenerArray;
continue;
}
// Already registert listeners? Add each new single one
foreach ($listenerArray as $diValue) {
$this->listeners[$uniqueKeyForListener][] = $diValue;
}
$this->getSystemLogger()->debug(
sprintf("More than one registert listeners for %s", $uniqueKeyForListener),
$this->listeners[$uniqueKeyForListener]
);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/Utils/FileUploadConfigurationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ class FileUploadConfigurationKeys
* @var string
*/
const COPY_IMAGES = 'copy-images';

/**
* Name for the column 'override-images'.
*
* @var string
*/
const OVERRIDE_IMAGES = 'override-images';
}
1 change: 1 addition & 0 deletions symfony/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@
<service id="import.events.emitter.factory" class="TechDivision\Import\Events\EmitterFactory">
<argument type="service" id="import.configuration.manager"/>
<argument type="service" id="service_container"/>
<argument type="service" id="loggers"/>
</service>
<service id="import.events.emitter" class="League\Event\Emitter">
<factory service="import.events.emitter.factory" method="createEmitter"/>
Expand Down

0 comments on commit d07a45b

Please sign in to comment.