Skip to content

Commit 0019185

Browse files
authored
FRW-10501 Filter duplicate event entities. (#11609)
FRW-10501 Optimized events in P&S.
1 parent ee89f41 commit 0019185

20 files changed

+295
-63
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"spryker/container": "*",
3030
"spryker/event": "*",
3131
"spryker/product-attribute": "*",
32+
"spryker/product-page-search": "*",
3233
"spryker/propel": "*",
3334
"spryker/queue": "*",
3435
"spryker/rabbit-mq": "*",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Zed\ProductStorage\Communication\Plugin\Event\Listener;
9+
10+
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
11+
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
12+
13+
/**
14+
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
15+
*/
16+
abstract class AbstractProductConcreteStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
17+
{
18+
/**
19+
* @var array<int>
20+
*/
21+
protected static $publishedProductConcreteIds = [];
22+
23+
/**
24+
* @var array<int>
25+
*/
26+
protected static $unpublishedProductConcreteIds = [];
27+
28+
/**
29+
* @param array<int> $productIds
30+
*
31+
* @return void
32+
*/
33+
protected function publishConcreteProducts(array $productIds): void
34+
{
35+
$productIds = array_values(array_unique(array_diff($productIds, static::$publishedProductConcreteIds)));
36+
if ($productIds) {
37+
$this->getFacade()->publishConcreteProducts($productIds);
38+
}
39+
static::$publishedProductConcreteIds = array_merge(static::$publishedProductConcreteIds, $productIds);
40+
}
41+
42+
/**
43+
* @param array<int> $productIds
44+
*
45+
* @return void
46+
*/
47+
protected function unpublishConcreteProducts(array $productIds): void
48+
{
49+
$productIds = array_values(array_unique(array_diff($productIds, static::$unpublishedProductConcreteIds)));
50+
if ($productIds) {
51+
$this->getFacade()->unpublishConcreteProducts($productIds);
52+
}
53+
54+
static::$unpublishedProductConcreteIds = array_merge(static::$unpublishedProductConcreteIds, $productIds);
55+
}
56+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Zed\ProductStorage\Communication\Plugin\Event\Listener;
9+
10+
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
11+
12+
/**
13+
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
14+
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
15+
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
16+
*/
17+
class AbstractProductStorageListener extends AbstractPlugin
18+
{
19+
/**
20+
* @var array<int>
21+
*/
22+
protected static $publishedProductAbstractIds = [];
23+
24+
/**
25+
* @var array<int>
26+
*/
27+
protected static $unpublishedProductAbstractIds = [];
28+
29+
/**
30+
* @var string
31+
*/
32+
public const COL_ID_PRODUCT_ABSTRACT = 'id_product_abstract';
33+
34+
/**
35+
* @param array<int> $productAbstractIds
36+
*
37+
* @return void
38+
*/
39+
protected function publishAbstractProducts(array $productAbstractIds)
40+
{
41+
$productAbstractIds = array_values(array_unique(array_diff($productAbstractIds, static::$publishedProductAbstractIds)));
42+
if ($productAbstractIds) {
43+
$this->getFacade()->publishAbstractProducts($productAbstractIds);
44+
}
45+
static::$publishedProductAbstractIds = array_merge(static::$publishedProductAbstractIds, $productAbstractIds);
46+
}
47+
48+
/**
49+
* @param array<int> $productAbstractIds
50+
*
51+
* @return void
52+
*/
53+
protected function unpublishProductAbstracts(array $productAbstractIds)
54+
{
55+
$productAbstractIds = array_values(array_unique(array_diff($productAbstractIds, static::$unpublishedProductAbstractIds)));
56+
if ($productAbstractIds) {
57+
$this->getFacade()->unpublishProductAbstracts($productAbstractIds);
58+
}
59+
static::$unpublishedProductAbstractIds = array_merge(static::$unpublishedProductAbstractIds, $productAbstractIds);
60+
}
61+
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractLocalizedAttributesStorageListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
use Orm\Zed\Product\Persistence\Map\SpyProductAbstractLocalizedAttributesTableMap;
1111
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
12-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1312

1413
/**
1514
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1615
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1716
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1817
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1918
*/
20-
class ProductAbstractLocalizedAttributesStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
19+
class ProductAbstractLocalizedAttributesStorageListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2120
{
2221
/**
2322
* @api
@@ -34,6 +33,6 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3433
SpyProductAbstractLocalizedAttributesTableMap::COL_FK_PRODUCT_ABSTRACT,
3534
);
3635

37-
$this->getFacade()->publishAbstractProducts($productAbstractIds);
36+
$this->publishAbstractProducts($productAbstractIds);
3837
}
3938
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractStorageListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Spryker\Zed\ProductStorage\Communication\Plugin\Event\Listener;
99

1010
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
11-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1211
use Spryker\Zed\Product\Dependency\ProductEvents;
1312

1413
/**
@@ -19,7 +18,7 @@
1918
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
2019
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
2120
*/
22-
class ProductAbstractStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
21+
class ProductAbstractStorageListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2322
{
2423
/**
2524
* @api
@@ -37,9 +36,9 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3736
$eventName === ProductEvents::ENTITY_SPY_PRODUCT_ABSTRACT_DELETE ||
3837
$eventName === ProductEvents::PRODUCT_ABSTRACT_UNPUBLISH
3938
) {
40-
$this->getFacade()->unpublishProductAbstracts($productAbstractIds);
39+
$this->unpublishProductAbstracts($productAbstractIds);
4140
} else {
42-
$this->getFacade()->publishAbstractProducts($productAbstractIds);
41+
$this->publishAbstractProducts($productAbstractIds);
4342
}
4443
}
4544
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractStoragePublishListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
namespace Spryker\Zed\ProductStorage\Communication\Plugin\Event\Listener;
99

1010
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
11-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1211

1312
/**
1413
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1514
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1615
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1716
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1817
*/
19-
class ProductAbstractStoragePublishListener extends AbstractPlugin implements EventBulkHandlerInterface
18+
class ProductAbstractStoragePublishListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2019
{
2120
/**
2221
* {@inheritDoc}
@@ -32,6 +31,6 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3231
{
3332
$productAbstractIds = $this->getFactory()->getEventBehaviorFacade()->getEventTransferIds($eventEntityTransfers);
3433

35-
$this->getFacade()->publishAbstractProducts($productAbstractIds);
34+
$this->publishAbstractProducts($productAbstractIds);
3635
}
3736
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractStorageUnpublishListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
namespace Spryker\Zed\ProductStorage\Communication\Plugin\Event\Listener;
99

1010
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
11-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1211

1312
/**
1413
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1514
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1615
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1716
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1817
*/
19-
class ProductAbstractStorageUnpublishListener extends AbstractPlugin implements EventBulkHandlerInterface
18+
class ProductAbstractStorageUnpublishListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2019
{
2120
/**
2221
* {@inheritDoc}
@@ -32,6 +31,6 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3231
{
3332
$productAbstractIds = $this->getFactory()->getEventBehaviorFacade()->getEventTransferIds($eventEntityTransfers);
3433

35-
$this->getFacade()->unpublishProductAbstracts($productAbstractIds);
34+
$this->unpublishProductAbstracts($productAbstractIds);
3635
}
3736
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractStoreStorageListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
use Orm\Zed\Product\Persistence\Map\SpyProductAbstractStoreTableMap;
1111
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
12-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1312

1413
/**
1514
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1615
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1716
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1817
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1918
*/
20-
class ProductAbstractStoreStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
19+
class ProductAbstractStoreStorageListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2120
{
2221
/**
2322
* @api
@@ -33,6 +32,6 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3332
->getEventBehaviorFacade()
3433
->getEventTransferForeignKeys($eventEntityTransfers, SpyProductAbstractStoreTableMap::COL_FK_PRODUCT_ABSTRACT);
3534

36-
$this->getFacade()->publishAbstractProducts($productAbstractIds);
35+
$this->publishAbstractProducts($productAbstractIds);
3736
}
3837
}

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductAbstractUrlStorageListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
use Orm\Zed\Url\Persistence\Map\SpyUrlTableMap;
1111
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
12-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1312

1413
/**
1514
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1615
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1716
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1817
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1918
*/
20-
class ProductAbstractUrlStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
19+
class ProductAbstractUrlStorageListener extends AbstractProductStorageListener implements EventBulkHandlerInterface
2120
{
2221
/**
2322
* @api
@@ -34,7 +33,7 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3433
return;
3534
}
3635

37-
$this->getFacade()->publishAbstractProducts($productAbstractIds);
36+
$this->publishAbstractProducts($productAbstractIds);
3837
}
3938

4039
/**

src/Spryker/Zed/ProductStorage/Communication/Plugin/Event/Listener/ProductConcreteLocalizedAttributesStorageListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
use Orm\Zed\Product\Persistence\Map\SpyProductLocalizedAttributesTableMap;
1111
use Spryker\Zed\Event\Dependency\Plugin\EventBulkHandlerInterface;
12-
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
1312

1413
/**
1514
* @method \Spryker\Zed\ProductStorage\Persistence\ProductStorageQueryContainerInterface getQueryContainer()
1615
* @method \Spryker\Zed\ProductStorage\Communication\ProductStorageCommunicationFactory getFactory()
1716
* @method \Spryker\Zed\ProductStorage\Business\ProductStorageFacadeInterface getFacade()
1817
* @method \Spryker\Zed\ProductStorage\ProductStorageConfig getConfig()
1918
*/
20-
class ProductConcreteLocalizedAttributesStorageListener extends AbstractPlugin implements EventBulkHandlerInterface
19+
class ProductConcreteLocalizedAttributesStorageListener extends AbstractProductConcreteStorageListener implements EventBulkHandlerInterface
2120
{
2221
/**
2322
* @api
@@ -34,6 +33,6 @@ public function handleBulk(array $eventEntityTransfers, $eventName)
3433
SpyProductLocalizedAttributesTableMap::COL_FK_PRODUCT,
3534
);
3635

37-
$this->getFacade()->publishConcreteProducts($productIds);
36+
$this->publishConcreteProducts($productIds);
3837
}
3938
}

0 commit comments

Comments
 (0)