Skip to content

Commit 020bbd6

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents c5f6330 + 01e3f19 commit 020bbd6

File tree

36 files changed

+1087
-230
lines changed

36 files changed

+1087
-230
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Api;
10+
11+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
12+
13+
/**
14+
* Interface for saving multiple operations
15+
*
16+
* @api
17+
*/
18+
interface SaveMultipleOperationsInterface
19+
{
20+
/**
21+
* Save Operations for Bulk
22+
*
23+
* @param OperationInterface[] $operations
24+
* @return void
25+
*/
26+
public function execute(array $operations): void;
27+
}

app/code/Magento/AsynchronousOperations/Model/BulkManagement.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public function scheduleBulk($bulkUuid, array $operations, $description, $userId
117117
$bulkSummary->setUserId($userId);
118118
$bulkSummary->setUserType($userType);
119119
$bulkSummary->setOperationCount((int)$bulkSummary->getOperationCount() + count($operations));
120-
121120
$this->entityManager->save($bulkSummary);
122121

123122
$connection->commit();

app/code/Magento/AsynchronousOperations/Model/MassSchedule.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Bulk\BulkManagementInterface;
1717
use Magento\Framework\DataObject\IdentityGeneratorInterface;
1818
use Magento\Framework\Encryption\Encryptor;
19+
use Magento\AsynchronousOperations\Api\SaveMultipleOperationsInterface;
1920
use Magento\Framework\Exception\BulkException;
2021
use Magento\Framework\Exception\LocalizedException;
2122
use Psr\Log\LoggerInterface;
@@ -67,6 +68,11 @@ class MassSchedule
6768
*/
6869
private $encryptor;
6970

71+
/**
72+
* @var SaveMultipleOperationsInterface
73+
*/
74+
private $saveMultipleOperations;
75+
7076
/**
7177
* Initialize dependencies.
7278
*
@@ -78,6 +84,7 @@ class MassSchedule
7884
* @param OperationRepositoryInterface $operationRepository
7985
* @param UserContextInterface $userContext
8086
* @param Encryptor $encryptor
87+
* @param SaveMultipleOperationsInterface $saveMultipleOperations
8188
*/
8289
public function __construct(
8390
IdentityGeneratorInterface $identityService,
@@ -87,7 +94,8 @@ public function __construct(
8794
LoggerInterface $logger,
8895
OperationRepositoryInterface $operationRepository,
8996
UserContextInterface $userContext,
90-
Encryptor $encryptor
97+
Encryptor $encryptor,
98+
SaveMultipleOperationsInterface $saveMultipleOperations
9199
) {
92100
$this->identityService = $identityService;
93101
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
@@ -97,6 +105,7 @@ public function __construct(
97105
$this->operationRepository = $operationRepository;
98106
$this->userContext = $userContext;
99107
$this->encryptor = $encryptor;
108+
$this->saveMultipleOperations = $saveMultipleOperations;
100109
}
101110

102111
/**
@@ -159,6 +168,7 @@ public function publishMass($topicName, array $entitiesArray, $groupId = null, $
159168
}
160169
}
161170

171+
$this->saveMultipleOperations->execute($operations);
162172
if (!$this->bulkManagement->scheduleBulk($groupId, $operations, $bulkDescription, $userId)) {
163173
throw new LocalizedException(
164174
__('Something went wrong while processing the request.')

app/code/Magento/AsynchronousOperations/Model/OperationManagement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\EntityManager\EntityManager;
1111

1212
/**
13-
* Class OperationManagement
13+
* Class for managing Bulk Operations
1414
*/
1515
class OperationManagement implements \Magento\Framework\Bulk\OperationManagementInterface
1616
{
@@ -45,7 +45,7 @@ public function __construct(
4545
$this->operationFactory = $operationFactory;
4646
$this->logger = $logger;
4747
}
48-
48+
4949
/**
5050
* @inheritDoc
5151
*/

app/code/Magento/AsynchronousOperations/Model/ResourceModel/Operation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
namespace Magento\AsynchronousOperations\Model\ResourceModel;
88

99
/**
10-
* Class Operation
10+
* Resource class for Bulk Operations
1111
*/
1212
class Operation extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1313
{
14+
15+
public const TABLE_NAME = "magento_operation";
16+
public const TABLE_PRIMARY_KEY = "id";
17+
1418
/**
1519
* Initialize banner sales rule resource model
1620
*
1721
* @return void
1822
*/
1923
protected function _construct()
2024
{
21-
$this->_init('magento_operation', 'id');
25+
$this->_init(self::TABLE_NAME, self::TABLE_PRIMARY_KEY);
2226
}
2327
}

app/code/Magento/AsynchronousOperations/Model/ResourceModel/Operation/OperationRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function createByTopic($topicName, $entityParams, $groupId)
9898

9999
/** @var OperationInterface $operation */
100100
$operation = $this->operationFactory->create($data);
101-
return $this->entityManager->save($operation);
101+
return $operation;
102102
}
103103

104104
/**
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Model;
10+
11+
use Magento\AsynchronousOperations\Api\SaveMultipleOperationsInterface;
12+
use Magento\AsynchronousOperations\Model\ResourceModel\Operation as OperationResource;
13+
use Magento\Framework\Exception\CouldNotSaveException;
14+
15+
/**
16+
* Implementation for saving multiple operations
17+
*/
18+
class SaveMultipleOperations implements SaveMultipleOperationsInterface
19+
{
20+
21+
/**
22+
* @var OperationResource
23+
*/
24+
private $operationResource;
25+
26+
/**
27+
* BulkSummary constructor.
28+
*
29+
* @param OperationResource $operationResource
30+
*/
31+
public function __construct(
32+
OperationResource $operationResource
33+
) {
34+
$this->operationResource = $operationResource;
35+
}
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
public function execute(array $operations): void
41+
{
42+
try {
43+
$operationsToInsert = array_map(function ($operation) {
44+
return $operation->getData();
45+
}, $operations);
46+
47+
$connection = $this->operationResource->getConnection();
48+
$connection->insertMultiple(
49+
$this->operationResource->getTable(OperationResource::TABLE_NAME),
50+
$operationsToInsert
51+
);
52+
} catch (\Exception $exception) {
53+
throw new CouldNotSaveException(__($exception->getMessage()));
54+
}
55+
}
56+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface" type="Magento\AsynchronousOperations\Model\BulkSummary" />
10+
<preference for="Magento\AsynchronousOperations\Api\SaveMultipleOperationsInterface" type="Magento\AsynchronousOperations\Model\SaveMultipleOperations" />
1011
<preference for="Magento\AsynchronousOperations\Api\Data\OperationInterface" type="Magento\AsynchronousOperations\Model\Operation" />
1112
<preference for="Magento\AsynchronousOperations\Api\Data\OperationListInterface" type="Magento\AsynchronousOperations\Model\OperationList" />
1213
<preference for="Magento\Framework\Bulk\BulkManagementInterface" type="Magento\AsynchronousOperations\Model\BulkManagement" />

app/code/Magento/Backend/Test/Mftf/Test/AdminLoginWithRestrictPermissionTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
<!--Create user role-->
2525
<actionGroup ref="AdminFillUserRoleRequiredDataActionGroup" stepKey="fillUserRoleRequiredData">
2626
<argument name="User" value="adminRole"/>
27-
<argument name="restrictedRole" value="Media Gallery"/>
27+
<argument name="restrictedRole" value="Global Search"/>
2828
</actionGroup>
2929
<actionGroup ref="AdminUserClickRoleResourceTabActionGroup" stepKey="switchToRoleResourceTab"/>
3030
<actionGroup ref="AdminAddRestrictedRoleActionGroup" stepKey="addRestrictedRoleStores">
3131
<argument name="User" value="adminRole"/>
32-
<argument name="restrictedRole" value="Media Gallery"/>
32+
<argument name="restrictedRole" value="Global Search"/>
3333
</actionGroup>
3434
<actionGroup ref="AdminUserSaveRoleActionGroup" stepKey="saveRole"/>
3535
<!--Create user and assign role to it-->

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ public function execute($id = null)
8585
$ids = [$id];
8686
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8787

88+
$storeIds = $this->getAssignedStoreIdsOfProduct($id);
89+
8890
$stores = $this->_storeManager->getStores();
8991
foreach ($stores as $store) {
9092
$tableExists = $this->_isFlatTableExists($store->getId());
9193
if ($tableExists) {
94+
if (!in_array($store->getId(), $storeIds)) {
95+
$this->flatItemEraser->deleteProductsFromStore($id, $store->getId());
96+
continue;
97+
}
9298
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
9399
$this->flatItemEraser->removeDisabledProducts($ids, $store->getId());
94100
}
@@ -129,4 +135,23 @@ public function execute($id = null)
129135

130136
return $this;
131137
}
138+
139+
/**
140+
* Get list store id where the product is enable
141+
*
142+
* @param int $productId
143+
* @return array
144+
*/
145+
private function getAssignedStoreIdsOfProduct($productId)
146+
{
147+
$select = $this->_connection->select();
148+
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
149+
->where('c.product_id = ' . $productId)
150+
->joinLeft(
151+
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
152+
'e.website_id = c.website_id',
153+
[]
154+
);
155+
return $this->_connection->fetchCol($select);
156+
}
132157
}

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/RowTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ public function testExecuteWithExistingFlatTablesCreatesTables()
160160
->willReturn('store_flat_table');
161161
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
162162
->willReturn(true);
163+
$this->connection->expects($this->any())->method('fetchCol')
164+
->willReturn(['store_id_1']);
163165
$this->flatItemEraser->expects($this->once())->method('removeDeletedProducts');
164166
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
165167
$this->model->execute('product_id_1');
166168
}
169+
170+
public function testExecuteWithExistingFlatTablesRemoveProductFromStore()
171+
{
172+
$this->productIndexerHelper->expects($this->any())->method('getFlatTableName')
173+
->willReturn('store_flat_table');
174+
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
175+
->willReturn(true);
176+
$this->connection->expects($this->any())->method('fetchCol')
177+
->willReturn([1]);
178+
$this->flatItemEraser->expects($this->once())->method('deleteProductsFromStore');
179+
$this->flatItemEraser->expects($this->never())->method('removeDeletedProducts');
180+
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
181+
$this->model->execute('product_id_1');
182+
}
167183
}

app/code/Magento/Quote/Model/Cart/CartTotalRepository.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Quote\Model\Cart;
710

811
use Magento\Quote\Api;
@@ -12,9 +15,11 @@
1215
use Magento\Framework\Api\ExtensibleDataInterface;
1316
use Magento\Quote\Model\Cart\Totals\ItemConverter;
1417
use Magento\Quote\Api\CouponManagementInterface;
18+
use Magento\Quote\Api\Data\TotalsInterface as QuoteTotalsInterface;
1519

1620
/**
1721
* Cart totals data object.
22+
*
1823
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1924
*/
2025
class CartTotalRepository implements CartTotalRepositoryInterface
@@ -79,11 +84,8 @@ public function __construct(
7984

8085
/**
8186
* @inheritdoc
82-
*
83-
* @param int $cartId The cart ID.
84-
* @return Totals Quote totals data.
8587
*/
86-
public function get($cartId)
88+
public function get($cartId): QuoteTotalsInterface
8789
{
8890
/** @var \Magento\Quote\Model\Quote $quote */
8991
$quote = $this->quoteRepository->getActive($cartId);
@@ -96,17 +98,14 @@ public function get($cartId)
9698
}
9799
unset($addressTotalsData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
98100

99-
/** @var \Magento\Quote\Api\Data\TotalsInterface $quoteTotals */
101+
/** @var QuoteTotalsInterface $quoteTotals */
100102
$quoteTotals = $this->totalsFactory->create();
101103
$this->dataObjectHelper->populateWithArray(
102104
$quoteTotals,
103105
$addressTotalsData,
104-
\Magento\Quote\Api\Data\TotalsInterface::class
106+
QuoteTotalsInterface::class
105107
);
106-
$items = [];
107-
foreach ($quote->getAllVisibleItems() as $index => $item) {
108-
$items[$index] = $this->itemConverter->modelToDataObject($item);
109-
}
108+
$items = array_map([$this->itemConverter, 'modelToDataObject'], $quote->getAllVisibleItems());
110109
$calculatedTotals = $this->totalsConverter->process($addressTotals);
111110
$quoteTotals->setTotalSegments($calculatedTotals);
112111

0 commit comments

Comments
 (0)