- Finishes import migration

- Updates models
- Improves Notice.js
This commit is contained in:
MrCasual
2015-11-06 21:28:24 -05:00
parent 158d26ef86
commit 3f168d052f
16 changed files with 586 additions and 139 deletions

View File

@ -1,6 +1,8 @@
<?php
namespace MailPoet\Models;
use MailPoet\Util\Helpers;
if(!defined('ABSPATH')) exit;
class SubscriberCustomField extends Model {
@ -9,4 +11,38 @@ class SubscriberCustomField extends Model {
function __construct() {
parent::__construct();
}
static function createMultiple($values) {
return self::rawExecute(
'INSERT IGNORE INTO `' . self::$_table . '` ' .
'(custom_field_id, subscriber_id, value) ' .
'VALUES ' . rtrim(
str_repeat(
'(?, ?, ?)' . ', '
, count($values)
), ', '
),
Helpers::flattenArray($values)
);
}
static function updateMultiple($subscribers) {
self::createMultiple($subscribers);
self::rawExecute(
'UPDATE `' . self::$_table . '` ' .
'SET value = ' .
'(CASE ' .
str_repeat(
'WHEN custom_field_id = ? AND subscriber_id = ? THEN ? ',
count($subscribers)
) .
'END) ' .
'WHERE subscriber_id IN (' .
implode(', ', Helpers::arrayColumn($subscribers, 1)) .
') AND custom_field_id IN (' .
implode(', ', array_unique(Helpers::arrayColumn($subscribers, 0)))
. ') ',
Helpers::flattenArray($subscribers)
);
}
}