Skip to content

Commit 14e9cc8

Browse files
committed
ACP2E-3813: Updating products using the Mass Action, resulted in an unexpected system logout
1 parent b1e9f22 commit 14e9cc8

File tree

5 files changed

+95
-107
lines changed

5 files changed

+95
-107
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function execute()
143143
$this->validateProductAttributes($attributesData);
144144
$this->publish($attributesData, $websiteRemoveData, $websiteAddData, $storeId, $websiteId, $productIds);
145145
$this->messageManager->addSuccessMessage(__('Message is added to queue'));
146+
$this->attributeHelper->setProductIds([]);
146147
} catch (LocalizedException $e) {
147148
$this->messageManager->addErrorMessage($e->getMessage());
148149
} catch (\Exception $e) {

app/design/adminhtml/Magento/backend/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,4 @@ Dashboard,Dashboard
549549
"Email to a Friend","Email to a Friend"
550550
"Invalid data type","Invalid data type"
551551
"Invalid value provided for attribute %1","Invalid value provided for attribute %1"
552-
"The current session size exceeds configured maximum session size, consider increasing the configured value.","The current session size exceeds configured maximum session size, consider increasing the configured value."
552+

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php renamed to dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php

Lines changed: 18 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
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
*/
6-
namespace Magento\Catalog\Controller\Adminhtml\Product\Action;
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute;
79

810
use Magento\Backend\Model\Session;
911
use Magento\Catalog\Block\Product\ListProduct;
1012
use Magento\Catalog\Helper\Product\Edit\Action\Attribute;
1113
use Magento\Catalog\Model\CategoryFactory;
1214
use Magento\Catalog\Model\Product\Visibility;
13-
use Magento\Framework\Message\MessageInterface;
1415
use Magento\Catalog\Model\ProductRepository;
1516
use Magento\Framework\App\Request\Http as HttpRequest;
17+
use Magento\Framework\Message\MessageInterface;
1618
use Magento\Framework\UrlInterface;
17-
use Magento\TestFramework\Helper\Bootstrap;
1819
use Magento\TestFramework\MessageQueue\EnvironmentPreconditionException;
1920
use Magento\TestFramework\MessageQueue\PreconditionFailedException;
2021
use Magento\TestFramework\MessageQueue\PublisherConsumerController;
2122
use Magento\TestFramework\TestCase\AbstractBackendController;
2223

2324
/**
25+
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
2426
* @magentoAppArea adminhtml
2527
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
27-
class AttributeTest extends AbstractBackendController
29+
class SaveTest extends AbstractBackendController
2830
{
2931
/** @var PublisherConsumerController */
3032
private $publisherConsumerController;
33+
3134
/**
3235
* @var string[]
3336
*/
@@ -39,22 +42,14 @@ protected function setUp(): void
3942

4043
$this->publisherConsumerController = $this->_objectManager->create(
4144
PublisherConsumerController::class,
42-
[
43-
'consumers' => $this->consumers,
44-
'logFilePath' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt",
45-
'maxMessages' => null,
46-
'appInitParams' => Bootstrap::getInstance()->getAppInitParams()
47-
]
45+
['consumers' => $this->consumers]
4846
);
49-
5047
try {
5148
$this->publisherConsumerController->startConsumers();
5249
} catch (EnvironmentPreconditionException $e) {
5350
$this->markTestSkipped($e->getMessage());
5451
} catch (PreconditionFailedException $e) {
55-
$this->fail(
56-
$e->getMessage()
57-
);
52+
$this->fail($e->getMessage());
5853
}
5954
}
6055

@@ -65,12 +60,10 @@ protected function tearDown(): void
6560
}
6661

6762
/**
68-
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
69-
*
7063
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
7164
* @magentoDbIsolation disabled
7265
*/
73-
public function testSaveActionRedirectsSuccessfully()
66+
public function testSaveActionRedirectsSuccessfully(): void
7467
{
7568
/** @var $session Session */
7669
$session = $this->_objectManager->get(Session::class);
@@ -100,14 +93,12 @@ public function testSaveActionRedirectsSuccessfully()
10093
}
10194

