Skip to content

Commit 9f42623

Browse files
author
Mohan Ahuja
committed
ACP2E-726: Unable to query bulk operations by search criteria using REST Api
- Reverted old solution - Added plugin for updating data value for magneto bulk operation
1 parent d14278c commit 9f42623

File tree

6 files changed

+47
-55
lines changed

6 files changed

+47
-55
lines changed

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Class Operation encapsulates methods for Operation Model Object
1313
*/
14-
class Operation extends DataObject implements OperationInterface, BulkOperationInterface
14+
class Operation extends DataObject implements OperationInterface
1515
{
1616
/**
1717
* @var OperationStatusValidator
@@ -37,15 +37,15 @@ public function __construct(
3737
*/
3838
public function getId()
3939
{
40-
return $this->getData(self::OPERATION_ID);
40+
return $this->getData(self::ID);
4141
}
4242

4343
/**
4444
* @inheritDoc
4545
*/
4646
public function setId($id)
4747
{
48-
return $this->setData(self::OPERATION_ID, $id);
48+
return $this->setData(self::ID, $id);
4949
}
5050

5151
/**
@@ -161,22 +161,6 @@ public function setErrorCode($errorCode)
161161
return $this->setData(self::ERROR_CODE, $errorCode);
162162
}
163163

164-
/**
165-
* @inheritDoc
166-
*/
167-
public function getOperationKey(): ?int
168-
{
169-
return $this->getData(self::ID) ? (int) $this->getData(self::ID) : null;
170-
}
171-
172-
/**
173-
* @inheritDoc
174-
*/
175-
public function setOperationKey(?int $operationKey)
176-
{
177-
return $this->setData(self::ID, $operationKey);
178-
}
179-
180164
/**
181165
* Retrieve existing extension attributes object.
182166
*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\AsynchronousOperations\Plugin;
9+
10+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
13+
/**
14+
* Class for bulk operation collection updates for operation key unique values
15+
*/
16+
class CollectionUpdater
17+
{
18+
/**
19+
* Adds id value in operation_key in case of bulk operation
20+
*
21+
* @param AbstractDb $subject
22+
* @param $result
23+
* @return array
24+
* @throws \Magento\Framework\Exception\LocalizedException
25+
*/
26+
public function afterGetData(AbstractDb $subject, $result)
27+
{
28+
if (is_array($result) && !empty($result) &&
29+
$subject->getResource()->getMainTable() == "magento_operation" &&
30+
$subject->getResource()->getTable('magento_bulk') == "magento_bulk"
31+
) {
32+
foreach ($result as $key => $row) {
33+
$result[$key][OperationInterface::ID] = $row['id'];
34+
}
35+
}
36+
37+
return $result;
38+
}
39+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
<argument name="bulkManagement" xsi:type="object">Magento\AsynchronousOperations\Model\VirtualType\BulkManagement</argument>
117117
</arguments>
118118
</type>
119+
<type name="Magento\Framework\Data\Collection\AbstractDb">
120+
<plugin name="collection_updater" type="Magento\AsynchronousOperations\Plugin\CollectionUpdater"/>
121+
</type>
119122
<preference for="Magento\AsynchronousOperations\Api\Data\AsyncResponseInterface" type="Magento\AsynchronousOperations\Model\AsyncResponse" />
120123
<preference for="Magento\AsynchronousOperations\Api\Data\ItemStatusInterface" type="Magento\AsynchronousOperations\Model\ItemStatus" />
121124
</config>

dev/tests/integration/testsuite/Magento/AsynchronousOperations/Cron/MarkIncompleteOperationsAsFailedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testExecute(): void
103103
);
104104
$this->assertEquals(1, $collection->count());
105105
$operation = $collection->getFirstItem();
106-
$this->assertEquals(1, $operation->getOperationKey());
106+
$this->assertEquals(1, $operation->getId());
107107
$this->assertEquals(0, $operation->getErrorCode());
108108
$this->assertEquals('Unknown Error', $operation->getResultMessage());
109109
}

dev/tests/integration/testsuite/Magento/AsynchronousOperations/Model/OperationManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testGetBulkStatus()
6161
}
6262
/** @var OperationInterface $operation */
6363
$operation = array_shift($operations);
64-
$operationId = $operation->getOperationKey();
64+
$operationId = $operation->getId();
6565

6666
$this->assertTrue($this->model->changeOperationStatus(
6767
'bulk-uuid-5',

0 commit comments

Comments
 (0)