Move constans to their classes

[MAILPOET-2348]
This commit is contained in:
Pavel Dohnal
2019-09-09 12:57:47 +02:00
committed by Jack Kitterhing
parent 3d750c5bb8
commit 493e16606c
9 changed files with 45 additions and 50 deletions

View File

@ -14,6 +14,15 @@ use MailPoet\WP\Posts;
class PostNotificationScheduler {
const SECONDS_IN_HOUR = 3600;
const LAST_WEEKDAY_FORMAT = 'L';
const INTERVAL_DAILY = 'daily';
const INTERVAL_IMMEDIATELY = 'immediately';
const INTERVAL_NTHWEEKDAY = 'nthWeekDay';
const INTERVAL_WEEKLY = 'weekly';
const INTERVAL_IMMEDIATE = 'immediate';
const INTERVAL_MONTHLY = 'monthly';
function transitionHook($new_status, $old_status, $post) {
Logger::getLogger('post-notifications')->addInfo(
'transition post notification hook initiated',
@ -88,27 +97,27 @@ class PostNotificationScheduler {
function processPostNotificationSchedule($newsletter) {
$interval_type = $newsletter->intervalType;
$hour = (int)$newsletter->timeOfDay / Scheduler::SECONDS_IN_HOUR;
$hour = (int)$newsletter->timeOfDay / self::SECONDS_IN_HOUR;
$week_day = $newsletter->weekDay;
$month_day = $newsletter->monthDay;
$nth_week_day = ($newsletter->nthWeekDay === Scheduler::LAST_WEEKDAY_FORMAT) ?
$nth_week_day = ($newsletter->nthWeekDay === self::LAST_WEEKDAY_FORMAT) ?
$newsletter->nthWeekDay :
'#' . $newsletter->nthWeekDay;
switch ($interval_type) {
case Scheduler::INTERVAL_IMMEDIATE:
case Scheduler::INTERVAL_DAILY:
case self::INTERVAL_IMMEDIATE:
case self::INTERVAL_DAILY:
$schedule = sprintf('0 %s * * *', $hour);
break;
case Scheduler::INTERVAL_WEEKLY:
case self::INTERVAL_WEEKLY:
$schedule = sprintf('0 %s * * %s', $hour, $week_day);
break;
case Scheduler::INTERVAL_NTHWEEKDAY:
case self::INTERVAL_NTHWEEKDAY:
$schedule = sprintf('0 %s ? * %s%s', $hour, $week_day, $nth_week_day);
break;
case Scheduler::INTERVAL_MONTHLY:
case self::INTERVAL_MONTHLY:
$schedule = sprintf('0 %s %s * *', $hour, $month_day);
break;
case Scheduler::INTERVAL_IMMEDIATELY:
case self::INTERVAL_IMMEDIATELY:
default:
$schedule = '* * * * *';
break;

View File

@ -11,15 +11,6 @@ use MailPoet\Tasks\Sending as SendingTask;
use MailPoet\WP\Functions as WPFunctions;
class Scheduler {
const SECONDS_IN_HOUR = 3600;
const LAST_WEEKDAY_FORMAT = 'L';
const WORDPRESS_ALL_ROLES = 'mailpoet_all';
const INTERVAL_IMMEDIATELY = 'immediately';
const INTERVAL_IMMEDIATE = 'immediate';
const INTERVAL_DAILY = 'daily';
const INTERVAL_WEEKLY = 'weekly';
const INTERVAL_MONTHLY = 'monthly';
const INTERVAL_NTHWEEKDAY = 'nthWeekDay';
static function scheduleAutomaticEmail($group, $event, $scheduling_condition = false, $subscriber_id = false, $meta = false) {
$newsletters = self::getNewsletters(Newsletter::TYPE_AUTOMATIC, $group);

View File

@ -8,6 +8,8 @@ use MailPoet\Tasks\Sending as SendingTask;
class WelcomeScheduler {
const WORDPRESS_ALL_ROLES = 'mailpoet_all';
function scheduleSubscriberWelcomeNotification($subscriber_id, $segments) {
$newsletters = Scheduler::getNewsletters(Newsletter::TYPE_WELCOME);
if (empty($newsletters)) return false;
@ -35,13 +37,13 @@ class WelcomeScheduler {
// do not schedule welcome newsletter if roles have not changed
$old_role = $old_user_data['roles'];
$new_role = $wp_user['roles'];
if ($newsletter->role === Scheduler::WORDPRESS_ALL_ROLES ||
if ($newsletter->role === self::WORDPRESS_ALL_ROLES ||
!array_diff($old_role, $new_role)
) {
continue;
}
}
if ($newsletter->role === Scheduler::WORDPRESS_ALL_ROLES ||
if ($newsletter->role === self::WORDPRESS_ALL_ROLES ||
in_array($newsletter->role, $wp_user['roles'])
) {
$this->createWelcomeNotificationSendingTask($newsletter, $subscriber_id);