Skip to content

Commit

Permalink
ENGCOM-2488: [Forwardport] Remove direct use of object manager #17042
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Jul 24, 2018
2 parents a3650d1 + 56bca45 commit cf77bf5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
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,33 @@
*/
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
* @param SubscriberFactory $subscriberFactory
*/
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 +46,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

0 comments on commit cf77bf5

Please sign in to comment.