Rename removeSubscribers() method and encapsulate task completion logic [MAILPOET-987]
This commit is contained in:
@ -64,11 +64,11 @@ class SendingQueue {
|
|||||||
}
|
}
|
||||||
// if some subscribers weren't found, remove them from the processing list
|
// if some subscribers weren't found, remove them from the processing list
|
||||||
if(count($found_subscribers_ids) !== count($subscribers_to_process_ids)) {
|
if(count($found_subscribers_ids) !== count($subscribers_to_process_ids)) {
|
||||||
$subscibers_to_remove = array_diff(
|
$subscribers_to_remove = array_diff(
|
||||||
$subscribers_to_process_ids,
|
$subscribers_to_process_ids,
|
||||||
$found_subscribers_ids
|
$found_subscribers_ids
|
||||||
);
|
);
|
||||||
$queue->removeNonexistentSubscribers($subscibers_to_remove);
|
$queue->removeSubscribers($subscribers_to_remove);
|
||||||
if(!count($queue->subscribers['to_process'])) {
|
if(!count($queue->subscribers['to_process'])) {
|
||||||
$this->newsletter_task->markNewsletterAsSent($newsletter, $queue);
|
$this->newsletter_task->markNewsletterAsSent($newsletter, $queue);
|
||||||
continue;
|
continue;
|
||||||
|
@ -12,6 +12,7 @@ class ScheduledTask extends Model {
|
|||||||
const PRIORITY_LOW = 10;
|
const PRIORITY_LOW = 10;
|
||||||
|
|
||||||
function complete() {
|
function complete() {
|
||||||
|
$this->processed_at = current_time('mysql');
|
||||||
$this->set('status', self::STATUS_COMPLETED);
|
$this->set('status', self::STATUS_COMPLETED);
|
||||||
$this->save();
|
$this->save();
|
||||||
return ($this->getErrors() === false && $this->id() > 0);
|
return ($this->getErrors() === false && $this->id() > 0);
|
||||||
|
@ -92,7 +92,7 @@ class SendingQueue extends Model {
|
|||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeNonexistentSubscribers($subscribers_to_remove) {
|
function removeSubscribers($subscribers_to_remove) {
|
||||||
$subscribers = $this->getSubscribers();
|
$subscribers = $this->getSubscribers();
|
||||||
$subscribers['to_process'] = array_values(
|
$subscribers['to_process'] = array_values(
|
||||||
array_diff(
|
array_diff(
|
||||||
|
@ -24,7 +24,7 @@ class Subscribers {
|
|||||||
return !empty($subscriber);
|
return !empty($subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeNonexistentSubscribers($subscribers_to_remove) {
|
function removeSubscribers($subscribers_to_remove) {
|
||||||
$this->getSubscribers()
|
$this->getSubscribers()
|
||||||
->whereIn('subscriber_id', $subscribers_to_remove)
|
->whereIn('subscriber_id', $subscribers_to_remove)
|
||||||
->deleteMany();
|
->deleteMany();
|
||||||
@ -42,8 +42,7 @@ class Subscribers {
|
|||||||
|
|
||||||
private function checkCompleted() {
|
private function checkCompleted() {
|
||||||
if(!ScheduledTaskSubscriber::getUnprocessedCount($this->task->id)) {
|
if(!ScheduledTaskSubscriber::getUnprocessedCount($this->task->id)) {
|
||||||
$this->task->processed_at = current_time('mysql');
|
$this->task->complete();
|
||||||
return $this->task->complete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user