10295
/**
103-
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
104-
*
10596
* @dataProvider saveActionVisibilityAttrDataProvider
10697
* @param array $attributes
10798
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
10899
* @magentoDbIsolation disabled
109100
*/
110-
public function testSaveActionChangeVisibility($attributes)
101+
public function testSaveActionChangeVisibility(array $attributes): void
111102
{
112103
/** @var ProductRepository $repository */
113104
$repository = $this->_objectManager->create(ProductRepository::class);
@@ -129,88 +120,26 @@ public function testSaveActionChangeVisibility($attributes)
129120
/** @var ListProduct $listProduct */
130121
$listProduct = $this->_objectManager->get(ListProduct::class);
131122

132-
sleep(30); // timeout to processing queue
133123
$this->publisherConsumerController->waitForAsynchronousResult(
134-
function () use ($repository) {
135-
sleep(10); // Should be refactored in the scope of MC-22947
136-
return $repository->get(
137-
'simple',
138-
false,
139-
null,
140-
true
141-
)->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE;
142-
},
143-
[]
124+
fn () => (int) $repository->get('simple', forceReload: true)->getVisibility()
125+
!== Visibility::VISIBILITY_NOT_VISIBLE
144126
);
145127

146128
$category = $categoryFactory->create()->load(2);
147129
$layer = $listProduct->getLayer();
148130
$layer->setCurrentCategory($category);
149131
$productCollection = $layer->getProductCollection();
150132
$productItem = $productCollection->getFirstItem();
151-
$this->assertEquals($session->getProductIds(), [$productItem->getId()]);
152-
}
153-
154-
/**
155-
* @param array $attributes Request parameter.
156-
*
157-
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute
158-
*
159-
* @dataProvider validateActionDataProvider
160-
*
161-
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
162-
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
163-
* @magentoDbIsolation disabled
164-
*/
165-
public function testValidateActionWithMassUpdate($attributes)
166-
{
167-
/** @var $session Session */
168-
$session = $this->_objectManager->get(Session::class);
169-
$session->setProductIds([1, 2]);
170-
171-
$this->getRequest()->setParam('attributes', $attributes);
172-
173-
$this->dispatch('backend/catalog/product_action_attribute/validate/store/0');
174-
175-
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
176-
177-
$response = $this->getResponse()->getBody();
178-
$this->assertJson($response);
179-
$data = json_decode($response, true);
180-
$this->assertArrayHasKey('error', $data);
181-
$this->assertFalse($data['error']);
182-
$this->assertCount(1, $data);
183-
}
184-
185-
/**
186-
* Data Provider for validation
187-
*
188-
* @return array
189-
*/
190-
public static function validateActionDataProvider()
191-
{
192-
return [
193-
[
194-
'attributes' => [
195-
'name' => 'Name',
196-
'description' => 'Description',
197-
'short_description' => 'Short Description',
198-
'price' => '512',
199-
'weight' => '16',
200-
'meta_title' => 'Meta Title',
201-
'meta_keyword' => 'Meta Keywords',
202-
'meta_description' => 'Meta Description',
203-
],
204-
]
205-
];
133+
$this->assertEquals([$product->getId()], [$productItem->getId()]);
134+
$this->assertEmpty($session->getProductIds());
206135
}
207136

208137
/**
209138
* Data Provider for save with visibility attribute
210139
*
211140
* @return array
212141
*/
213-
public static function saveActionVisibilityAttrDataProvider()
142+
public static function saveActionVisibilityAttrDataProvider(): array
214143
{
215144
return [
216145
['attributes' => ['visibility' => Visibility::VISIBILITY_BOTH]],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute;
9+
10+
use Magento\Backend\Model\Session;
11+
use Magento\Catalog\Model\CategoryFactory;
12+
use Magento\TestFramework\TestCase\AbstractBackendController;
13+
14+
/**
15+
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute
16+
* @magentoAppArea adminhtml
17+
*/
18+
class ValidateTest extends AbstractBackendController
19+
{
20+
/**
21+
* @param array $attributes Request parameter.
22+
* @dataProvider validateActionDataProvider
23+
*
24+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
25+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
26+
* @magentoDbIsolation disabled
27+
*/
28+
public function testValidateActionWithMassUpdate(array $attributes): void
29+
{
30+
$session = $this->_objectManager->get(Session::class);
31+
$session->setProductIds([1, 2]);
32+
33+
$this->getRequest()->setParam('attributes', $attributes);
34+
$this->dispatch('backend/catalog/product_action_attribute/validate/store/0');
35+
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
36+
37+
$response = $this->getResponse()->getBody();
38+
$this->assertJson($response);
39+
$data = json_decode($response, true);
40+
$this->assertArrayHasKey('error', $data);
41+
$this->assertFalse($data['error']);
42+
$this->assertCount(1, $data);
43+
}
44+
45+
/**
46+
* Data Provider for validation
47+
*
48+
* @return array
49+
*/
50+
public static function validateActionDataProvider(): array
51+
{
52+
return [
53+
[
54+
'attributes' => [
55+
'name' => 'Name',
56+
'description' => 'Description',
57+
'short_description' => 'Short Description',
58+
'price' => '512',
59+
'weight' => '16',
60+
'meta_title' => 'Meta Title',
61+
'meta_keyword' => 'Meta Keywords',
62+
'meta_description' => 'Meta Description',
63+
],
64+
],
65+
];
66+
}
67+
}

lib/internal/Magento/Framework/Session/SaveHandler.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,14 @@ public function read($sessionId): string
125125
$sessionMaxSize = $this->sessionMaxSizeConfig->getSessionMaxSize();
126126
$sessionSize = $sessionData !== null ? strlen($sessionData) : 0;
127127

128-
if ($sessionMaxSize !== null && $sessionMaxSize < $sessionSize) {
129-
switch ($this->appState->getAreaCode()) {
130-
case Area::AREA_ADMINHTML:
131-
$this->messageManager->addNoticeMessage(
132-
__(
133-
'The current session size exceeds configured maximum session size,'
134-
. ' consider increasing the configured value.'
135-
)
136-
);
137-
break;
138-
case Area::AREA_FRONTEND:
139-
$this->messageManager->addErrorMessage(
140-
__('There is an error. Please Contact store administrator.')
141-
);
142-
//clear session data for all areas other than adminhtml
143-
default:
144-
$sessionData = '';
128+
if ($sessionMaxSize !== null && $sessionMaxSize < $sessionSize
129+
&& $this->appState->getAreaCode() !== Area::AREA_ADMINHTML
130+
) {
131+
$sessionData = '';
132+
if ($this->appState->getAreaCode() === Area::AREA_FRONTEND) {
133+
$this->messageManager->addErrorMessage(
134+
__('There is an error. Please Contact store administrator.')
135+
);
145136
}
146137
}
147138

0 commit comments

Comments
 (0)