Sending queue refactoring WIP [MAILPOET-903]
This commit is contained in:
@ -10,6 +10,10 @@ class ScheduledTaskSubscriber extends Model {
|
||||
public static $_table = MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE;
|
||||
public static $_id_column = array('task_id', 'subscriber_id');
|
||||
|
||||
function task() {
|
||||
return $this->hasOne(__NAMESPACE__ . '\ScheduledTask', 'id', 'task_id');
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
if(!is_array($data) || empty($data['task_id']) || empty($data['subscriber_id'])) {
|
||||
return;
|
||||
@ -21,6 +25,11 @@ class ScheduledTaskSubscriber extends Model {
|
||||
));
|
||||
}
|
||||
|
||||
static function setSubscribers($task_id, array $subscriber_ids) {
|
||||
static::clearSubscribers($task_id);
|
||||
return static::addSubscribers($task_id, $subscriber_ids);
|
||||
}
|
||||
|
||||
static function addSubscribers($task_id, array $subscriber_ids) {
|
||||
foreach($subscriber_ids as $subscriber_id) {
|
||||
self::createOrUpdate(array(
|
||||
@ -30,6 +39,10 @@ class ScheduledTaskSubscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static function clearSubscribers($task_id) {
|
||||
return self::where('task_id', $task_id)->deleteMany();
|
||||
}
|
||||
|
||||
static function getUnprocessedCount($task_id) {
|
||||
return self::getCount($task_id, self::STATUS_UNPROCESSED);
|
||||
}
|
||||
|
Reference in New Issue
Block a user