Skip to content

Commit

Permalink
Merge pull request #401 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
HuyPhuc98 authored Jun 22, 2023
2 parents dcb31aa + 9daa925 commit 1ea31a5
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 494 deletions.
21 changes: 11 additions & 10 deletions Mail/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ public function aroundSendMessage(
$message->getHeaders()->removeHeader("Content-Disposition");
}
$transport->send($message);
}
if ($this->helper->versionCompare('2.2.8')) {
$messageTmp = $this->getMessage($subject);
if ($messageTmp && is_object($messageTmp)) {
$body = $messageTmp->getBody();
if (is_object($body) && $body->isMultiPart()) {
$message->setBody($body->getPartContent("0"));

if ($this->helper->versionCompare('2.2.8')) {
$messageTmp = $this->getMessage($subject);
if ($messageTmp && is_object($messageTmp)) {
$body = $messageTmp->getBody();
if (is_object($body) && $body->isMultiPart()) {
$message->setBody($body->getPartContent("0"));
}
}
}
}

$this->emailLog($message);
$this->emailLog($message);
}
} catch (Exception $e) {
$this->emailLog($message, false);
throw new MailException(new Phrase($e->getMessage()), $e);
Expand Down Expand Up @@ -226,7 +227,7 @@ public function validateBlacklist($message)
*/
protected function emailLog($message, $status = true)
{
if ($this->resourceMail->isEnableEmailLog($this->_storeId)) {
if ($this->helper->isEnabled($this->_storeId) && $this->resourceMail->isEnableEmailLog($this->_storeId)) {
/** @var Log $log */
$log = $this->logFactory->create();
try {
Expand Down
2 changes: 1 addition & 1 deletion Model/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function resendEmail()
}
}

$this->mailResource->setSmtpOptions(Store::DEFAULT_STORE_ID, ['ignore_log' => true]);
$this->mailResource->setSmtpOptions(Store::DEFAULT_STORE_ID, ['force_sent' => true]);

try {
$this->_transportBuilder
Expand Down
67 changes: 0 additions & 67 deletions Setup/InstallSchema.php

This file was deleted.

177 changes: 177 additions & 0 deletions Setup/Patch/Data/UpgradeAttributeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Smtp
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Setup\Patch\Data;

use Magento\Config\Model\ResourceModel\Config\Data\Collection;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Validator\ValidateException;

/**
* Class UpgradeAttributeData
* @package Mageplaza\Smtp\Setup\Patch\Data
*/
class UpgradeAttributeData implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
* @var AttributeSetFactory
*/
protected $attributeSetFactory;

/**
* @var CustomerSetupFactory
*/
protected $customerSetupFactory;

/**
* @var Collection
*/
protected $configCollection;

/**
* @var TypeListInterface
*/
protected $_cacheTypeList;

/**
* UpgradeData constructor.
*
* @param AttributeSetFactory $attributeSetFactory
* @param CustomerSetupFactory $customerSetupFactory
* @param Collection $configCollection
* @param TypeListInterface $cacheTypeList
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
AttributeSetFactory $attributeSetFactory,
CustomerSetupFactory $customerSetupFactory,
Collection $configCollection,
TypeListInterface $cacheTypeList
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->attributeSetFactory = $attributeSetFactory;
$this->customerSetupFactory = $customerSetupFactory;
$this->configCollection = $configCollection;
$this->_cacheTypeList = $cacheTypeList;
}

/**
* {@inheritdoc}
*
* @throws LocalizedException
* @throws ValidateException
*/
public function apply()
{
$setup = $this->moduleDataSetup;

$setup->startSetup();

/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();

/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

$customerSetup->addAttribute(Customer::ENTITY, 'mp_smtp_is_synced', [
'type' => 'int',
'label' => 'Mp SMTP is synced',
'input' => 'hidden',
'required' => false,
'visible' => false,
'user_defined' => false,
'sort_order' => 90,
'position' => 90,
'system' => 0,
'is_used_in_grid' => false,
]);

$customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mp_smtp_is_synced')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer']
])
->save();

$connection = $setup->getConnection();
$configCollection = $this->configCollection->addPathFilter('smtp/abandoned_cart');
if ($configCollection->getSize() > 0) {
$table = $this->configCollection->getMainTable();
$paths = [
'smtp/abandoned_cart/enabled' => 'email_marketing/general/enabled',
'smtp/abandoned_cart/app_id' => 'email_marketing/general/app_id',
'smtp/abandoned_cart/secret_key' => 'email_marketing/general/secret_key'
];

foreach ($paths as $oldPath => $newPath) {
$connection->update(
$table,
['path' => $newPath],
['path = ?' => $oldPath]
);
}
$this->_cacheTypeList->cleanType('config');
}
}

/**
* @return array
*/
public static function getDependencies()
{
return [];
}

/**
* @return array
*/
public function getAliases()
{
return [];
}

/**
* @return array
*/
public function revert()
{
return [];
}
}
Loading

0 comments on commit 1ea31a5

Please sign in to comment.