- Updates Mailer class to use default values from Settings

This commit is contained in:
Vlad
2016-07-21 10:29:16 -04:00
parent 9b9cb1455a
commit 067b3ff3e6
2 changed files with 32 additions and 26 deletions

View File

@ -19,28 +19,29 @@ class TaskScheduler {
} }
function init() { function init() {
// configure task scheduler only outside of cli environment try {
if(php_sapi_name() === 'cli') return; // configure task scheduler only outside of cli environment
switch($this->method) { if(php_sapi_name() === 'cli') return;
case self::METHOD_MAILPOET: switch($this->method) {
return $this->configureMailpoetScheduler(); case self::METHOD_MAILPOET:
break; return $this->configureMailpoetScheduler();
case self::METHOD_WORDPRESS: break;
return $this->configureWordpressScheduler(); case self::METHOD_WORDPRESS:
break; return $this->configureWordpressScheduler();
default: break;
throw new \Exception(__("Task scheduler is not configured")); default:
break; throw new \Exception(__("Task scheduler is not configured"));
}; break;
};
} catch(\Exception $e) {
// ignore exceptions as they should not prevent the rest of the site from loading
}
} }
function configureMailpoetScheduler() { function configureMailpoetScheduler() {
try { $supervisor = new Supervisor();
$supervisor = new Supervisor(); $supervisor->checkDaemon();
$supervisor->checkDaemon(); return;
} catch(\Exception $e) {
// exceptions should not prevent the rest of the site loading
}
} }
function configureWordpressScheduler() { function configureWordpressScheduler() {

View File

@ -44,14 +44,14 @@ class Mailer {
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_ELASTICEMAIL: case self::METHOD_ELASTICEMAIL:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->mailer['api_key'], $this->mailer['api_key'],
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_MAILGUN: case self::METHOD_MAILGUN:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->mailer['domain'], $this->mailer['domain'],
@ -59,27 +59,27 @@ class Mailer {
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_MAILPOET: case self::METHOD_MAILPOET:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->mailer['mailpoet_api_key'], $this->mailer['mailpoet_api_key'],
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_SENDGRID: case self::METHOD_SENDGRID:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->mailer['api_key'], $this->mailer['api_key'],
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_PHPMAIL: case self::METHOD_PHPMAIL:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
case self::METHOD_SMTP: case self::METHOD_SMTP:
$mailer_instance = new $this->mailer['class']( $mailer_instance = new $this->mailer['class'](
$this->mailer['host'], $this->mailer['host'],
@ -91,7 +91,7 @@ class Mailer {
$this->sender, $this->sender,
$this->reply_to $this->reply_to
); );
break; break;
default: default:
throw new \Exception(__('Mailing method does not exist')); throw new \Exception(__('Mailing method does not exist'));
} }
@ -103,6 +103,11 @@ class Mailer {
$mailer = Setting::getValue(self::MAILER_CONFIG); $mailer = Setting::getValue(self::MAILER_CONFIG);
if(!$mailer || !isset($mailer['method'])) throw new \Exception(__('Mailer is not configured')); if(!$mailer || !isset($mailer['method'])) throw new \Exception(__('Mailer is not configured'));
} }
if(empty($mailer['frequency'])) {
$default_settings = Setting::getDefaults();
$mailer['frequency'] = $default_settings['mta']['frequency'];
}
// add additional variables to the mailer object
$mailer['class'] = 'MailPoet\\Mailer\\Methods\\' . $mailer['method']; $mailer['class'] = 'MailPoet\\Mailer\\Methods\\' . $mailer['method'];
$mailer['frequency_interval'] = $mailer['frequency_interval'] =
(int)$mailer['frequency']['interval'] * self::SENDING_LIMIT_INTERVAL_MULTIPLIER; (int)$mailer['frequency']['interval'] * self::SENDING_LIMIT_INTERVAL_MULTIPLIER;