Merge pull request #826 from mailpoet/newsletter_restore_fix

Set newsletter status to draft when restoring newsletters trashed during sending [MAILPOET-816]
This commit is contained in:
mrcasual
2017-02-21 13:54:17 +01:00
committed by GitHub
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);
}
}

View File

@@ -136,6 +136,9 @@ abstract class ValidModel extends \Model {
} else {
$this->validateAndSet($key, $value);
}
// we should return $this to not break Idiorm's fluent interface:
// $model->set('property', 'foo')->save();
return $this;
}