Skip to content

Commit a9db5c7

Browse files
author
Magento CICD
authored
merge magento/2.2-develop into magento-mpi/pr-regression-ece
2 parents 0af1f2d + 22b7543 commit a9db5c7

File tree

7 files changed

+174
-8
lines changed

7 files changed

+174
-8
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,7 @@ public function reindex()
351351
{
352352
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
353353
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
354-
if (!$indexer->isScheduled()) {
355-
$indexer->reindexRow($this->getCustomerId());
356-
}
354+
$indexer->reindexRow($this->getCustomerId());
357355
}
358356

359357
/**

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,7 @@ public function reindex()
10771077
{
10781078
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
10791079
$indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1080-
if (!$indexer->isScheduled()) {
1081-
$indexer->reindexRow($this->getId());
1082-
}
1080+
$indexer->reindexRow($this->getId());
10831081
}
10841082

10851083
/**

app/code/Magento/Deploy/Model/Mode.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Config\File\ConfigFilePool;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Magento\Framework\Exception\LocalizedException;
1718

1819
/**
1920
* A class to manage Magento modes
@@ -75,13 +76,23 @@ public function __construct(
7576
/**
7677
* Enable production mode
7778
*
79+
* @throws LocalizedException
7880
* @return void
7981
*/
8082
public function enableProductionMode()
8183
{
8284
$this->enableMaintenanceMode($this->output);
83-
$this->filesystem->regenerateStatic($this->output);
84-
$this->setStoreMode(State::MODE_PRODUCTION);
85+
$previousMode = $this->getMode();
86+
try {
87+
// We have to turn on production mode before generation.
88+
// We need this to enable generation of the "min" files.
89+
$this->setStoreMode(State::MODE_PRODUCTION);
90+
$this->filesystem->regenerateStatic($this->output);
91+
} catch (LocalizedException $e) {
92+
// We have to return store mode to previous state in case of error.
93+
$this->setStoreMode($previousMode);
94+
throw $e;
95+
}
8596
$this->disableMaintenanceMode($this->output);
8697
}
8798

app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit_Framework_MockObject_MockObject as Mock;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Magento\Framework\Config\File\ConfigFilePool;
18+
use Magento\Framework\Exception\LocalizedException;
1719

1820
/**
1921
* @inheritdoc
@@ -96,4 +98,71 @@ public function testGetMode()
9698
$this->assertSame(null, $this->model->getMode());
9799
$this->assertSame(State::MODE_DEVELOPER, $this->model->getMode());
98100
}
101+
102+
/**
103+
* Test that production mode will be enabled before static generation call.
104+
* We need this to be sure that "min" files will be generated.
105+
*/
106+
public function testEnableProductionMode()
107+
{
108+
$mode = State::MODE_DEVELOPER;
109+
$modeModel = $this->model;
110+
$dataStorage = [
111+
ConfigFilePool::APP_ENV => [
112+
State::PARAM_MODE => State::MODE_DEVELOPER,
113+
],
114+
];
115+
$this->writerMock->expects($this->once())
116+
->method("saveConfig")
117+
->willReturnCallback(function ($data) use (&$dataStorage) {
118+
$dataStorage = $data;
119+
});
120+
$this->readerMock->expects($this->any())
121+
->method('load')
122+
->willReturnCallback(function () use (&$dataStorage) {
123+
return $dataStorage[ConfigFilePool::APP_ENV];
124+
});
125+
$this->filesystemMock->expects($this->once())
126+
->method("regenerateStatic")
127+
->willReturnCallback(function () use (&$modeModel, &$mode) {
128+
$mode = $modeModel->getMode();
129+
});
130+
$this->model->enableProductionMode();
131+
$this->assertEquals(State::MODE_PRODUCTION, $mode);
132+
}
133+
134+
/**
135+
* Test that previous mode will be enabled after error during static generation call.
136+
* We need this to be sure that mode will be reverted to it previous tate.
137+
*
138+
* @expectedException \Magento\Framework\Exception\LocalizedException
139+
*/
140+
public function testEnableDeveloperModeOnFail()
141+
{
142+
$mode = State::MODE_DEVELOPER;
143+
$dataStorage = [
144+
ConfigFilePool::APP_ENV => [
145+
State::PARAM_MODE => State::MODE_DEVELOPER,
146+
],
147+
];
148+
$this->writerMock->expects($this->exactly(2))
149+
->method("saveConfig")
150+
->withConsecutive(
151+
[$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_PRODUCTION]])],
152+
[$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_DEVELOPER]])]
153+
)
154+
->willReturnCallback(function ($data) use (&$dataStorage) {
155+
$dataStorage = $data;
156+
});
157+
$this->readerMock->expects($this->any())
158+
->method('load')
159+
->willReturnCallback(function () use (&$dataStorage) {
160+
return $dataStorage[ConfigFilePool::APP_ENV];
161+
});
162+
$this->filesystemMock->expects($this->once())
163+
->method("regenerateStatic")
164+
->willThrowException(new LocalizedException(__('Exception')));
165+
$this->model->enableProductionMode();
166+
$this->assertEquals(State::MODE_PRODUCTION, $mode);
167+
}
99168
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model\ResourceModel\Grid;
8+
9+
use Magento\Customer\Api\CustomerRepositoryInterface;
10+
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Framework\Indexer\IndexerRegistry;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* Customer grid collection tests.
16+
*/
17+
class CollectionTest extends \Magento\TestFramework\Indexer\TestCase
18+
{
19+
/** @var \Magento\Framework\ObjectManagerInterface */
20+
private $objectManager;
21+
22+
/** @var IndexerRegistry */
23+
private $indexerRegistry;
24+
25+
/** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */
26+
private $targetObject;
27+
28+
/** @var CustomerRepositoryInterface */
29+
private $customerRepository;
30+
31+
protected function setUp()
32+
{
33+
$this->objectManager = Bootstrap::getObjectManager();
34+
$this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class);
35+
$this->targetObject = $this->objectManager
36+
->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class);
37+
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
38+
}
39+
40+
/**
41+
* Test updated data for customer grid indexer during save/update customer data(including address data)
42+
* 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
48+
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
49+
*/
50+
public function testGetItemByIdForUpdateOnSchedule()
51+
{
52+
/** Verify after first save */
53+
/** @var CustomerInterface $newCustomer */
54+
$newCustomer = $this->customerRepository->get('customer@example.com');
55+
/** @var CustomerInterface $item */
56+
$item = $this->targetObject->getItemById($newCustomer->getId());
57+
$this->assertNotEmpty($item);
58+
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
59+
$this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull());
60+
61+
/** Verify after update */
62+
$newCustomer->setEmail('customer_updated@example.com');
63+
$this->customerRepository->save($newCustomer);
64+
$this->targetObject->clear();
65+
$item = $this->targetObject->getItemById($newCustomer->getId());
66+
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
/** @var Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
9+
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
10+
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
11+
$indexer->setScheduled(true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
/** @var Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
9+
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
10+
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
11+
$indexer->setScheduled(false);

0 commit comments

Comments
 (0)