Rename removeSubscribers() method and encapsulate task completion logic [MAILPOET-987]

This commit is contained in:
stoletniy
2017-07-20 11:22:47 +03:00
parent c924778d50
commit b42d8e68d9
4 changed files with 6 additions and 6 deletions

View File

@ -64,11 +64,11 @@ class SendingQueue {
}
// if some subscribers weren't found, remove them from the processing list
if(count($found_subscribers_ids) !== count($subscribers_to_process_ids)) {
$subscibers_to_remove = array_diff(
$subscribers_to_remove = array_diff(
$subscribers_to_process_ids,
$found_subscribers_ids
);
$queue->removeNonexistentSubscribers($subscibers_to_remove);
$queue->removeSubscribers($subscribers_to_remove);
if(!count($queue->subscribers['to_process'])) {
$this->newsletter_task->markNewsletterAsSent($newsletter, $queue);
continue;

View File

@ -12,6 +12,7 @@ class ScheduledTask extends Model {
const PRIORITY_LOW = 10;
function complete() {
$this->processed_at = current_time('mysql');
$this->set('status', self::STATUS_COMPLETED);
$this->save();
return ($this->getErrors() === false && $this->id() > 0);

View File

@ -92,7 +92,7 @@ class SendingQueue extends Model {
return $model;
}
function removeNonexistentSubscribers($subscribers_to_remove) {
function removeSubscribers($subscribers_to_remove) {
$subscribers = $this->getSubscribers();
$subscribers['to_process'] = array_values(
array_diff(

View File

@ -24,7 +24,7 @@ class Subscribers {
return !empty($subscriber);
}
function removeNonexistentSubscribers($subscribers_to_remove) {
function removeSubscribers($subscribers_to_remove) {
$this->getSubscribers()
->whereIn('subscriber_id', $subscribers_to_remove)
->deleteMany();
@ -42,8 +42,7 @@ class Subscribers {
private function checkCompleted() {
if(!ScheduledTaskSubscriber::getUnprocessedCount($this->task->id)) {
$this->task->processed_at = current_time('mysql');
return $this->task->complete();
$this->task->complete();
}
}
}