-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathAssetProcessor.php
49 lines (39 loc) · 1.48 KB
/
AssetProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Synolia\SyliusAkeneoPlugin\Processor\Product;
use Sylius\Component\Core\Model\ProductInterface;
use Synolia\SyliusAkeneoPlugin\Checker\EditionCheckerInterface;
use Synolia\SyliusAkeneoPlugin\Repository\AssetRepository;
final class AssetProcessor implements AssetProcessorInterface
{
public static function getDefaultPriority(): int
{
return 850;
}
public function __construct(
private EditionCheckerInterface $editionChecker,
private AssetRepository $assetRepository,
) {
}
public function process(ProductInterface $product, array $resource): void
{
/*
* I need to clean the product-assets association to clean removed product asset from akeneo but
* I couldn't clean assets using $product->getAssets()->clear() before re-importing them as the unit of work still
* thinks that the assets are to be deleted and I didn't want to use the entity manager flush as we don't want
* to import an empty product.
*/
$this->assetRepository->cleanAssetsForProduct($product);
}
public function support(ProductInterface $product, array $resource): bool
{
$isEnterprise = $this->editionChecker->isEnterprise() || $this->editionChecker->isSerenityEdition();
if (!$isEnterprise) {
return false;
}
if (!\method_exists($product, 'getAssets')) {
return false;
}
return true;
}
}