Skip to content
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

Remove direct use of object manager #16851

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@
*/
namespace Magento\Newsletter\Controller\Adminhtml\Subscriber;

class MassDelete extends \Magento\Newsletter\Controller\Adminhtml\Subscriber
use Magento\Newsletter\Controller\Adminhtml\Subscriber;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Framework\App\ObjectManager;

class MassDelete extends Subscriber
{
/**
* @var SubscriberFactory
*/
private $subscriberFactory;

/**
* @param Context $context
* @param FileFactory $fileFactory
*/
public function __construct(
Context $context,
FileFactory $fileFactory,
SubscriberFactory $subscriberFactory = null
) {
$this->subscriberFactory = $subscriberFactory ?: ObjectManager::getInstance()->get(SubscriberFactory::class);
parent::__construct($context, $fileFactory);
}

/**
* Delete one or more subscribers action
*
Expand All @@ -21,9 +45,7 @@ public function execute()
} else {
try {
foreach ($subscribersIds as $subscriberId) {
$subscriber = $this->_objectManager->create(
\Magento\Newsletter\Model\Subscriber::class
)->load(
$subscriber = $this->subscriberFactory->create()->load(
$subscriberId
);
$subscriber->delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@
*/
namespace Magento\Newsletter\Controller\Adminhtml\Subscriber;

class MassUnsubscribe extends \Magento\Newsletter\Controller\Adminhtml\Subscriber
use Magento\Newsletter\Controller\Adminhtml\Subscriber;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Framework\App\ObjectManager;

class MassUnsubscribe extends Subscriber
{
/**
* @var SubscriberFactory
*/
private $subscriberFactory;

/**
* @param Context $context
* @param FileFactory $fileFactory
*/
public function __construct(
Context $context,
FileFactory $fileFactory,
SubscriberFactory $subscriberFactory = null
) {
$this->subscriberFactory = $subscriberFactory ?: ObjectManager::getInstance()->get(SubscriberFactory::class);
parent::__construct($context, $fileFactory);
}

/**
* Unsubscribe one or more subscribers action
*
Expand All @@ -21,9 +45,7 @@ public function execute()
} else {
try {
foreach ($subscribersIds as $subscriberId) {
$subscriber = $this->_objectManager->create(
\Magento\Newsletter\Model\Subscriber::class
)->load(
$subscriber = $this->subscriberFactory->create()->load(
$subscriberId
);
$subscriber->unsubscribe();
Expand Down