- Adds new "hash" column to the newsletters table
- Updates newsletter model to automatically generate hash when saving newsletter - Adds new getByHash method to the newsletter model
This commit is contained in:
@ -11,7 +11,6 @@ class Newsletter extends Model {
|
||||
const TYPE_WELCOME = 'welcome';
|
||||
const TYPE_NOTIFICATION = 'notification';
|
||||
const TYPE_NOTIFICATION_HISTORY = 'notification_history';
|
||||
|
||||
// standard newsletters
|
||||
const STATUS_DRAFT = 'draft';
|
||||
const STATUS_SCHEDULED = 'scheduled';
|
||||
@ -19,6 +18,7 @@ class Newsletter extends Model {
|
||||
const STATUS_SENT = 'sent';
|
||||
// automatic newsletters status
|
||||
const STATUS_ACTIVE = 'active';
|
||||
const NEWSLETTER_HASH_LENGTH = 6;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
@ -37,6 +37,12 @@ class Newsletter extends Model {
|
||||
? json_encode($this->body)
|
||||
: $this->body
|
||||
);
|
||||
|
||||
$this->set('hash',
|
||||
($this->hash)
|
||||
? $this->hash
|
||||
: self::generateHash($this->id)
|
||||
);
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
@ -647,4 +653,16 @@ class Newsletter extends Model {
|
||||
}
|
||||
return $orm->findMany();
|
||||
}
|
||||
}
|
||||
|
||||
static function getByHash($hash) {
|
||||
return parent::where('hash', $hash)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
static function generateHash($id = null) {
|
||||
if(!is_null($id)) {
|
||||
return substr(md5(AUTH_KEY . $id), 0, self::NEWSLETTER_HASH_LENGTH);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user