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

Fix Configuration Typo, Change Password to Encrypted Field #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
2 changes: 0 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Fruitcake\EmailAdvancedConfig\Helper;


use Fruitcake\EmailAdvancedConfig\Model\Config\Source\SmtpTransportType;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\ScopeInterface;


class Data extends AbstractHelper
{
const CONFIG_PATH = 'fruitcake_email_advanced/';
Expand Down
75 changes: 75 additions & 0 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Fruitcake\EmailAdvancedConfig\Setup;

use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Cache\Manager;

class UpgradeData implements UpgradeDataInterface
{
/**
* @var AdapterInterface
*/
protected $connection;

/**
* @var EncryptorInterface
*/
protected $encryptor;

/**
* @var WriterInterface
*/
protected $configWriter;

/**
* @var Manager
*/
protected $cacheManager;

/**
* @param ResourceConnection $resourceConnection
* @param EncryptorInterface $encryptor
* @param WriterInterface $configWriter
* @param Manager $cacheManager
*/
public function __construct(
ResourceConnection $resourceConnection,
EncryptorInterface $encryptor,
WriterInterface $configWriter,
Manager $cacheManager
) {
$this->connection = $resourceConnection->getConnection();
$this->encryptor = $encryptor;
$this->configWriter = $configWriter;
$this->cacheManager = $cacheManager;
}

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
if (version_compare($context->getVersion(), '1.0.1', '<')) {
$passwordPath = 'fruitcake_email_advanced/smtp/password';

$passwordQuery = $this->connection
->select()
->from('core_config_data', 'value')
->where('path = ?', $passwordPath);

if ($password = $this->connection->fetchOne($passwordQuery)) {
$this->configWriter->save(
$passwordPath,
$this->encryptor->encrypt($password)
);

$this->cacheManager->flush(['config']);
$this->cacheManager->clean(['config']);
}
}
}
}
10 changes: 7 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<class>separator-top</class>
<label>Email Advanced</label>
<tab>fruitcake</tab>
<resource>Fruitcake_EmailAdvancedConfig::smpt</resource>
<resource>Fruitcake_EmailAdvancedConfig::smtp</resource>
<group id="smtp" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>SMTP Configuration</label>
<field id="transport" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -45,20 +45,24 @@
<field id="transport">smtp</field>
</depends>
</field>
<field id="password" translate="label comment" type="text" sortOrder="102" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">

<field id="password" translate="label comment" type="obscure" sortOrder="102" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Password</label>
<comment>Username</comment>
<comment>Password</comment>
<source_model>Magento\Config\Model\Config\Backend\Encrypted</source_model>
<depends>
<field id="transport">smtp</field>
</depends>
</field>

<field id="auth" translate="label" type="select" sortOrder="103" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Auth</label>
<source_model>Fruitcake\EmailAdvancedConfig\Model\Config\Source\SmtpAuthType</source_model>
<depends>
<field id="transport">smtp</field>
</depends>
</field>

<field id="ssl" translate="label" type="select" sortOrder="104" showInDefault="1" showInWebsite="1" showInStore="1">
<label>SSL</label>
<source_model>Fruitcake\EmailAdvancedConfig\Model\Config\Source\SmtpSslType</source_model>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<smtp>
<host>localhost</host>
<port>25</port>
<password backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
<transport>sendmail</transport>
<auth>plain</auth>
<ssl>none</ssl>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fruitcake_EmailAdvancedConfig" setup_version="1.0.0">
<module name="Fruitcake_EmailAdvancedConfig" setup_version="1.0.1">
<sequence>
<module name="Magento_Email"/>
</sequence>
Expand Down