Reactivate all inactive subscribers when inactive interval is set to never
[MAILPOET-2003]
This commit is contained in:
committed by
M. Shull
parent
e5f5b3534c
commit
f5d154d680
@ -30,12 +30,19 @@ class InactiveSubscribers extends SimpleWorker {
|
||||
|
||||
|
||||
function processTaskStrategy(ScheduledTask $task) {
|
||||
$days_to_inactive = (int)$this->settings->get('deactivate_subscriber_after_inactive_days');
|
||||
$tracking_enabled = (bool)$this->settings->get('tracking.enabled');
|
||||
if ($days_to_inactive === 0 || !$tracking_enabled) {
|
||||
if (!$tracking_enabled) {
|
||||
self::schedule();
|
||||
return true;
|
||||
}
|
||||
$days_to_inactive = (int)$this->settings->get('deactivate_subscriber_after_inactive_days');
|
||||
// Activate all inactive subscribers in case the feature is turned off
|
||||
if ($days_to_inactive === 0) {
|
||||
$this->inactive_subscribers_controller->reactivateInactiveSubscribers();
|
||||
self::schedule();
|
||||
return true;
|
||||
}
|
||||
// Handle activation/deactivation within interval
|
||||
while ($this->inactive_subscribers_controller->markInactiveSubscribers($days_to_inactive, self::BATCH_SIZE) === self::BATCH_SIZE) {
|
||||
CronHelper::enforceExecutionLimit($this->timer);
|
||||
};
|
||||
|
@ -33,6 +33,17 @@ class InactiveSubscribersController {
|
||||
return $this->activateSubscribers($threshold_date, $batch_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
function reactivateInactiveSubscribers() {
|
||||
$reactivate_all_inactive_query = sprintf(
|
||||
"UPDATE %s SET status = '%s' WHERE status = '%s';",
|
||||
Subscriber::$_table, Subscriber::STATUS_SUBSCRIBED, Subscriber::STATUS_INACTIVE
|
||||
);
|
||||
\ORM::rawExecute($reactivate_all_inactive_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $days_to_inactive
|
||||
* @return Carbon
|
||||
|
@ -21,11 +21,12 @@ class InactiveSubscribersTest extends \MailPoetTest {
|
||||
parent::_before();
|
||||
}
|
||||
|
||||
function testItSchedulesNextRunWhenThereIsNothingToDo() {
|
||||
function testItReactivateInactiveSubscribersWhenIntervalIsSetToNever() {
|
||||
$this->settings->set('deactivate_subscriber_after_inactive_days', 0);
|
||||
$controller_mock = Stub::make(InactiveSubscribersController::class, [
|
||||
'markInactiveSubscribers' => Stub\Expected::never(),
|
||||
'markActiveSubscribers' => Stub\Expected::never(),
|
||||
'reactivateInactiveSubscribers' => Stub\Expected::once(),
|
||||
], $this);
|
||||
|
||||
$worker = new InactiveSubscribers($controller_mock, $this->settings);
|
||||
@ -45,6 +46,7 @@ class InactiveSubscribersTest extends \MailPoetTest {
|
||||
$controller_mock = Stub::make(InactiveSubscribersController::class, [
|
||||
'markInactiveSubscribers' => Stub\Expected::never(),
|
||||
'markActiveSubscribers' => Stub\Expected::never(),
|
||||
'reactivateInactiveSubscribers' => Stub\Expected::never(),
|
||||
], $this);
|
||||
|
||||
$worker = new InactiveSubscribers($controller_mock, $this->settings);
|
||||
@ -56,6 +58,7 @@ class InactiveSubscribersTest extends \MailPoetTest {
|
||||
$controller_mock = Stub::make(InactiveSubscribersController::class, [
|
||||
'markInactiveSubscribers' => Stub\Expected::once(1),
|
||||
'markActiveSubscribers' => Stub\Expected::once(1),
|
||||
'reactivateInactiveSubscribers' => Stub\Expected::never(),
|
||||
], $this);
|
||||
|
||||
$worker = new InactiveSubscribers($controller_mock, $this->settings);
|
||||
@ -74,6 +77,7 @@ class InactiveSubscribersTest extends \MailPoetTest {
|
||||
$controller_mock = Stub::make(InactiveSubscribersController::class, [
|
||||
'markInactiveSubscribers' => Stub::consecutive(InactiveSubscribers::BATCH_SIZE, InactiveSubscribers::BATCH_SIZE, 1, 'ok'),
|
||||
'markActiveSubscribers' => Stub::consecutive(InactiveSubscribers::BATCH_SIZE, 1, 'ok'),
|
||||
'reactivateInactiveSubscribers' => Stub\Expected::never(),
|
||||
], $this);
|
||||
|
||||
$worker = new InactiveSubscribers($controller_mock, $this->settings);
|
||||
@ -88,6 +92,7 @@ class InactiveSubscribersTest extends \MailPoetTest {
|
||||
$controller_mock = Stub::make(InactiveSubscribersController::class, [
|
||||
'markInactiveSubscribers' => Stub\Expected::once(InactiveSubscribers::BATCH_SIZE),
|
||||
'markActiveSubscribers' => Stub\Expected::never(),
|
||||
'reactivateInactiveSubscribers' => Stub\Expected::never(),
|
||||
], $this);
|
||||
|
||||
$worker = new InactiveSubscribers($controller_mock, $this->settings, microtime(true) - (CronHelper::DAEMON_EXECUTION_LIMIT - 1));
|
||||
|
@ -188,6 +188,15 @@ class InactiveSubscribersControllerTest extends \MailPoetTest {
|
||||
expect($subscriber->status)->equals(Subscriber::STATUS_INACTIVE);
|
||||
}
|
||||
|
||||
function testItDoesReactivateInactiveSubscribers() {
|
||||
list($task) = $this->createCompletedSendingTask(2);
|
||||
$subscriber = $this->createSubscriber('s1@email.com', 10, Subscriber::STATUS_INACTIVE);
|
||||
$this->addSubcriberToTask($subscriber, $task);
|
||||
$this->controller->reactivateInactiveSubscribers();
|
||||
$subscriber = Subscriber::findOne($subscriber->id);
|
||||
expect($subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @param int $created_days_ago
|
||||
|
Reference in New Issue
Block a user