-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
24 changed files
with
241 additions
and
288 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin\EventSubscriber; | ||
|
||
use Sylius\Component\Core\Model\ImagesAwareInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ProductEventSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
'sylius.product.pre_create' => ['removeImagesFileProperty', -50], | ||
'sylius.product.pre_update' => ['removeImagesFileProperty', -50], | ||
]; | ||
} | ||
|
||
/** | ||
* When more than two variants with different images are handled by the same instance of Messenger | ||
* the file property should be removed after having uploaded with the Sylius\Bundle\CoreBundle\EventListener\ImagesUploadListener. | ||
* Otherwise, the next pre create/update product event will throw an error by getting content from the first image that was removed by the TemporaryFilesManager. | ||
* See features/importing_products_from_queue.feature for having a real case. | ||
*/ | ||
public function removeImagesFileProperty(GenericEvent $event): void | ||
{ | ||
/** @var ImagesAwareInterface|mixed $subject */ | ||
$subject = $event->getSubject(); | ||
Assert::isInstanceOf($subject, ImagesAwareInterface::class); | ||
|
||
foreach ($subject->getImages() as $image) { | ||
$image->setFile(null); | ||
} | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin\MessageHandler; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use RuntimeException; | ||
use Webgriffe\SyliusAkeneoPlugin\ImporterInterface; | ||
use Webgriffe\SyliusAkeneoPlugin\ImporterRegistryInterface; | ||
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport; | ||
use Webgriffe\SyliusAkeneoPlugin\TemporaryFilesManager; | ||
|
||
final class ItemImportHandler | ||
{ | ||
public function __construct( | ||
private ImporterRegistryInterface $importerRegistry, | ||
private TemporaryFilesManager $temporaryFilesManager, | ||
private EntityManagerInterface $entityManager, | ||
) { | ||
} | ||
|
||
public function __invoke(ItemImport $message): void | ||
{ | ||
$akeneoIdentifier = $message->getAkeneoIdentifier(); | ||
$importer = $this->resolveImporter($message->getAkeneoEntity()); | ||
$importer->import($akeneoIdentifier); | ||
|
||
$this->entityManager->flush(); | ||
|
||
$this->temporaryFilesManager->deleteAllTemporaryFiles(); | ||
} | ||
|
||
private function resolveImporter(string $akeneoEntity): ImporterInterface | ||
{ | ||
foreach ($this->importerRegistry->all() as $importer) { | ||
if ($importer->getAkeneoEntity() === $akeneoEntity) { | ||
return $importer; | ||
} | ||
} | ||
|
||
throw new RuntimeException(sprintf('Cannot find suitable importer for entity "%s".', $akeneoEntity)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -73,4 +73,5 @@ sylius_grid: | |
framework: | ||
messenger: | ||
routing: | ||
'Webgriffe\SyliusAkeneoPlugin\Message\ItemImport': main | ||
|
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,4 @@ | ||
framework: | ||
messenger: | ||
transports: | ||
main: 'in-memory://' |
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 |
---|---|---|
@@ -1,30 +0,0 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Cli; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\ApplicationTester; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Webgriffe\SyliusAkeneoPlugin\Command\ConsumeCommand; | ||
|
||
final class ConsumeCommandContext implements Context | ||
{ | ||
public function __construct(private KernelInterface $kernel, private ConsumeCommand $consumeCommand) | ||
{ | ||
} | ||
|
||
/** | ||
* @When /^I import all items in queue$/ | ||
*/ | ||
public function iImportAllItemsInQueue(): void | ||
{ | ||
$application = new Application($this->kernel); | ||
$application->setAutoExit(false); | ||
$application->add($this->consumeCommand); | ||
$applicationTester = new ApplicationTester($application); | ||
$applicationTester->run(['command' => 'webgriffe:akeneo:consume']); | ||
} | ||
} | ||
Oops, something went wrong.