Merge pull request #477 from mailpoet/php7_mysql_fix
Fix for PHP7 & Mysql 5.7
This commit is contained in:
@ -59,10 +59,10 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'name varchar(90) NOT NULL,',
|
'name varchar(90) NOT NULL,',
|
||||||
'type varchar(90) NOT NULL DEFAULT "default",',
|
'type varchar(90) NOT NULL DEFAULT "default",',
|
||||||
'description varchar(250) NOT NULL,',
|
'description varchar(250) NOT NULL DEFAULT "",',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
'deleted_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY name (name)'
|
'UNIQUE KEY name (name)'
|
||||||
);
|
);
|
||||||
@ -110,11 +110,11 @@ class Migrator {
|
|||||||
'count_processed mediumint(9) NOT NULL DEFAULT 0,',
|
'count_processed mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'count_to_process mediumint(9) NOT NULL DEFAULT 0,',
|
'count_to_process mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'count_failed mediumint(9) NOT NULL DEFAULT 0,',
|
'count_failed mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'scheduled_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'scheduled_at TIMESTAMP NULL,',
|
||||||
'processed_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'processed_at TIMESTAMP NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
'deleted_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -124,13 +124,13 @@ class Migrator {
|
|||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'wp_user_id bigint(20) NULL,',
|
'wp_user_id bigint(20) NULL,',
|
||||||
'first_name tinytext NOT NULL,',
|
'first_name tinytext NOT NULL DEFAULT "",',
|
||||||
'last_name tinytext NOT NULL,',
|
'last_name tinytext NOT NULL DEFAULT "",',
|
||||||
'email varchar(150) NOT NULL,',
|
'email varchar(150) NOT NULL,',
|
||||||
'status varchar(12) NOT NULL DEFAULT "unconfirmed",',
|
'status varchar(12) NOT NULL DEFAULT "unconfirmed",',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'deleted_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY email (email)'
|
'UNIQUE KEY email (email)'
|
||||||
);
|
);
|
||||||
@ -143,8 +143,8 @@ class Migrator {
|
|||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'segment_id mediumint(9) NOT NULL,',
|
'segment_id mediumint(9) NOT NULL,',
|
||||||
'status varchar(12) NOT NULL DEFAULT "subscribed",',
|
'status varchar(12) NOT NULL DEFAULT "subscribed",',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY subscriber_segment (subscriber_id,segment_id)'
|
'UNIQUE KEY subscriber_segment (subscriber_id,segment_id)'
|
||||||
);
|
);
|
||||||
@ -156,9 +156,9 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'custom_field_id mediumint(9) NOT NULL,',
|
'custom_field_id mediumint(9) NOT NULL,',
|
||||||
'value varchar(255) NOT NULL,',
|
'value varchar(255) NOT NULL DEFAULT "",',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY subscriber_id_custom_field_id (subscriber_id,custom_field_id)'
|
'UNIQUE KEY subscriber_id_custom_field_id (subscriber_id,custom_field_id)'
|
||||||
);
|
);
|
||||||
@ -168,17 +168,17 @@ class Migrator {
|
|||||||
function newsletters() {
|
function newsletters() {
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'subject varchar(250) NOT NULL,',
|
'subject varchar(250) NOT NULL DEFAULT "",',
|
||||||
'type varchar(20) NOT NULL DEFAULT "standard",',
|
'type varchar(20) NOT NULL DEFAULT "standard",',
|
||||||
'sender_address varchar(150) NOT NULL,',
|
'sender_address varchar(150) NOT NULL DEFAULT "",',
|
||||||
'sender_name varchar(150) NOT NULL,',
|
'sender_name varchar(150) NOT NULL DEFAULT "",',
|
||||||
'reply_to_address varchar(150) NOT NULL,',
|
'reply_to_address varchar(150) NOT NULL DEFAULT "",',
|
||||||
'reply_to_name varchar(150) NOT NULL,',
|
'reply_to_name varchar(150) NOT NULL DEFAULT "",',
|
||||||
'preheader varchar(250) NOT NULL,',
|
'preheader varchar(250) NOT NULL DEFAULT "",',
|
||||||
'body longtext,',
|
'body longtext,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'deleted_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id)'
|
'PRIMARY KEY (id)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -192,8 +192,8 @@ class Migrator {
|
|||||||
'body LONGTEXT,',
|
'body LONGTEXT,',
|
||||||
'thumbnail LONGTEXT,',
|
'thumbnail LONGTEXT,',
|
||||||
'readonly TINYINT(1) DEFAULT 0,',
|
'readonly TINYINT(1) DEFAULT 0,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id)'
|
'PRIMARY KEY (id)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -204,8 +204,8 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'name varchar(90) NOT NULL,',
|
'name varchar(90) NOT NULL,',
|
||||||
'newsletter_type varchar(90) NOT NULL,',
|
'newsletter_type varchar(90) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY name_newsletter_type (newsletter_type,name)'
|
'UNIQUE KEY name_newsletter_type (newsletter_type,name)'
|
||||||
);
|
);
|
||||||
@ -217,9 +217,9 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'option_field_id mediumint(9) NOT NULL,',
|
'option_field_id mediumint(9) NOT NULL,',
|
||||||
'value varchar(255) NOT NULL,',
|
'value varchar(255) NOT NULL DEFAULT "",',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY newsletter_id_option_field_id (newsletter_id,option_field_id)'
|
'UNIQUE KEY newsletter_id_option_field_id (newsletter_id,option_field_id)'
|
||||||
);
|
);
|
||||||
@ -231,8 +231,8 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'segment_id mediumint(9) NOT NULL,',
|
'segment_id mediumint(9) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY newsletter_segment (newsletter_id,segment_id)'
|
'UNIQUE KEY newsletter_segment (newsletter_id,segment_id)'
|
||||||
);
|
);
|
||||||
@ -246,8 +246,8 @@ class Migrator {
|
|||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'url varchar(255) NOT NULL,',
|
'url varchar(255) NOT NULL,',
|
||||||
'hash varchar(20) NOT NULL,',
|
'hash varchar(20) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -260,9 +260,9 @@ class Migrator {
|
|||||||
'body longtext,',
|
'body longtext,',
|
||||||
'settings longtext,',
|
'settings longtext,',
|
||||||
'styles longtext,',
|
'styles longtext,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'deleted_at TIMESTAMP NULL DEFAULT NULL,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'deleted_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id)'
|
'PRIMARY KEY (id)'
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -274,7 +274,7 @@ class Migrator {
|
|||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'sent_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'sent_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -288,8 +288,8 @@ class Migrator {
|
|||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'link_id mediumint(9) NOT NULL,',
|
'link_id mediumint(9) NOT NULL,',
|
||||||
'count mediumint(9) NOT NULL,',
|
'count mediumint(9) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -301,7 +301,7 @@ class Migrator {
|
|||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -313,7 +313,7 @@ class Migrator {
|
|||||||
'newsletter_id mediumint(9) NOT NULL,',
|
'newsletter_id mediumint(9) NOT NULL,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'queue_id mediumint(9) NOT NULL,',
|
'queue_id mediumint(9) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id)',
|
'PRIMARY KEY (id)',
|
||||||
);
|
);
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
@ -324,7 +324,7 @@ class Migrator {
|
|||||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||||
'form_id mediumint(9) NOT NULL,',
|
'form_id mediumint(9) NOT NULL,',
|
||||||
'subscriber_id mediumint(9) NOT NULL,',
|
'subscriber_id mediumint(9) NOT NULL,',
|
||||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
'created_at TIMESTAMP NULL,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY form_subscriber (form_id,subscriber_id)'
|
'UNIQUE KEY form_subscriber (form_id,subscriber_id)'
|
||||||
);
|
);
|
||||||
|
@ -309,9 +309,10 @@ class Subscriber extends Model {
|
|||||||
$customFields = CustomField::findArray();
|
$customFields = CustomField::findArray();
|
||||||
foreach ($customFields as $customField) {
|
foreach ($customFields as $customField) {
|
||||||
$orm = $orm->selectExpr(
|
$orm = $orm->selectExpr(
|
||||||
'CASE WHEN ' .
|
'MAX(CASE WHEN ' .
|
||||||
MP_CUSTOM_FIELDS_TABLE . '.id=' . $customField['id'] . ' THEN ' .
|
MP_CUSTOM_FIELDS_TABLE . '.id=' . $customField['id'] . ' THEN ' .
|
||||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value END as "' . $customField['id'].'"');
|
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value END) as "' . $customField['id'].'"'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$orm = $orm
|
$orm = $orm
|
||||||
->leftOuterJoin(
|
->leftOuterJoin(
|
||||||
|
@ -175,6 +175,7 @@ class Export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSubscribers($offset, $limit) {
|
function getSubscribers($offset, $limit) {
|
||||||
|
// JOIN subscribers on segment and subscriber_segment tables
|
||||||
$subscribers = Subscriber::
|
$subscribers = Subscriber::
|
||||||
left_outer_join(
|
left_outer_join(
|
||||||
SubscriberSegment::$_table,
|
SubscriberSegment::$_table,
|
||||||
@ -190,12 +191,16 @@ class Export {
|
|||||||
'=',
|
'=',
|
||||||
SubscriberSegment::$_table . '.segment_id'
|
SubscriberSegment::$_table . '.segment_id'
|
||||||
))
|
))
|
||||||
->filter('filterWithCustomFieldsForExport');
|
->filter('filterWithCustomFieldsForExport')
|
||||||
|
->groupBy(Subscriber::$_table . '.id');
|
||||||
if($this->subscribers_without_segment !== false) {
|
if($this->subscribers_without_segment !== false) {
|
||||||
|
// if there are subscribers who do not belong to any segment, use
|
||||||
|
// a CASE function to group them under "Not In Segment"
|
||||||
$subscribers = $subscribers
|
$subscribers = $subscribers
|
||||||
->selectExpr('CASE WHEN ' . Segment::$_table . '.name IS NOT NULL ' .
|
->selectExpr(
|
||||||
|
'MAX(CASE WHEN ' . Segment::$_table . '.name IS NOT NULL ' .
|
||||||
'THEN ' . Segment::$_table . '.name ' .
|
'THEN ' . Segment::$_table . '.name ' .
|
||||||
'ELSE "' . __('Not In Segment') . '" END as segment_name'
|
'ELSE "' . __('Not In Segment') . '" END) as segment_name'
|
||||||
)
|
)
|
||||||
->whereRaw(
|
->whereRaw(
|
||||||
SubscriberSegment::$_table . '.segment_id IN (' .
|
SubscriberSegment::$_table . '.segment_id IN (' .
|
||||||
@ -204,21 +209,23 @@ class Export {
|
|||||||
$this->segments
|
$this->segments
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// if all subscribers belong to at least one segment, select the segment name
|
||||||
$subscribers = $subscribers
|
$subscribers = $subscribers
|
||||||
->select(Segment::$_table . '.name', 'segment_name')
|
->selectExpr('MAX('.Segment::$_table . '.name) as segment_name')
|
||||||
->whereIn(SubscriberSegment::$_table . '.segment_id', $this->segments);
|
->whereIn(SubscriberSegment::$_table . '.segment_id', $this->segments);
|
||||||
}
|
}
|
||||||
if(!$this->group_by_segment_option) {
|
if($this->group_by_segment_option) {
|
||||||
$subscribers =
|
$subscribers = $subscribers->groupBy(Segment::$_table . '.id');
|
||||||
$subscribers->groupBy(Subscriber::$_table . '.id');
|
|
||||||
}
|
}
|
||||||
if($this->export_confirmed_option) {
|
if($this->export_confirmed_option) {
|
||||||
|
// select only subscribers with "subscribed" status
|
||||||
$subscribers =
|
$subscribers =
|
||||||
$subscribers->where(Subscriber::$_table . '.status', 'subscribed');
|
$subscribers->where(Subscriber::$_table . '.status', 'subscribed');
|
||||||
}
|
}
|
||||||
$subscribers = $subscribers
|
$subscribers = $subscribers
|
||||||
->whereNull(Subscriber::$_table . '.deleted_at')
|
->whereNull(Subscriber::$_table . '.deleted_at')
|
||||||
->limit(sprintf('%d, %d', $offset, $limit))
|
->offset($offset)
|
||||||
|
->limit($limit)
|
||||||
->findArray();
|
->findArray();
|
||||||
return $subscribers;
|
return $subscribers;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,8 @@ class MailChimp {
|
|||||||
function getDataCenter($APIKey) {
|
function getDataCenter($APIKey) {
|
||||||
if (!preg_match('/-[a-zA-Z0-9]{3,}/', $APIKey)) return false;
|
if (!preg_match('/-[a-zA-Z0-9]{3,}/', $APIKey)) return false;
|
||||||
// double parantheses: http://phpsadness.com/sad/51
|
// double parantheses: http://phpsadness.com/sad/51
|
||||||
return end((explode('-', $APIKey)));
|
$key_parts = explode('-', $APIKey);
|
||||||
|
return end($key_parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAPIKey($APIKey) {
|
function getAPIKey($APIKey) {
|
||||||
|
@ -66,7 +66,6 @@ class CustomFieldTest extends MailPoetTest {
|
|||||||
function testItHasACreatedAtOnCreation() {
|
function testItHasACreatedAtOnCreation() {
|
||||||
$custom_field = CustomField::findOne($this->custom_field->id);
|
$custom_field = CustomField::findOne($this->custom_field->id);
|
||||||
expect($custom_field->created_at)->notNull();
|
expect($custom_field->created_at)->notNull();
|
||||||
expect($custom_field->created_at)->notEquals('0000-00-00 00:00:00');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasAnUpdatedAtOnCreation() {
|
function testItHasAnUpdatedAtOnCreation() {
|
||||||
|
@ -49,7 +49,6 @@ class FormTest extends MailPoetTest {
|
|||||||
function testItHasACreatedAtOnCreation() {
|
function testItHasACreatedAtOnCreation() {
|
||||||
$form = Form::findOne($this->form->id);
|
$form = Form::findOne($this->form->id);
|
||||||
expect($form->created_at)->notNull();
|
expect($form->created_at)->notNull();
|
||||||
expect($form->created_at)->notEquals('0000-00-00 00:00:00');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasAnUpdatedAtOnCreation() {
|
function testItHasAnUpdatedAtOnCreation() {
|
||||||
|
@ -59,7 +59,6 @@ class NewsletterOptionFieldTest extends MailPoetTest {
|
|||||||
|
|
||||||
function testItHasACreatedAtOnCreation() {
|
function testItHasACreatedAtOnCreation() {
|
||||||
expect($this->option_field->created_at)->notNull();
|
expect($this->option_field->created_at)->notNull();
|
||||||
expect($this->option_field->created_at)->notEquals('0000-00-00 00:00:00');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasAnUpdatedAtOnCreation() {
|
function testItHasAnUpdatedAtOnCreation() {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SendingQueue;
|
use MailPoet\Models\SendingQueue;
|
||||||
use MailPoet\Models\NewsletterSegment;
|
use MailPoet\Models\NewsletterSegment;
|
||||||
use MailPoet\Models\NewsletterOptionField;
|
use MailPoet\Models\NewsletterOptionField;
|
||||||
@ -61,7 +62,6 @@ class NewsletterTest extends MailPoetTest {
|
|||||||
function testItHasACreatedAtOnCreation() {
|
function testItHasACreatedAtOnCreation() {
|
||||||
$newsletter = Newsletter::findOne($this->newsletter->id);
|
$newsletter = Newsletter::findOne($this->newsletter->id);
|
||||||
expect($newsletter->created_at)->notNull();
|
expect($newsletter->created_at)->notNull();
|
||||||
expect($newsletter->created_at)->notEquals('0000-00-00 00:00:00');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasAnUpdatedAtOnCreation() {
|
function testItHasAnUpdatedAtOnCreation() {
|
||||||
@ -111,10 +111,17 @@ class NewsletterTest extends MailPoetTest {
|
|||||||
$sending_queue = SendingQueue::create();
|
$sending_queue = SendingQueue::create();
|
||||||
$sending_queue->newsletter_id = $this->newsletter->id;
|
$sending_queue->newsletter_id = $this->newsletter->id;
|
||||||
$sending_queue->save();
|
$sending_queue->save();
|
||||||
|
|
||||||
|
$subscriber = Subscriber::createOrUpdate(array(
|
||||||
|
'email' => 'john.doe@mailpoet.com'
|
||||||
|
));
|
||||||
|
|
||||||
$opens = StatisticsOpens::create();
|
$opens = StatisticsOpens::create();
|
||||||
|
$opens->subscriber_id = $subscriber->id;
|
||||||
$opens->newsletter_id = $this->newsletter->id;
|
$opens->newsletter_id = $this->newsletter->id;
|
||||||
$opens->queue_id = $sending_queue->id;
|
$opens->queue_id = $sending_queue->id;
|
||||||
$opens->save();
|
$opens->save();
|
||||||
|
|
||||||
$newsletter->queue = $newsletter->getQueue()->asArray();
|
$newsletter->queue = $newsletter->getQueue()->asArray();
|
||||||
$statistics = $newsletter->getStatistics();
|
$statistics = $newsletter->getStatistics();
|
||||||
expect($statistics->opened)->equals(1);
|
expect($statistics->opened)->equals(1);
|
||||||
|
@ -78,7 +78,6 @@ class SegmentTest extends MailPoetTest {
|
|||||||
function testItHasACreatedAtOnCreation() {
|
function testItHasACreatedAtOnCreation() {
|
||||||
$segment = Segment::findOne($this->segment->id);
|
$segment = Segment::findOne($this->segment->id);
|
||||||
expect($segment->created_at)->notNull();
|
expect($segment->created_at)->notNull();
|
||||||
expect($segment->created_at)->notEquals('0000-00-00 00:00:00');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasAnUpdatedAtOnCreation() {
|
function testItHasAnUpdatedAtOnCreation() {
|
||||||
|
@ -53,8 +53,10 @@ class NewslettersTest extends MailPoetTest {
|
|||||||
|
|
||||||
function testItCanSaveAnExistingNewsletter() {
|
function testItCanSaveAnExistingNewsletter() {
|
||||||
$router = new Newsletters();
|
$router = new Newsletters();
|
||||||
$newsletter_data = $this->newsletter->asArray();
|
$newsletter_data = array(
|
||||||
$newsletter_data['subject'] = 'My Updated Newsletter';
|
'id' => $this->newsletter->id,
|
||||||
|
'subject' => 'My Updated Newsletter'
|
||||||
|
);
|
||||||
|
|
||||||
$response = $router->save($newsletter_data);
|
$response = $router->save($newsletter_data);
|
||||||
expect($response['result'])->true();
|
expect($response['result'])->true();
|
||||||
|
@ -64,9 +64,9 @@ class ExportTest extends MailPoetTest {
|
|||||||
$entity->hydrate($subscriber);
|
$entity->hydrate($subscriber);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
foreach($this->segments_data as $custom_field) {
|
foreach($this->segments_data as $segment) {
|
||||||
$entity = Segment::create();
|
$entity = Segment::create();
|
||||||
$entity->hydrate($custom_field);
|
$entity->hydrate($segment);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
foreach($this->custom_fields_data as $custom_field) {
|
foreach($this->custom_fields_data as $custom_field) {
|
||||||
|
Reference in New Issue
Block a user