Skip to content

Commit 5fd6839

Browse files
committed
Merge remote-tracking branch 'origin/AC-13810' into AC-13810-V1
2 parents 71bfd9a + a06cede commit 5fd6839

File tree

9 files changed

+109
-57
lines changed

9 files changed

+109
-57
lines changed

app/code/Magento/Customer/Model/Address.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Customer\Model;
77

@@ -371,7 +371,9 @@ public function reindex()
371371
{
372372
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
373373
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
374-
$indexer->reindexRow($this->getCustomerId());
374+
if (!$indexer->isScheduled()) {
375+
$indexer->reindexRow($this->getCustomerId());
376+
}
375377
}
376378

377379
/**

app/code/Magento/Customer/Model/Customer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,8 @@ public function resetErrors()
11021102
*/
11031103
public function afterSave()
11041104
{
1105-
if ($this->getIndexer()->getState()->getStatus() == StateInterface::STATUS_VALID) {
1105+
$indexer = $this->getIndexer();
1106+
if (($indexer->getState()->getStatus() == StateInterface::STATUS_VALID) && !$indexer->isScheduled()) {
11061107
$this->_getResource()->addCommitCallback([$this, 'reindex']);
11071108
}
11081109
return parent::afterSave();
@@ -1126,7 +1127,9 @@ public function afterDeleteCommit()
11261127
*/
11271128
public function reindex()
11281129
{
1129-
$this->getIndexer()->reindexRow($this->getId());
1130+
if (!$this->getIndexer()->isScheduled()) {
1131+
$this->getIndexer()->reindexRow($this->getId());
1132+
}
11301133
}
11311134

11321135
/**

app/code/Magento/Customer/etc/di.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2013 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -593,4 +593,9 @@
593593
type="Magento\Customer\Plugin\AsyncRequestCustomerGroupAuthorization"
594594
/>
595595
</type>
596+
<virtualType name="Magento\Customer\Model\MviewAction" type="\Magento\Framework\Mview\View\BaseAction">
597+
<arguments>
598+
<argument name="indexerId" xsi:type="string">customer_grid</argument>
599+
</arguments>
600+
</virtualType>
596601
</config>

app/code/Magento/Customer/etc/indexer.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2015 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
10-
<indexer id="customer_grid" view_id="customer_dummy" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
10+
<indexer id="customer_grid" view_id="customer_grid_flat" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
1111
<title translate="true">Customer Grid</title>
1212
<description translate="true">Rebuild Customer grid index</description>
1313

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2015 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
9-
<view id="customer_dummy" class="Magento\Framework\Indexer\Action\Dummy" group="indexer"/>
9+
<view id="customer_grid_flat" class="Magento\Customer\Model\MviewAction" group="indexer">
10+
<subscriptions>
11+
<table name="customer_entity" entity_column="entity_id" />
12+
<table name="customer_entity_datetime" entity_column="entity_id" />
13+
<table name="customer_entity_decimal" entity_column="entity_id" />
14+
<table name="customer_entity_int" entity_column="entity_id" />
15+
<table name="customer_address_entity" entity_column="parent_id" />
16+
</subscriptions>
17+
</view>
1018
</config>

dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Grid/CollectionTest.php

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Customer\Model\ResourceModel\Grid;
88

99
use Magento\Customer\Api\CustomerRepositoryInterface;
10-
use Magento\Customer\Api\Data\CustomerInterface;
1110
use Magento\Customer\Model\Customer;
1211
use Magento\Framework\Indexer\IndexerRegistry;
1312
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
@@ -19,59 +18,53 @@
1918
*/
2019
class CollectionTest extends TestCase
2120
{
21+
/** @var CustomerRepositoryInterface */
22+
private $customerRepository;
2223

23-
public static function setUpBeforeClass(): void
24-
{
25-
$db = Bootstrap::getInstance()
26-
->getBootstrap()
27-
->getApplication()
28-
->getDbInstance();
29-
if (!$db->isDbDumpExists()) {
30-
throw new \LogicException('DB dump does not exist.');
31-
}
32-
$db->restoreFromDbDump();
24+
/** @var \Magento\Framework\ObjectManagerInterface */
25+
private $objectManager;
3326

34-
$indexerRegistry = Bootstrap::getObjectManager()->create(IndexerRegistry::class);
35-
$indexer = $indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
36-
$indexer->reindexAll();
37-
parent::setUpBeforeClass();
27+
/** @var IndexerRegistry */
28+
private $indexerRegistry;
29+
30+
/** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */
31+
private $targetObject;
32+
33+
protected function setUp(): void
34+
{
35+
$this->objectManager = Bootstrap::getObjectManager();
36+
$this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class);
37+
$this->targetObject = $this->objectManager
38+
->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class);
39+
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
3840
}
3941

4042
/**
41-
* Test updated data for customer grid indexer during save/update customer data(including address data)
43+
* Test updated data for customer grid indexer
4244
* in 'Update on Schedule' mode.
43-
*
44-
* Customer Grid Indexer can't work in 'Update on Schedule' mode. All data for indexer must be updated in realtime
45-
* during save/update customer data(including address data).
46-
*
47-
* @magentoDataFixture Magento/Customer/_files/customer_grid_indexer_enabled_update_on_schedule.php
4845
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
4946
* @magentoAppIsolation enabled
5047
* @magentoDbIsolation disabled
5148
*/
5249
public function testGetItemByIdForUpdateOnSchedule()
5350
{
54-
$targetObject = Bootstrap::getObjectManager()
55-
->create(Collection::class);
56-
$customerRepository = Bootstrap::getObjectManager()
57-
->create(CustomerRepositoryInterface::class);
58-
/** Verify after first save */
59-
60-
/** @var CustomerInterface $newCustomer */
61-
$newCustomer = $customerRepository->get('customer@example.com');
62-
/** @var CustomerInterface $item */
63-
$item = $targetObject->getItemById($newCustomer->getId());
51+
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
52+
$indexer->reindexAll();
53+
$newCustomer = $this->customerRepository->get('customer@example.com');
54+
$item = $this->targetObject->getItemById($newCustomer->getId());
6455
$this->assertNotEmpty($item);
6556
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
6657
$this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull());
6758

68-
/** Verify after update */
59+
/** set customer grid indexer on schedule' mode */
60+
$indexer->setScheduled(true);
6961

62+
/** Verify after update */
7063
$newCustomer->setEmail('customer_updated@example.com');
71-
$customerRepository->save($newCustomer);
72-
$targetObject->clear();
73-
$item = $targetObject->getItemById($newCustomer->getId());
74-
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
64+
$this->customerRepository->save($newCustomer);
65+
$this->targetObject->clear();
66+
$item = $this->targetObject->getItemById($newCustomer->getId());
67+
$this->assertNotEquals('customer_updated@example.com', $item->getEmail());
7568
}
7669

7770
/**

dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/AddressTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
/**
@@ -478,7 +478,8 @@ public function testDifferentOptions(): void
478478
/**
479479
* Test customer indexer gets invalidated after import when Update on Schedule mode is set
480480
*
481-
* @magentoDbIsolation enabled
481+
* @magentoAppIsolation enabled
482+
* @magentoDbIsolation disabled
482483
*/
483484
public function testCustomerIndexer(): void
484485
{

dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/CustomerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\CustomerImportExport\Model\Import;
@@ -495,7 +495,8 @@ public function testUpdateExistingCustomers(): void
495495
/**
496496
* Test customer indexer gets invalidated after import when Update on Schedule mode is set
497497
*
498-
* @magentoDbIsolation enabled
498+
* @magentoAppIsolation enabled
499+
* @magentoDbIsolation disabled
499500
* @return void
500501
*/
501502
public function testCustomerIndexer(): void
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Mview\View;
9+
10+
use Magento\Framework\Indexer\IndexerRegistry;
11+
12+
/**
13+
* Action the use indexer to reindex items
14+
*/
15+
class BaseAction implements \Magento\Framework\Mview\ActionInterface
16+
{
17+
/**
18+
* @param IndexerRegistry $indexerRegistry
19+
* @param string $indexerId
20+
*/
21+
public function __construct(
22+
private IndexerRegistry $indexerRegistry,
23+
private string $indexerId
24+
) {
25+
}
26+
27+
/**
28+
* Execute materialization on ids entities
29+
*
30+
* @param int[] $ids
31+
* @return void
32+
*/
33+
public function execute($ids)
34+
{
35+
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
36+
$indexer = $this->indexerRegistry->get($this->indexerId);
37+
$indexer->reindexList($ids);
38+
}
39+
}

0 commit comments

Comments
 (0)