Skip to content

Cleanup ObjectManager usage - Magento_AsynchronousOperations #27083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions app/code/Magento/AsynchronousOperations/Model/BulkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AsynchronousOperations\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResourceConnection;
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory;
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
use Magento\Framework\MessageQueue\BulkPublisherInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Bulk\BulkManagementInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\MessageQueue\BulkPublisherInterface;
use Psr\Log\LoggerInterface;

/**
* Class BulkManagement
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* Asynchronous Bulk Management
*/
class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
class BulkManagement implements BulkManagementInterface
{
/**
* @var EntityManager
Expand Down Expand Up @@ -54,12 +55,12 @@ class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
private $resourceConnection;

/**
* @var \Magento\Authorization\Model\UserContextInterface
* @var UserContextInterface
*/
private $userContext;

/**
* @var \Psr\Log\LoggerInterface
* @var LoggerInterface
*/
private $logger;

Expand All @@ -71,7 +72,7 @@ class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
* @param BulkPublisherInterface $publisher
* @param MetadataPool $metadataPool
* @param ResourceConnection $resourceConnection
* @param \Psr\Log\LoggerInterface $logger
* @param LoggerInterface $logger
* @param UserContextInterface $userContext
*/
public function __construct(
Expand All @@ -81,8 +82,8 @@ public function __construct(
BulkPublisherInterface $publisher,
MetadataPool $metadataPool,
ResourceConnection $resourceConnection,
\Psr\Log\LoggerInterface $logger,
UserContextInterface $userContext = null
LoggerInterface $logger,
UserContextInterface $userContext
) {
$this->entityManager = $entityManager;
$this->bulkSummaryFactory= $bulkSummaryFactory;
Expand All @@ -91,7 +92,7 @@ public function __construct(
$this->resourceConnection = $resourceConnection;
$this->publisher = $publisher;
$this->logger = $logger;
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
$this->userContext = $userContext;
}

/**
Expand Down
20 changes: 9 additions & 11 deletions app/code/Magento/AsynchronousOperations/Model/MassConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AsynchronousOperations\Model;

use Magento\Framework\Registry;
use Magento\Framework\MessageQueue\CallbackInvokerInterface;
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
use Magento\Framework\MessageQueue\ConsumerInterface;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Magento\Framework\MessageQueue\QueueInterface;
use Magento\Framework\MessageQueue\ConsumerInterface;
use Magento\Framework\Registry;

/**
* Class Consumer used to process OperationInterface messages.
Expand All @@ -28,19 +27,19 @@ class MassConsumer implements ConsumerInterface
private $invoker;

/**
* @var \Magento\Framework\MessageQueue\ConsumerConfigurationInterface
* @var ConsumerConfigurationInterface
*/
private $configuration;

/**
* @var Registry
* @var MassConsumerEnvelopeCallbackFactory
*/
private $registry;
private $massConsumerEnvelopeCallback;

/**
* @var MassConsumerEnvelopeCallbackFactory
* @var Registry
*/
private $massConsumerEnvelopeCallback;
private $registry;

/**
* Initialize dependencies.
Expand All @@ -54,13 +53,12 @@ public function __construct(
CallbackInvokerInterface $invoker,
ConsumerConfigurationInterface $configuration,
MassConsumerEnvelopeCallbackFactory $massConsumerEnvelopeCallback,
Registry $registry = null
Registry $registry
) {
$this->invoker = $invoker;
$this->configuration = $configuration;
$this->massConsumerEnvelopeCallback = $massConsumerEnvelopeCallback;
$this->registry = $registry ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(Registry::class);
$this->registry = $registry;
}

/**
Expand Down
30 changes: 14 additions & 16 deletions app/code/Magento/AsynchronousOperations/Model/MassSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AsynchronousOperations\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject\IdentityGeneratorInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory;
use Magento\AsynchronousOperations\Api\Data\AsyncResponseInterface;
use Magento\AsynchronousOperations\Api\Data\AsyncResponseInterfaceFactory;
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterface;
use Magento\Framework\Bulk\BulkManagementInterface;
use Magento\Framework\Exception\BulkException;
use Psr\Log\LoggerInterface;
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory;
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\OperationRepository;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\Bulk\BulkManagementInterface;
use Magento\Framework\DataObject\IdentityGeneratorInterface;
use Magento\Framework\Encryption\Encryptor;
use Magento\Framework\Exception\BulkException;
use Magento\Framework\Exception\LocalizedException;
use Psr\Log\LoggerInterface;

/**
* Class MassSchedule used for adding multiple entities as Operations to Bulk Management with the status tracking
Expand All @@ -30,7 +28,7 @@
class MassSchedule
{
/**
* @var \Magento\Framework\DataObject\IdentityGeneratorInterface
* @var IdentityGeneratorInterface
*/
private $identityService;

Expand All @@ -45,7 +43,7 @@ class MassSchedule
private $itemStatusInterfaceFactory;

/**
* @var \Magento\Framework\Bulk\BulkManagementInterface
* @var BulkManagementInterface
*/
private $bulkManagement;

Expand All @@ -60,7 +58,7 @@ class MassSchedule
private $operationRepository;

/**
* @var \Magento\Authorization\Model\UserContextInterface
* @var UserContextInterface
*/
private $userContext;

Expand All @@ -79,7 +77,7 @@ class MassSchedule
* @param LoggerInterface $logger
* @param OperationRepository $operationRepository
* @param UserContextInterface $userContext
* @param Encryptor|null $encryptor
* @param Encryptor $encryptor
*/
public function __construct(
IdentityGeneratorInterface $identityService,
Expand All @@ -88,17 +86,17 @@ public function __construct(
BulkManagementInterface $bulkManagement,
LoggerInterface $logger,
OperationRepository $operationRepository,
UserContextInterface $userContext = null,
Encryptor $encryptor = null
UserContextInterface $userContext,
Encryptor $encryptor
) {
$this->identityService = $identityService;
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
$this->asyncResponseFactory = $asyncResponseFactory;
$this->bulkManagement = $bulkManagement;
$this->logger = $logger;
$this->operationRepository = $operationRepository;
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
$this->encryptor = $encryptor ?: ObjectManager::getInstance()->get(Encryptor::class);
$this->userContext = $userContext;
$this->encryptor = $encryptor;
}

/**
Expand Down