- Prevents WP user's first/last name to be updated during import
- Resets "next step" button state when going to step 3 of import - Closes #469
This commit is contained in:
@@ -1112,6 +1112,7 @@ define(
|
|||||||
});
|
});
|
||||||
importData.step2 = importResults;
|
importData.step2 = importResults;
|
||||||
enableSegmentSelection(mailpoetSegments);
|
enableSegmentSelection(mailpoetSegments);
|
||||||
|
toggleNextStepButton('off');
|
||||||
router.navigate('step3', {trigger: true});
|
router.navigate('step3', {trigger: true});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -47,7 +47,7 @@ class Import {
|
|||||||
list($subscribers_data, $subscriber_fields) = $this->extendSubscribersAndFields(
|
list($subscribers_data, $subscriber_fields) = $this->extendSubscribersAndFields(
|
||||||
$subscribers_data, $subscriber_fields
|
$subscribers_data, $subscriber_fields
|
||||||
);
|
);
|
||||||
list($existing_subscribers, $new_subscribers) =
|
list($existing_subscribers, $wp_users, $new_subscribers) =
|
||||||
$this->filterExistingAndNewSubscribers($subscribers_data);
|
$this->filterExistingAndNewSubscribers($subscribers_data);
|
||||||
$created_subscribers = $updated_subscribers = array();
|
$created_subscribers = $updated_subscribers = array();
|
||||||
try {
|
try {
|
||||||
@@ -68,6 +68,9 @@ class Import {
|
|||||||
$subscriber_fields,
|
$subscriber_fields,
|
||||||
$subscriber_custom_fields
|
$subscriber_custom_fields
|
||||||
);
|
);
|
||||||
|
if ($wp_users) {
|
||||||
|
$this->synchronizeWPUsers($wp_users);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(\PDOException $e) {
|
} catch(\PDOException $e) {
|
||||||
return array(
|
return array(
|
||||||
@@ -98,7 +101,7 @@ class Import {
|
|||||||
$chunk_size = 200;
|
$chunk_size = 200;
|
||||||
$existing_records = array_filter(
|
$existing_records = array_filter(
|
||||||
array_map(function($subscriber_emails) {
|
array_map(function($subscriber_emails) {
|
||||||
return Subscriber::selectMany(array('email'))
|
return Subscriber::selectMany(array('email', 'wp_user_id'))
|
||||||
->whereIn('email', $subscriber_emails)
|
->whereIn('email', $subscriber_emails)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->findArray();
|
->findArray();
|
||||||
@@ -106,10 +109,15 @@ class Import {
|
|||||||
);
|
);
|
||||||
if(!$existing_records) {
|
if(!$existing_records) {
|
||||||
return array(
|
return array(
|
||||||
false,
|
$existing_records = false,
|
||||||
|
$wp_users = false,
|
||||||
$subscribers_data
|
$subscribers_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$wp_users = array_map(function($subscriber) {
|
||||||
|
return Helpers::arrayColumn($subscriber, 'wp_user_id');
|
||||||
|
}, $existing_records);
|
||||||
|
$wp_users = array_filter($wp_users[0]);
|
||||||
$existing_records = Helpers::flattenArray($existing_records);
|
$existing_records = Helpers::flattenArray($existing_records);
|
||||||
$new_records = array_keys(
|
$new_records = array_keys(
|
||||||
array_diff(
|
array_diff(
|
||||||
@@ -120,6 +128,7 @@ class Import {
|
|||||||
if(!$new_records) {
|
if(!$new_records) {
|
||||||
return array(
|
return array(
|
||||||
$subscribers_data,
|
$subscribers_data,
|
||||||
|
$wp_users,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -144,6 +153,7 @@ class Import {
|
|||||||
}, $subscribers_data);
|
}, $subscribers_data);
|
||||||
return array(
|
return array(
|
||||||
$existing_subscribers,
|
$existing_subscribers,
|
||||||
|
$wp_users,
|
||||||
$new_subscribers
|
$new_subscribers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -339,6 +349,10 @@ class Import {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function synchronizeWPUsers($wp_users) {
|
||||||
|
return array_walk($wp_users, '\MailPoet\Segments\WP::synchronizeUser');
|
||||||
|
}
|
||||||
|
|
||||||
function addSubscribersToSegments($subscribers, $segments) {
|
function addSubscribersToSegments($subscribers, $segments) {
|
||||||
foreach(array_chunk($subscribers, 200) as $data) {
|
foreach(array_chunk($subscribers, 200) as $data) {
|
||||||
SubscriberSegment::createMultiple($segments, $data);
|
SubscriberSegment::createMultiple($segments, $data);
|
||||||
|
@@ -77,13 +77,15 @@ 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
|
||||||
));
|
));
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
list($existing, $new) = $this->import->filterExistingAndNewSubscribers(
|
list($existing, $wp_users, $new) = $this->import->filterExistingAndNewSubscribers(
|
||||||
$subscribers_data
|
$subscribers_data
|
||||||
);
|
);
|
||||||
expect($existing['email'][0])->equals($subscribers_data['email'][0]);
|
expect($existing['email'][0])->equals($subscribers_data['email'][0]);
|
||||||
|
expect($wp_users[0])->equals($subscriber->wp_user_id);
|
||||||
expect($new['email'][0])->equals($subscribers_data['email'][1]);
|
expect($new['email'][0])->equals($subscribers_data['email'][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user