- Renamed List model to Segment

This commit is contained in:
MrCasual
2015-09-02 09:29:54 -04:00
parent 78a2a50af7
commit 64756c865d
8 changed files with 109 additions and 109 deletions

View File

@ -34,13 +34,13 @@ class Initializer {
$settings = Env::$db_prefix . 'settings'; $settings = Env::$db_prefix . 'settings';
$newsletters = Env::$db_prefix . 'newsletters'; $newsletters = Env::$db_prefix . 'newsletters';
$lists = Env::$db_prefix . 'lists'; $lists = Env::$db_prefix . 'lists';
$subscriber_list = Env::$db_prefix . 'subscriber_list'; $subscriber_segment = Env::$db_prefix . 'subscriber_segment';
define('MP_SUBSCRIBERS_TABLE', $subscribers); define('MP_SUBSCRIBERS_TABLE', $subscribers);
define('MP_SETTINGS_TABLE', $settings); define('MP_SETTINGS_TABLE', $settings);
define('MP_NEWSLETTERS_TABLE', $newsletters); define('MP_NEWSLETTERS_TABLE', $newsletters);
define('MP_LISTS_TABLE', $lists); define('MP_LISTS_TABLE', $lists);
define('MP_SUBSCRIBER_LIST_TABLE', $subscriber_list); define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
} }
function setupActivator() { function setupActivator() {

View File

@ -14,7 +14,7 @@ class Migrator {
'settings', 'settings',
'newsletters', 'newsletters',
'lists', 'lists',
'subscriber_list' 'subscriber_segment'
); );
} }
@ -91,7 +91,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function subscriber_list() { function subscriber_segment() {
$attributes = array( $attributes = array(
'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,',

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
class SList extends Model { class Segment extends Model {
public static $_table = MP_LISTS_TABLE; public static $_table = MP_LISTS_TABLE;
function __construct() { function __construct() {
@ -30,6 +30,6 @@ class SList extends Model {
} }
public function subscribers() { public function subscribers() {
return self::has_many_through(__NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\SubscriberList', 'list_id', 'subscriber_id'); return self::has_many_through(__NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\SubscriberSegment', 'list_id', 'subscriber_id');
} }
} }

View File

@ -16,6 +16,6 @@ class Subscriber extends Model {
} }
public function lists() { public function lists() {
return self::has_many_through(__NAMESPACE__ . '\SList', __NAMESPACE__ . '\SubscriberList', 'subscriber_id', 'list_id'); return self::has_many_through(__NAMESPACE__ . '\Segment', __NAMESPACE__ . '\SubscriberSegment', 'subscriber_id', 'list_id');
} }
} }

View File

@ -3,8 +3,8 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
class SubscriberList extends Model { class SubscriberSegment extends Model {
public static $_table = MP_SUBSCRIBER_LIST_TABLE; public static $_table = MP_SUBSCRIBER_SEGMENT_TABLE;
function __construct() { function __construct() {
parent::__construct(); parent::__construct();

View File

@ -10,8 +10,8 @@ $models = array(
'Subscriber', 'Subscriber',
'Setting', 'Setting',
'Newsletter', 'Newsletter',
'SList', 'Segment',
'SubscriberList' 'SubscriberSegment'
); );
$destroy = function ($model) { $destroy = function ($model) {
Model::factory('\MailPoet\Models\\' . $model) Model::factory('\MailPoet\Models\\' . $model)

View File

@ -1,8 +1,8 @@
<?php <?php
use MailPoet\Models\SubscriberList; use MailPoet\Models\SubscriberSegment;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\SList; use MailPoet\Models\Segment;
class SListCest { class SListCest {
function _before() { function _before() {
@ -11,7 +11,7 @@ class SListCest {
'name' => 'some name', 'name' => 'some name',
); );
$this->list = SList::create(); $this->list = Segment::create();
$this->list->hydrate($this->data); $this->list->hydrate($this->data);
$this->saved = $this->list->save(); $this->saved = $this->list->save();
} }
@ -22,28 +22,28 @@ class SListCest {
function itHasToBeValid() { function itHasToBeValid() {
expect($this->saved)->equals(true); expect($this->saved)->equals(true);
$empty_model = SList::create(); $empty_model = Segment::create();
expect($empty_model->save())->equals(false); expect($empty_model->save())->equals(false);
$validations = $empty_model->getValidationErrors(); $validations = $empty_model->getValidationErrors();
expect(count($validations))->equals(2); expect(count($validations))->equals(2);
} }
function itHasACreatedAtOnCreation() { function itHasACreatedAtOnCreation() {
$list = SList::where('name', $this->data['name']) $list = Segment::where('name', $this->data['name'])
->findOne(); ->findOne();
$time_difference = strtotime($list->created_at) >= $this->before_time; $time_difference = strtotime($list->created_at) >= $this->before_time;
expect($time_difference)->equals(true); expect($time_difference)->equals(true);
} }
function itHasAnUpdatedAtOnCreation() { function itHasAnUpdatedAtOnCreation() {
$list = SList::where('name', $this->data['name']) $list = Segment::where('name', $this->data['name'])
->findOne(); ->findOne();
$time_difference = strtotime($list->updated_at) >= $this->before_time; $time_difference = strtotime($list->updated_at) >= $this->before_time;
expect($time_difference)->equals(true); expect($time_difference)->equals(true);
} }
function itKeepsTheCreatedAtOnUpdate() { function itKeepsTheCreatedAtOnUpdate() {
$list = SList::where('name', $this->data['name']) $list = Segment::where('name', $this->data['name'])
->findOne(); ->findOne();
$old_created_at = $list->created_at; $old_created_at = $list->created_at;
$list->name = 'new name'; $list->name = 'new name';
@ -52,7 +52,7 @@ class SListCest {
} }
function itUpdatesTheUpdatedAtOnUpdate() { function itUpdatesTheUpdatedAtOnUpdate() {
$list = SList::where('name', $this->data['name']) $list = Segment::where('name', $this->data['name'])
->findOne(); ->findOne();
$update_time = time(); $update_time = time();
$list->name = 'new name'; $list->name = 'new name';
@ -65,15 +65,15 @@ class SListCest {
$data = array( $data = array(
'name' => 'some other new name' 'name' => 'some other new name'
); );
$createNewRecord = SList::createOrUpdate($data); $createNewRecord = Segment::createOrUpdate($data);
$data = array( $data = array(
'name' => $this->data['name'], 'name' => $this->data['name'],
'name_updated' => 'updated name', 'name_updated' => 'updated name',
); );
$updateExistingRecord = SList::createOrUpdate($data); $updateExistingRecord = Segment::createOrUpdate($data);
$allRecords = SList::find_array(); $allRecords = Segment::find_array();
expect(count($allRecords))->equals(2); expect(count($allRecords))->equals(2);
expect($allRecords[0]['name'])->equals($data['name_updated']); expect($allRecords[0]['name'])->equals($data['name_updated']);
} }
@ -95,24 +95,24 @@ class SListCest {
$subscriber = Subscriber::create(); $subscriber = Subscriber::create();
$subscriber->hydrate($subscriberData); $subscriber->hydrate($subscriberData);
$subscriber->save(); $subscriber->save();
$association = SubscriberList::create(); $association = SubscriberSegment::create();
$association->subscriber_id = $subscriber->id; $association->subscriber_id = $subscriber->id;
$association->list_id = $this->list->id; $association->list_id = $this->list->id;
$association->save(); $association->save();
} }
$list = SList::find_one($this->list->id); $list = Segment::find_one($this->list->id);
$subscribers = $list->subscribers() $subscribers = $list->subscribers()
->find_array(); ->find_array();
expect(count($subscribers))->equals(2); expect(count($subscribers))->equals(2);
} }
function _after() { function _after() {
ORM::for_table(SList::$_table) ORM::for_table(Segment::$_table)
->delete_many(); ->delete_many();
ORM::for_table(Subscriber::$_table) ORM::for_table(Subscriber::$_table)
->delete_many(); ->delete_many();
ORM::for_table(SubscriberList::$_table) ORM::for_table(SubscriberSegment::$_table)
->delete_many(); ->delete_many();
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\SList; use MailPoet\Models\Segment;
use MailPoet\Models\SubscriberList; use MailPoet\Models\SubscriberSegment;
class SubscriberCest { class SubscriberCest {
@ -58,10 +58,10 @@ class SubscriberCest {
'name' => 'some name' 'name' => 'some name'
); );
$list = SList::create(); $list = Segment::create();
$list->hydrate($listData); $list->hydrate($listData);
$list->save(); $list->save();
$association = SubscriberList::create(); $association = SubscriberSegment::create();
$association->subscriber_id = $this->subscriber->id; $association->subscriber_id = $this->subscriber->id;
$association->list_id = $list->id; $association->list_id = $list->id;
$association->save(); $association->save();
@ -75,9 +75,9 @@ class SubscriberCest {
function _after() { function _after() {
ORM::for_table(Subscriber::$_table) ORM::for_table(Subscriber::$_table)
->delete_many(); ->delete_many();
ORM::for_table(SList::$_table) ORM::for_table(Segment::$_table)
->delete_many(); ->delete_many();
ORM::for_table(SubscriberList::$_table) ORM::for_table(SubscriberSegment::$_table)
->delete_many(); ->delete_many();
} }
} }