Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed Jun 6, 2018
1 parent e801ddd commit 61221ca
Show file tree
Hide file tree
Showing 19 changed files with 320 additions and 441 deletions.
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Smtp/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @category Mageplaza
* @package Mageplaza_RewardPoints
* @copyright Copyright (c) 2018 Mageplaza (http://www.mageplaza.com/)
* @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

Expand Down
34 changes: 15 additions & 19 deletions Controller/Adminhtml/Smtp/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
*
* @category Mageplaza
* @package Mageplaza_Smtp
* @copyright Copyright (c) 2017-2018 Mageplaza (https://www.mageplaza.com/)
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Controller\Adminhtml\Smtp;

use Magento\Backend\App\Action;
use Mageplaza\Smtp\Model\LogFactory;
use Magento\Backend\App\Action\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Translate\Inline\StateInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Smtp\Model\LogFactory;

/**
* Class Email
Expand Down Expand Up @@ -80,9 +80,9 @@ public function __construct(
{
parent::__construct($context);

$this->logFactory = $logFactory;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->logFactory = $logFactory;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->_transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
}
Expand All @@ -93,24 +93,20 @@ public function __construct(
public function execute()
{
$logId = $this->getRequest()->getParam('id');

if (!$logId) {
$this->_redirect('*/smtp/log');
$this->_redirect('*/*/log');

return;
}

$email = $this->logFactory->create();
$data = $email->load($logId)->getData();
$data['email_content'] = htmlspecialchars_decode($data['email_content']);

$status = $email->resendEmail($data);

if ($status) {
$this->messageManager->addSuccess(
__('Email re-sent successfully!')
);
$email = $this->logFactory->create()->load($logId);
if ($email->resendEmail()) {
$this->messageManager->addSuccessMessage(__('Email re-sent successfully!'));
} else {
$this->messageManager->addErrorMessage(__('We can\'t process your request right now.'));
}
$this->_redirect('*/smtp/log');

return;
}
}
1 change: 0 additions & 1 deletion Controller/Adminhtml/Smtp/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function __construct(
*/
public function execute()
{

$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Mageplaza_Smtp::log');
$resultPage->getConfig()->getTitle()->prepend((__('Emails Log')));
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Smtp/MassDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @category Mageplaza
* @package Mageplaza_RewardPoints
* @copyright Copyright (c) 2018 Mageplaza (http://www.mageplaza.com/)
* @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

Expand Down
44 changes: 21 additions & 23 deletions Controller/Adminhtml/Smtp/MassResend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*
* @category Mageplaza
* @package Mageplaza_RewardPoints
* @copyright Copyright (c) 2018 Mageplaza (http://www.mageplaza.com/)
* @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Controller\Adminhtml\Smtp;

use Magento\Backend\App\Action;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
use Mageplaza\Smtp\Model\ResourceModel\Log\CollectionFactory;

/**
Expand Down Expand Up @@ -61,40 +61,38 @@ public function __construct(
{
parent::__construct($context);

$this->filter = $filter;
$this->filter = $filter;
$this->emailLog = $emailLog;
}

/**
* @return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
* @return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

try {
$collection = $this->filter->getCollection($this->emailLog->create());

$resend = 0;
foreach ($collection->getItems() as $item) {
$data = $item->getData();
$data['email_content'] = htmlspecialchars_decode($data['email_content']);
$item->resendEmail($data);
$collection = $this->filter->getCollection($this->emailLog->create());
$resend = 0;

/** @var \Mageplaza\Smtp\Model\Log $item */
foreach ($collection->getItems() as $item) {
if (!$item->resendEmail()) {
$this->messageManager->addErrorMessage(
__('We can\'t process your request for email log #%1', $item->getId())
);
} else {
$resend++;
}
} catch (\Exception $e) {
$this->messageManager->addError(
__('We can\'t process your request right now. %1', $e->getMessage())
}

if ($resend) {
$this->messageManager->addSuccessMessage(
__('A total of %1 record(s) have been sent.', $resend)
);
$this->_redirect('adminhtml/smtp/log');
return;
}

$this->messageManager->addSuccessMessage(
__('A total of %1 record(s) have been sent.', $resend)
);
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

return $resultRedirect->setPath('adminhtml/smtp/log');
}
Expand Down
2 changes: 1 addition & 1 deletion Cron/ClearLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function execute()
return $this;
}

$day = (int)$this->helper->getDeveloperConfig('clean_email');
$day = (int)$this->helper->getConfigGeneral('clean_email');
if (isset($day) && $day > 0) {
$timeEnd = strtotime($this->date->date()) - $day * 24 * 60 * 60;

Expand Down
12 changes: 0 additions & 12 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Data extends AbstractData
const CONFIG_MODULE_PATH = 'smtp';
const CONFIG_GROUP_SMTP = 'configuration_option';
const DEVELOP_GROUP_SMTP = 'developer';
const GENERAL_GROUP_SMTP = 'general';

/**
* @param string $code
Expand All @@ -59,17 +58,6 @@ public function getDeveloperConfig($code = '', $storeId = null)
return $this->getModuleConfig(self::DEVELOP_GROUP_SMTP . $code, $storeId);
}

/**
* @param string $code
* @param null $storeId
* @return mixed
*/
public function getGeneralConfig($code = '', $storeId = null){
$code = ($code !== '') ? '/' . $code : '';

return $this->getModuleConfig(self::GENERAL_GROUP_SMTP . $code, $storeId);
}

/**
* @param bool $decrypt
* @return array|mixed
Expand Down
2 changes: 1 addition & 1 deletion Mail/Rse/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function isDeveloperMode($storeId)
public function isEnableEmailLog($storeId)
{
if (!isset($this->_emailLog[$storeId])) {
$this->_emailLog[$storeId] = $this->smtpHelper->getGeneralConfig('log_email', $storeId);
$this->_emailLog[$storeId] = $this->smtpHelper->getConfigGeneral('log_email', $storeId);
}

return $this->_emailLog[$storeId];
Expand Down
14 changes: 4 additions & 10 deletions Mail/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,17 @@ public function aroundSendMessage(
)
{
$this->_storeId = $this->registry->registry('mp_smtp_store_id');
$isResend = $this->registry->registry('mp_smtp_is_resend');
$message = $this->getMessage($subject);
if (($isResend || $this->resourceMail->isModuleEnable($this->_storeId)) && $message) {
$this->registry->unregister('mp_smtp_is_resend');
if ($this->resourceMail->isModuleEnable($this->_storeId) && $message) {
$message = $this->resourceMail->processMessage($message, $this->_storeId);
$transport = $this->resourceMail->getTransport($this->_storeId);
try {
if (!$this->resourceMail->isDeveloperMode($this->_storeId) || !$this->resourceMail->isModuleEnable($this->_storeId)) {
if (!$this->resourceMail->isDeveloperMode($this->_storeId)) {
$transport->send($message);
}
if($this->resourceMail->isModuleEnable($this->_storeId)) {
$this->emailLog($message);
}
$this->emailLog($message);
} catch (\Exception $e) {
if($this->resourceMail->isModuleEnable($this->_storeId)) {
$this->emailLog($message, false);
}
$this->emailLog($message, false);
throw new MailException(new Phrase($e->getMessage()), $e);
}
} else {
Expand Down
Loading

0 comments on commit 61221ca

Please sign in to comment.