Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogDataExporter\Model\Indexer;

use Magento\Indexer\Model\Indexer;

/**
* Class IndexInvalidationManager
*
* Invalidates indexes by preconfigured events
*/
class IndexInvalidationManager
{
/**
* @var Indexer
*/
private $indexer;

/**
* @var array
*/
private $invalidationEvents;

/**
* IndexInvalidationManager constructor.
*
* @param Indexer $indexer
* @param array $invalidationEvents
*/
public function __construct(
Indexer $indexer,
array $invalidationEvents
) {
$this->indexer = $indexer;
$this->invalidationEvents = $invalidationEvents;
}

/**
* Invalidates all indexes subscribed on event
*
* @param string $eventName
*/
public function invalidate(string $eventName): void
{
$indexers = isset($this->invalidationEvents[$eventName]) ? $this->invalidationEvents[$eventName] : [];
foreach ($indexers as $indexer) {
$this->indexer->load($indexer)->invalidate();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogDataExporter\Plugin\Index;

use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
use Magento\Store\Model\ResourceModel\Group;

/**
* Class InvalidateOnGroupChange
*
* Invalidates indexes on Store Group change
*/
class InvalidateOnGroupChange
{
/**
* @var IndexInvalidationManager
*/
private $invalidationManager;

/**
* @var string
*/
private $invalidationEvent;

/**
* InvalidateOnChange constructor.
*
* @param IndexInvalidationManager $invalidationManager
* @param string $invalidationEvent
*/
public function __construct(
IndexInvalidationManager $invalidationManager,
string $invalidationEvent = 'group_changed'
) {
$this->invalidationManager = $invalidationManager;
$this->invalidationEvent = $invalidationEvent;
}

/**
* Invalidate on save
*
* @param Group $subject
* @param Group $result
* @return Group
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(Group $subject, Group $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}

/**
* Invalidate on delete
*
* @param Group $subject
* @param Group $result
* @return Group
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDelete(Group $subject, Group $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogDataExporter\Plugin\Index;

use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
use Magento\Store\Model\ResourceModel\Store;

/**
* Class InvalidateOnGroupChange
*
* Invalidates indexes on Store change
*/
class InvalidateOnStoreChange
{
/**
* @var IndexInvalidationManager
*/
private $invalidationManager;

/**
* @var string
*/
private $invalidationEvent;

/**
* InvalidateOnChange constructor.
*
* @param IndexInvalidationManager $invalidationManager
* @param string $invalidationEvent
*/
public function __construct(
IndexInvalidationManager $invalidationManager,
string $invalidationEvent = 'group_changed'
) {
$this->invalidationManager = $invalidationManager;
$this->invalidationEvent = $invalidationEvent;
}

/**
* Invalidate on save
*
* @param Store $subject
* @param Store $result
* @return Store
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(Store $subject, Store $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}

/**
* Invalidate on delete
*
* @param Store $subject
* @param Store $result
* @return Store
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDelete(Store $subject, Store $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogDataExporter\Plugin\Index;

use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
use Magento\Store\Model\ResourceModel\Website;

class InvalidateOnWebsiteChange
{
/**
* @var IndexInvalidationManager
*/
private $invalidationManager;

/**
* @var string
*/
private $invalidationEvent;

/**
* InvalidateOnChange constructor.
*
* @param IndexInvalidationManager $invalidationManager
* @param string $invalidationEvent
*/
public function __construct(
IndexInvalidationManager $invalidationManager,
string $invalidationEvent = 'website_changed'
) {
$this->invalidationManager = $invalidationManager;
$this->invalidationEvent = $invalidationEvent;
}

/**
* Invalidate on save
*
* @param Website $subject
* @param Website $result
* @return Website
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(Website $subject, Website $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}

/**
* Invalidate on delete
*
* @param Website $subject
* @param Website $result
* @return Website
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDelete(Website $subject, Website $result)
{
$this->invalidationManager->invalidate($this->invalidationEvent);
return $result;
}
}
33 changes: 31 additions & 2 deletions app/code/Magento/CatalogDataExporter/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@
</argument>
</arguments>
</type>

<virtualType name="Magento\CatalogDataExporter\Model\Provider\Product\Downloadable\LinkSampleUrlProvider"
type="Magento\CatalogDataExporter\Model\Provider\Product\Downloadable\SampleUrlProvider">
<arguments>
Expand All @@ -460,12 +459,42 @@
</argument>
</arguments>
</type>

<type name="Magento\Framework\Setup\Declaration\Schema\Operations\AddColumn">
<arguments>
<argument name="triggers" xsi:type="array">
<item name="migrateDataFromJSON" xsi:type="object">Magento\CatalogDataExporter\Plugin\DDLTrigger\MigrateDataFromJSON</item>
</argument>
</arguments>
</type>
<!-- Indexes mass-invalidation logic -->
<type name="Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager">
<arguments>
<argument name="invalidationEvents" xsi:type="array">
<item name="store_changed" xsi:type="array">
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
</item>
<item name="website_changed" xsi:type="array">
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
</item>
<item name="group_changed" xsi:type="array">
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
</item>
</argument>
</arguments>
</type>
<type name="Magento\Store\Model\ResourceModel\Website">
<plugin name="invalidate_feed_index_on_store_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnWebsiteChange" />
</type>
<type name="Magento\Store\Model\ResourceModel\Group">
<plugin name="invalidate_feed_index_on_group_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnGroupChange" />
</type>
<type name="Magento\Store\Model\ResourceModel\Store">
<plugin name="invalidate_feed_index_on_website_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnStoreChange" />
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ private function validateVariantsData(ProductInterface $product, array $extract,
'selections' => $this->getVariantSelections($childProduct, $attributeCodes)
];
}
$this->assertEquals($variants, $extract['feedData']['variants']);
$actualVariants = $extract['feedData']['variants'];
usort($actualVariants, function ($a, $b){return $a['sku'] <=> $b['sku'];});
usort($variants, function ($a, $b){return $a['sku'] <=> $b['sku'];});
$this->assertEquals($variants, $actualVariants);
}

/**
Expand Down