Skip to content

Commit d8f6151

Browse files
committed
Merge branch 'ACP2E-1505' of https://github.com/magento-l3/magento2ce into PR-01-10-2023
2 parents f5b1563 + 1b3a0c0 commit d8f6151

File tree

2 files changed

+125
-8
lines changed

2 files changed

+125
-8
lines changed

app/code/Magento/Catalog/Setup/Patch/Data/UpdateMultiselectAttributesBackendTypes.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ public function apply()
8181
->select()
8282
->from($varcharTable)
8383
->where('attribute_id in (?)', $attributesToMigrate);
84-
$dataToMigrate = array_map(static function ($row) {
85-
$row['value_id'] = null;
86-
return $row;
87-
}, $connection->fetchAll($varcharTableDataSql));
88-
89-
foreach (array_chunk($dataToMigrate, 2000) as $dataChunk) {
90-
$connection->insertMultiple($textTable, $dataChunk);
91-
}
9284

85+
$columns = $connection->describeTable($varcharTable);
86+
unset($columns['value_id']);
87+
$connection->query(
88+
$connection->insertFromSelect(
89+
$connection->select()
90+
->from($varcharTable, array_keys($columns))
91+
->where('attribute_id in (?)', $attributesToMigrate),
92+
$textTable,
93+
array_keys($columns)
94+
)
95+
);
9396
$connection->query($connection->deleteFromSelect($varcharTableDataSql, $varcharTable));
9497

9598
foreach ($attributesToMigrate as $attributeId) {
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Setup\Patch\Data;
9+
10+
use Magento\Catalog\Setup\Patch\Data\UpdateMultiselectAttributesBackendTypes;
11+
use Magento\Eav\Setup\EavSetup;
12+
use Magento\Eav\Setup\EavSetupFactory;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\DB\Select;
15+
use Magento\Framework\Setup\ModuleDataSetupInterface;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class UpdateMultiselectAttributesBackendTypesTest extends TestCase
19+
{
20+
/**
21+
* @var ModuleDataSetupInterface|\PHPUnit\Framework\MockObject\MockObject
22+
*/
23+
private $dataSetup;
24+
25+
/**
26+
* @var EavSetupFactory|\PHPUnit\Framework\MockObject\MockObject
27+
*/
28+
private $eavSetupFactory;
29+
30+
/**
31+
* @var UpdateMultiselectAttributesBackendTypes
32+
*/
33+
private $model;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
protected function setUp(): void
39+
{
40+
parent::setUp();
41+
$this->dataSetup = $this->createMock(ModuleDataSetupInterface::class);
42+
$this->eavSetupFactory = $this->createMock(EavSetupFactory::class);
43+
$this->model = new UpdateMultiselectAttributesBackendTypes($this->dataSetup, $this->eavSetupFactory);
44+
}
45+
46+
public function testApply(): void
47+
{
48+
$attributeIds = [3, 7];
49+
$entityTypeId = 4;
50+
$eavSetup = $this->createMock(EavSetup::class);
51+
$connection = $this->createMock(AdapterInterface::class);
52+
$select1 = $this->createMock(Select::class);
53+
$select2 = $this->createMock(Select::class);
54+
$select3 = $this->createMock(Select::class);
55+
$this->eavSetupFactory->method('create')
56+
->willReturn($eavSetup);
57+
$this->dataSetup->method('getConnection')
58+
->willReturn($connection);
59+
$this->dataSetup->method('getTable')
60+
->willReturnArgument(0);
61+
$eavSetup->method('getEntityTypeId')
62+
->willReturn(4);
63+
$eavSetup->method('updateAttribute')
64+
->withConsecutive(
65+
[$entityTypeId, 3, 'backend_type', 'text'],
66+
[$entityTypeId, 7, 'backend_type', 'text']
67+
);
68+
$connection->expects($this->exactly(3))
69+
->method('select')
70+
->willReturnOnConsecutiveCalls($select1, $select2, $select3);
71+
$connection->method('describeTable')
72+
->willReturn(
73+
[
74+
'value_id' => [],
75+
'attribute_id' => [],
76+
'store_id' => [],
77+
'value' => [],
78+
'row_id' => [],
79+
]
80+
);
81+
$connection->method('fetchCol')
82+
->with($select1)
83+
->willReturn($attributeIds);
84+
$connection->method('insertFromSelect')
85+
->with($select3, 'catalog_product_entity_text', ['attribute_id', 'store_id', 'value', 'row_id'])
86+
->willReturn('');
87+
$connection->method('deleteFromSelect')
88+
->with($select2, 'catalog_product_entity_varchar')
89+
->willReturn('');
90+
$select1->method('from')
91+
->with('eav_attribute', ['attribute_id'])
92+
->willReturnSelf();
93+
$select1->method('where')
94+
->withConsecutive(
95+
['entity_type_id = ?', $entityTypeId],
96+
['backend_type = ?', 'varchar'],
97+
['frontend_input = ?', 'multiselect']
98+
)
99+
->willReturnSelf();
100+
$select2->method('from')
101+
->with('catalog_product_entity_varchar')
102+
->willReturnSelf();
103+
$select2->method('where')
104+
->with('attribute_id in (?)', $attributeIds)
105+
->willReturnSelf();
106+
$select3->method('from')
107+
->with('catalog_product_entity_varchar', ['attribute_id', 'store_id', 'value', 'row_id'])
108+
->willReturnSelf();
109+
$select3->method('where')
110+
->with('attribute_id in (?)', $attributeIds)
111+
->willReturnSelf();
112+
$this->model->apply();
113+
}
114+
}

0 commit comments

Comments
 (0)