Only schedule notification for standard newsletters

[MAILPOET-1571]
This commit is contained in:
Pavel Dohnal
2019-01-08 15:53:47 +01:00
parent 1d34613b17
commit 6452e83476
5 changed files with 63 additions and 27 deletions

View File

@ -5,5 +5,29 @@ namespace MailPoet\Models;
class StatsNotification extends Model {
public static $_table = MP_STATS_NOTIFICATIONS_TABLE;
/** @return StatsNotification */
static function createOrUpdate($data = array()) {
$model = null;
if(isset($data['id']) && (int)$data['id'] > 0) {
$model = static::findOne((int)$data['id']);
}
if(!$model && isset($data['task_id']) && $data['newsletter_id']) {
$model = self::where('newsletter_id', $data['newsletter_id'])
->where('task_id', $data['task_id'])
->findOne();
}
if(!$model) {
$model = static::create();
$model->hydrate($data);
} else {
unset($data['id']);
$model->set($data);
}
return $model->save();
}
}