refactor smtp preferences

This commit is contained in:
Yuri Kuznetsov
2014-03-26 15:57:12 +02:00
parent 57add24ba3
commit 6f76f7289d
2 changed files with 19 additions and 15 deletions
+14 -2
View File
@@ -25,9 +25,21 @@ namespace Espo\Entities;
class Preferences extends \Espo\Core\ORM\Entity
{
public function getSmtpSettings()
public function getSmtpParams()
{
// TODO
$smtpParams = array();
$smtpParams['server'] = $this->get('smtpServer');
if ($smtpParams['server']) {
$smtpParams['port'] = $this->get('smtpPort');
$smtpParams['server'] = $this->get('smtpServer');
$smtpParams['auth'] = $this->get('smtpAuth');
$smtpParams['security'] = $this->get('smtpSecurity');
$smtpParams['username'] = $this->get('smtpUsername');
$smtpParams['password'] = $this->get('smtpPassword');
return $smtpParams;
} else {
return false;
}
}
}
+5 -13
View File
@@ -43,7 +43,7 @@ class Email extends Record
protected function getPreferences()
{
return $this->injections['preferences'];
}
}
public function createEntity($data)
{
@@ -52,18 +52,10 @@ class Email extends Record
if ($entity && $entity->get('status') == 'Sending') {
$emailSender = $this->getMailSender();
if (strtolower($this->getUser()->get('emailAddress')) == strtolower($entity->get('from'))) {
$smtpParams = array();
$smtpParams['server'] = $this->getPreferences()->get('smtpServer');
if (!empty($smtpParams['server'])) {
$smtpParams['fromName'] = $this->getUser()->get('name');
$smtpParams['port'] = $this->getPreferences()->get('smtpPort');
$smtpParams['server'] = $this->getPreferences()->get('smtpServer');
$smtpParams['auth'] = $this->getPreferences()->get('smtpAuth');
$smtpParams['security'] = $this->getPreferences()->get('smtpSecurity');
$smtpParams['username'] = $this->getPreferences()->get('smtpUsername');
$smtpParams['password'] = $this->getPreferences()->get('smtpPassword');
if (strtolower($this->getUser()->get('emailAddress')) == strtolower($entity->get('from'))) {
$smtpParams = $this->getPreferences()->getSmtpParams();
if ($smtpParams) {
$smtpParams['fromName'] = $this->getUser()->get('name');
$emailSender->useSmtp($smtpParams);
}
} else {