Set newsletter status as draft when restoring newsletters trashed during sending [MAILPOET-816]

This commit is contained in:
Alexey Stoletniy
2017-02-21 13:13:59 +03:00
parent c98cdb3e57
commit bcf89f0dfe
3 changed files with 69 additions and 3 deletions

View File

@ -715,4 +715,23 @@ class Newsletter extends Model {
self::NEWSLETTER_HASH_LENGTH
);
}
function restore() {
if ($this->status == self::STATUS_SENDING) {
$this->set('status', self::STATUS_DRAFT);
$this->save();
}
return parent::restore();
}
static function bulkRestore($orm) {
parent::bulkAction($orm, function($ids) {
Newsletter::whereIn('id', $ids)
->where('status', Newsletter::STATUS_SENDING)
->findResultSet()
->set('status', Newsletter::STATUS_DRAFT)
->save();
});
return parent::bulkRestore($orm);
}
}