- 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:
@@ -177,6 +177,7 @@ class Migrator {
|
|||||||
function newsletters() {
|
function newsletters() {
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
|
'hash varchar(150) NULL DEFAULT NULL,',
|
||||||
'parent_id mediumint(9) NULL,',
|
'parent_id mediumint(9) NULL,',
|
||||||
'subject varchar(250) NOT NULL DEFAULT "",',
|
'subject varchar(250) NOT NULL DEFAULT "",',
|
||||||
'type varchar(20) NOT NULL DEFAULT "standard",',
|
'type varchar(20) NOT NULL DEFAULT "standard",',
|
||||||
|
@@ -11,7 +11,6 @@ class Newsletter extends Model {
|
|||||||
const TYPE_WELCOME = 'welcome';
|
const TYPE_WELCOME = 'welcome';
|
||||||
const TYPE_NOTIFICATION = 'notification';
|
const TYPE_NOTIFICATION = 'notification';
|
||||||
const TYPE_NOTIFICATION_HISTORY = 'notification_history';
|
const TYPE_NOTIFICATION_HISTORY = 'notification_history';
|
||||||
|
|
||||||
// standard newsletters
|
// standard newsletters
|
||||||
const STATUS_DRAFT = 'draft';
|
const STATUS_DRAFT = 'draft';
|
||||||
const STATUS_SCHEDULED = 'scheduled';
|
const STATUS_SCHEDULED = 'scheduled';
|
||||||
@@ -19,6 +18,7 @@ class Newsletter extends Model {
|
|||||||
const STATUS_SENT = 'sent';
|
const STATUS_SENT = 'sent';
|
||||||
// automatic newsletters status
|
// automatic newsletters status
|
||||||
const STATUS_ACTIVE = 'active';
|
const STATUS_ACTIVE = 'active';
|
||||||
|
const NEWSLETTER_HASH_LENGTH = 6;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -37,6 +37,12 @@ class Newsletter extends Model {
|
|||||||
? json_encode($this->body)
|
? json_encode($this->body)
|
||||||
: $this->body
|
: $this->body
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->set('hash',
|
||||||
|
($this->hash)
|
||||||
|
? $this->hash
|
||||||
|
: self::generateHash($this->id)
|
||||||
|
);
|
||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,4 +653,16 @@ class Newsletter extends Model {
|
|||||||
}
|
}
|
||||||
return $orm->findMany();
|
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