-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c87a80d
commit 21905d5
Showing
120 changed files
with
1,889 additions
and
1,929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Exceptions; | ||
|
||
class NotImplementedException extends \LogicException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Factory\Message\Batch; | ||
|
||
use Synolia\SyliusAkeneoPlugin\Message\Batch\BatchMessageInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
class BatchMessageFactory implements BatchMessageFactoryInterface | ||
{ | ||
public static function createFromPayload(PipelinePayloadInterface $payload, array $items): BatchMessageInterface | ||
{ | ||
return $payload->createBatchMessage($items); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Factory/Message/Batch/BatchMessageFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Factory\Message\Batch; | ||
|
||
use Synolia\SyliusAkeneoPlugin\Message\Batch\BatchMessageInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
interface BatchMessageFactoryInterface | ||
{ | ||
public static function createFromPayload(PipelinePayloadInterface $payload, array $items): BatchMessageInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Handler\Task; | ||
|
||
use Akeneo\Pim\ApiClient\Pagination\Page; | ||
use Akeneo\Pim\ApiClient\Pagination\PageInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Synolia\SyliusAkeneoPlugin\Factory\Message\Batch\BatchMessageFactoryInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; | ||
|
||
class SymfonyMessengerTaskHandler implements TaskHandlerInterface | ||
{ | ||
public const HANDLER_CODE = 'messenger'; | ||
|
||
public function __construct( | ||
protected EntityManagerInterface $entityManager, | ||
protected LoggerInterface $logger, | ||
private MessageBusInterface $bus, | ||
private BatchMessageFactoryInterface $batchMessageFactory, | ||
) { | ||
} | ||
|
||
public function support(PipelinePayloadInterface $pipelinePayload): bool | ||
{ | ||
return $pipelinePayload->getHandler() === self::HANDLER_CODE; | ||
} | ||
|
||
public function batch(PipelinePayloadInterface $pipelinePayload, array $items): void | ||
{ | ||
$this->bus->dispatch($this->batchMessageFactory->createFromPayload($pipelinePayload, $items)); | ||
} | ||
|
||
public function handle( | ||
PipelinePayloadInterface $pipelinePayload, | ||
ResourceCursorInterface|PageInterface $handleType, | ||
): void { | ||
$count = 0; | ||
$items = []; | ||
|
||
if ($handleType instanceof PageInterface) { | ||
$this->handleByPage($pipelinePayload, $handleType, $count, $items); | ||
} else { | ||
$this->handleByCursor($pipelinePayload, $handleType, $count, $items); | ||
} | ||
} | ||
|
||
private function handleByPage( | ||
PipelinePayloadInterface $payload, | ||
PageInterface $page, | ||
int &$count = 0, | ||
array &$items = [], | ||
): void { | ||
while ( | ||
($page instanceof Page && $page->hasNextPage()) || | ||
($page instanceof Page && !$page->hasPreviousPage()) || | ||
$page instanceof Page | ||
) { | ||
foreach ($page->getItems() as $item) { | ||
++$count; | ||
$items[] = $item; | ||
$identifiers[] = $item['code'] ?? $item['identifier']; | ||
|
||
if (0 === $count % $payload->getBatchSize()) { | ||
$this->logger->notice('Batching', ['codes' => $identifiers]); | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
$page = $page->getNextPage(); | ||
} | ||
|
||
if ($items !== []) { | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
private function handleByCursor( | ||
PipelinePayloadInterface $payload, | ||
ResourceCursorInterface $resourceCursor, | ||
int &$count = 0, | ||
array &$items = [], | ||
): void { | ||
/** | ||
* @var array<string, mixed> $item | ||
*/ | ||
foreach ($resourceCursor as $item) { | ||
++$count; | ||
$items[] = $item; | ||
$identifiers[] = $item['code'] ?? $item['identifier']; | ||
|
||
if (0 === $count % $payload->getBatchSize()) { | ||
$this->logger->notice('Batching', ['codes' => $identifiers]); | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
if ($items !== []) { | ||
$this->batch($payload, $items); | ||
$items = []; | ||
} | ||
} | ||
|
||
public function setUp(PipelinePayloadInterface $pipelinePayload): PipelinePayloadInterface | ||
{ | ||
return $pipelinePayload; | ||
} | ||
|
||
public function tearDown(PipelinePayloadInterface $pipelinePayload): PipelinePayloadInterface | ||
{ | ||
return $pipelinePayload; | ||
} | ||
|
||
public function continue(PipelinePayloadInterface $pipelinePayload): void | ||
{ | ||
} | ||
} |
Oops, something went wrong.