- Fixes an issue where a subscriber with the same email but different case
variant is not considered unique - Fixes an issue where an object of existing subscribers would not have the same number of data in each child array due to null values being removed - Updates unit tests
This commit is contained in:
@ -184,6 +184,9 @@ class Import {
|
|||||||
}, $existing_records);
|
}, $existing_records);
|
||||||
$wp_users = array_filter($wp_users[0]);
|
$wp_users = array_filter($wp_users[0]);
|
||||||
$existing_records = Helpers::flattenArray($existing_records);
|
$existing_records = Helpers::flattenArray($existing_records);
|
||||||
|
// convert existing subscribers' emails retrieved from the database to lowercase
|
||||||
|
// to be compared with the import UI data that has lowercase emails
|
||||||
|
$existing_records = array_map('strtolower', $existing_records);
|
||||||
$new_records = array_keys(
|
$new_records = array_keys(
|
||||||
array_diff(
|
array_diff(
|
||||||
$subscribers_data['email'],
|
$subscribers_data['email'],
|
||||||
@ -205,15 +208,12 @@ class Import {
|
|||||||
}, $new_records);
|
}, $new_records);
|
||||||
}, $subscribers_data)
|
}, $subscribers_data)
|
||||||
);
|
);
|
||||||
|
|
||||||
$existing_subscribers =
|
$existing_subscribers =
|
||||||
array_map(function($subscriber) use ($new_records) {
|
array_map(function($subscriber) use ($new_records) {
|
||||||
return array_values( // reindex array
|
return array_values( // reindex array
|
||||||
array_filter( // remove NULL entries
|
|
||||||
array_map(function($index, $data) use ($new_records) {
|
array_map(function($index, $data) use ($new_records) {
|
||||||
if(!in_array($index, $new_records)) return $data;
|
if(!in_array($index, $new_records)) return $data;
|
||||||
}, array_keys($subscriber), $subscriber)
|
}, array_keys($subscriber), $subscriber)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}, $subscribers_data);
|
}, $subscribers_data);
|
||||||
return array(
|
return array(
|
||||||
@ -387,23 +387,22 @@ class Import {
|
|||||||
CustomField::whereIn('id', $subscriber_custom_fields)->select('id')->findArray()
|
CustomField::whereIn('id', $subscriber_custom_fields)->select('id')->findArray()
|
||||||
);
|
);
|
||||||
if(!$subscriber_custom_fields) return;
|
if(!$subscriber_custom_fields) return;
|
||||||
$subscribers = array_map(
|
$subscribers = array_map(function($column) use ($db_subscribers, $subscribers_data) {
|
||||||
function($column) use ($db_subscribers, $subscribers_data) {
|
$count = range(0, count($subscribers_data[$column]) - 1);
|
||||||
$count = range(0, count($subscribers_data[$column]) - 1);
|
return array_filter( // remove null values
|
||||||
return array_map(
|
array_map(function($index, $value) use ($db_subscribers, $subscribers_data, $column) {
|
||||||
function($index, $value)
|
$subscriber_id = array_search(
|
||||||
use ($db_subscribers, $subscribers_data, $column) {
|
$subscribers_data['email'][$index],
|
||||||
$subscriber_id = array_search(
|
$db_subscribers
|
||||||
$subscribers_data['email'][$index],
|
);
|
||||||
$db_subscribers
|
// if subscriber does not not exist, return a null value
|
||||||
);
|
return ($subscriber_id) ?
|
||||||
return array(
|
array($column, $subscriber_id, $value) :
|
||||||
$column,
|
null;
|
||||||
$subscriber_id,
|
}, $count, $subscribers_data[$column])
|
||||||
$value
|
);
|
||||||
);
|
}, $subscriber_custom_fields);
|
||||||
}, $count, $subscribers_data[$column]);
|
$subscribers[0] = array_filter($subscribers[0]);
|
||||||
}, $subscriber_custom_fields);
|
|
||||||
foreach(array_chunk($subscribers[0], 200) as $data) {
|
foreach(array_chunk($subscribers[0], 200) as $data) {
|
||||||
if($action === 'create') {
|
if($action === 'create') {
|
||||||
SubscriberCustomField::createMultiple(
|
SubscriberCustomField::createMultiple(
|
||||||
|
@ -110,7 +110,7 @@ class ImportTest extends MailPoetTest {
|
|||||||
array(
|
array(
|
||||||
'first_name' => 'Adam',
|
'first_name' => 'Adam',
|
||||||
'last_name' => 'Smith',
|
'last_name' => 'Smith',
|
||||||
'email' => 'adam@smith.com',
|
'email' => 'Adam@Smith.com',
|
||||||
'wp_user_id' => 1
|
'wp_user_id' => 1
|
||||||
));
|
));
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
|
Reference in New Issue
Block a user