Skip to content

Commit

Permalink
TE-7332 merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
gechetspr committed Mar 11, 2021
2 parents ef3eb25 + 60898a7 commit e73f8e7
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"spryker/search": "^8.3.0",
"spryker/storage": "^3.4.1",
"spryker/symfony": "^3.1.0",
"spryker/synchronization-extension": "^1.1.0",
"spryker/synchronization-extension": "^1.2.0",
"spryker/util-encoding": "^2.0.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
<property name="data" type="array" singular="data"/>
</transfer>

<transfer name="SynchronizationDataQueryExpanderStrategyConfiguration">
<property name="offset" type="int"/>
<property name="chunkSize" type="int"/>
</transfer>

</transfers>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Spryker\Zed\Synchronization\Business\Message\QueueMessageCreatorInterface;
use Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToQueueClientInterface;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryContainerPluginInterface;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface;

class QueryContainerExporter implements ExporterInterface
{
Expand All @@ -37,6 +38,11 @@ class QueryContainerExporter implements ExporterInterface
*/
protected $synchronizationDataPlugins;

/**
* @var \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface
*/
protected $synchronizationDataQueryExpanderStrategyPlugin;

/**
* @var int
*/
Expand All @@ -45,15 +51,18 @@ class QueryContainerExporter implements ExporterInterface
/**
* @param \Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToQueueClientInterface $queueClient
* @param \Spryker\Zed\Synchronization\Business\Message\QueueMessageCreatorInterface $synchronizationQueueMessageCreator
* @param \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface $synchronizationDataQueryExpanderStrategyPlugin
* @param int $chunkSize
*/
public function __construct(
SynchronizationToQueueClientInterface $queueClient,
QueueMessageCreatorInterface $synchronizationQueueMessageCreator,
SynchronizationDataQueryExpanderStrategyPluginInterface $synchronizationDataQueryExpanderStrategyPlugin,
$chunkSize
) {
$this->queueClient = $queueClient;
$this->queueMessageCreator = $synchronizationQueueMessageCreator;
$this->synchronizationDataQueryExpanderStrategyPlugin = $synchronizationDataQueryExpanderStrategyPlugin;
$this->chunkSize = $chunkSize ?? static::DEFAULT_CHUNK_SIZE;
}

Expand Down Expand Up @@ -97,7 +106,7 @@ protected function exportData(array $ids, SynchronizationDataQueryContainerPlugi
*/
protected function createSynchronizationDataQueryContainerPluginIterator(array $ids, SynchronizationDataQueryContainerPluginInterface $plugin): Iterator
{
return new SynchronizationDataQueryContainerPluginIterator($plugin, $this->chunkSize, $ids);
return new SynchronizationDataQueryContainerPluginIterator($plugin, $this->synchronizationDataQueryExpanderStrategyPlugin, $this->chunkSize, $ids);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace Spryker\Zed\Synchronization\Business\Iterator;

use Generated\Shared\Transfer\SynchronizationDataQueryExpanderStrategyConfigurationTransfer;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryContainerPluginInterface;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface;

class SynchronizationDataQueryContainerPluginIterator extends AbstractSynchronizationDataPluginIterator
{
Expand All @@ -16,20 +18,31 @@ class SynchronizationDataQueryContainerPluginIterator extends AbstractSynchroniz
*/
protected $plugin;

/**
* @var \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface
*/
protected $synchronizationDataQueryExpanderStrategyPlugin;

/**
* @var int[]
*/
protected $filterIds;

/**
* @param \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryContainerPluginInterface $plugin
* @param \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface $synchronizationDataQueryExpanderStrategyPlugin
* @param int $chunkSize
* @param int[] $ids
*/
public function __construct(SynchronizationDataQueryContainerPluginInterface $plugin, int $chunkSize, array $ids = [])
{
public function __construct(
SynchronizationDataQueryContainerPluginInterface $plugin,
SynchronizationDataQueryExpanderStrategyPluginInterface $synchronizationDataQueryExpanderStrategyPlugin,
int $chunkSize,
array $ids = []
) {
parent::__construct($plugin, $chunkSize);

$this->synchronizationDataQueryExpanderStrategyPlugin = $synchronizationDataQueryExpanderStrategyPlugin;
$this->filterIds = $ids;
}

Expand All @@ -38,10 +51,18 @@ public function __construct(SynchronizationDataQueryContainerPluginInterface $pl
*/
protected function updateCurrent(): void
{
$this->current = $this->plugin->queryData($this->filterIds)
->offset($this->offset)
->limit($this->chunkSize)
->find()
->getData();
$synchronizationDataQueryExpanderStrategyConfigurationTransfer = new SynchronizationDataQueryExpanderStrategyConfigurationTransfer();
$synchronizationDataQueryExpanderStrategyConfigurationTransfer
->setOffset($this->offset)
->setChunkSize($this->chunkSize);

$query = $this->plugin->queryData($this->filterIds);

$query = $this->synchronizationDataQueryExpanderStrategyPlugin->expandQuery(
$query,
$synchronizationDataQueryExpanderStrategyConfigurationTransfer
);

$this->current = $query->find()->getData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Spryker\Zed\Synchronization\Business\Storage\SynchronizationStorage;
use Spryker\Zed\Synchronization\Business\Validation\OutdatedValidator;
use Spryker\Zed\Synchronization\SynchronizationDependencyProvider;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface;

/**
* @method \Spryker\Zed\Synchronization\SynchronizationConfig getConfig()
Expand Down Expand Up @@ -71,10 +72,19 @@ public function createQueryContainerExporter()
return new QueryContainerExporter(
$this->getQueueClient(),
$this->createQueueMessageCreator(),
$this->getSynchronizationDataQueryExpanderStrategyPlugin(),
$this->getConfig()->getSyncExportChunkSize()
);
}

/**
* @return \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface
*/
public function getSynchronizationDataQueryExpanderStrategyPlugin(): SynchronizationDataQueryExpanderStrategyPluginInterface
{
return $this->getProvidedDependency(SynchronizationDependencyProvider::PLUGIN_SYNCHRONIZATION_DATA_QUERY_EXPANDER_STRATEGY);
}

/**
* @return \Spryker\Zed\Synchronization\Business\Export\ExporterPluginResolverInterface
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Synchronization\Communication\Plugin\Synchronization;

use Generated\Shared\Transfer\SynchronizationDataQueryExpanderStrategyConfigurationTransfer;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface;

class SynchronizationDataQueryExpanderOffsetLimitStrategyPlugin implements SynchronizationDataQueryExpanderStrategyPluginInterface
{
/**
* {@inheritDoc}
*
* @api
*
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $query
* @param \Generated\Shared\Transfer\SynchronizationDataQueryExpanderStrategyConfigurationTransfer $synchronizationDataQueryExpanderStrategyConfigurationTransfer
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function expandQuery(
ModelCriteria $query,
SynchronizationDataQueryExpanderStrategyConfigurationTransfer $synchronizationDataQueryExpanderStrategyConfigurationTransfer
): ModelCriteria {
$query
->offset($synchronizationDataQueryExpanderStrategyConfigurationTransfer->getOffsetOrFail())
->limit($synchronizationDataQueryExpanderStrategyConfigurationTransfer->getChunkSizeOrFail());

return $query;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Synchronization\Communication\Plugin\Synchronization;

use Generated\Shared\Transfer\SynchronizationDataQueryExpanderStrategyConfigurationTransfer;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface;

class SynchronizationDataQueryExpanderWhereBetweenStrategyPlugin implements SynchronizationDataQueryExpanderStrategyPluginInterface
{
/**
* {@inheritDoc}
*
* @api
*
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $query
* @param \Generated\Shared\Transfer\SynchronizationDataQueryExpanderStrategyConfigurationTransfer $synchronizationDataQueryExpanderStrategyConfigurationTransfer
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function expandQuery(
ModelCriteria $query,
SynchronizationDataQueryExpanderStrategyConfigurationTransfer $synchronizationDataQueryExpanderStrategyConfigurationTransfer
): ModelCriteria {
$primaryKeys = $query->getTableMap()->getPrimaryKeys();

$offset = $synchronizationDataQueryExpanderStrategyConfigurationTransfer->getOffsetOrFail();
$chunkSize = $synchronizationDataQueryExpanderStrategyConfigurationTransfer->getChunkSizeOrFail();

$nextRange = $offset + $chunkSize;

$query
->where(sprintf('%s BETWEEN %s AND %s', key($primaryKeys), $offset, $nextRange));

return $query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Spryker\Zed\Kernel\AbstractBundleDependencyProvider;
use Spryker\Zed\Kernel\Container;
use Spryker\Zed\Synchronization\Communication\Plugin\Synchronization\SynchronizationDataQueryExpanderOffsetLimitStrategyPlugin;
use Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToQueueClientBridge;
use Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToSearchClientBridge;
use Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToStorageClientBridge;
Expand All @@ -24,6 +25,7 @@ class SynchronizationDependencyProvider extends AbstractBundleDependencyProvider
public const CLIENT_QUEUE = 'CLIENT_QUEUE';
public const SERVICE_UTIL_ENCODING = 'UTIL_ENCODING_SERVICE';
public const PLUGINS_SYNCHRONIZATION_DATA = 'PLUGINS_SYNCHRONIZATION_DATA';
public const PLUGIN_SYNCHRONIZATION_DATA_QUERY_EXPANDER_STRATEGY = 'PLUGIN_SYNCHRONIZATION_DATA_QUERY_EXPANDER_STRATEGY';

/**
* @param \Spryker\Zed\Kernel\Container $container
Expand All @@ -37,6 +39,7 @@ public function provideBusinessLayerDependencies(Container $container)
$container = $this->addQueueClient($container);
$container = $this->addUtilEncodingService($container);
$container = $this->addSynchronizationDataPlugins($container);
$container = $this->addSynchronizationDataQueryExpanderStrategyPlugin($container);

return $container;
}
Expand Down Expand Up @@ -130,4 +133,26 @@ protected function getSynchronizationDataPlugins()
{
return [];
}

/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
protected function addSynchronizationDataQueryExpanderStrategyPlugin($container)
{
$container->set(static::PLUGIN_SYNCHRONIZATION_DATA_QUERY_EXPANDER_STRATEGY, function (Container $container) {
return $this->getSynchronizationDataQueryExpanderStrategyPlugin();
});

return $container;
}

/**
* @return \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataQueryExpanderStrategyPluginInterface
*/
protected function getSynchronizationDataQueryExpanderStrategyPlugin()
{
return new SynchronizationDataQueryExpanderOffsetLimitStrategyPlugin();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,11 @@ public function testExecuteResolvedPluginsBySources(): void

$this->tester->setConfig(KernelConstants::PROJECT_NAMESPACES, ['Pyz']);

$container = new Container();
$container[SynchronizationDependencyProvider::CLIENT_QUEUE] = function (Container $container) {
$this->tester->setDependency(SynchronizationDependencyProvider::PLUGINS_SYNCHRONIZATION_DATA, function () {
return $this->createSynchronizationDataPlugins();
});

$this->tester->setDependency(SynchronizationDependencyProvider::CLIENT_QUEUE, function () {
$queueMock = $this->createQueueClientBridge();
$synchronizationPlugins = $this->createSynchronizationDataPlugins();

Expand All @@ -381,15 +384,11 @@ public function testExecuteResolvedPluginsBySources(): void
$queueMock->expects($this->never())->method('sendMessages');

return $queueMock;
};
});

$container[SynchronizationDependencyProvider::PLUGINS_SYNCHRONIZATION_DATA] = function (Container $container) {
return $this->createSynchronizationDataPlugins();
};
$container[SynchronizationDependencyProvider::SERVICE_UTIL_ENCODING] = $this->createUtilEncodingServiceBridge();
$this->tester->setDependency(SynchronizationDependencyProvider::SERVICE_UTIL_ENCODING, $this->createUtilEncodingServiceBridge());

$this->prepareFacade($container);
$this->synchronizationFacade->executeResolvedPluginsBySources([]);
$this->tester->getFacade()->executeResolvedPluginsBySources([]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
* @method \Spryker\Zed\Synchronization\Business\SynchronizationFacadeInterface getFacade()
*/
class SynchronizationBusinessTester extends Actor
{
Expand Down
1 change: 1 addition & 0 deletions tests/SprykerTest/Zed/Synchronization/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ suites:
- \SprykerTest\Shared\Testify\Helper\LocatorHelper
- \SprykerTest\Shared\Testify\Helper\DependencyHelper
- \SprykerTest\Shared\Propel\Helper\TransactionHelper
- \SprykerTest\Zed\Testify\Helper\BusinessHelper

0 comments on commit e73f8e7

Please sign in to comment.