diff --git a/lib/Config/MP2Migrator.php b/lib/Config/MP2Migrator.php index f6ea2cc057..d1af4fce42 100644 --- a/lib/Config/MP2Migrator.php +++ b/lib/Config/MP2Migrator.php @@ -156,7 +156,6 @@ class MP2Migrator { } $this->importSegments(); - $this->segments_mapping = $this->getImportedMapping('segments'); $this->importCustomFields(); $this->importSubscribers(); @@ -287,6 +286,7 @@ class MP2Migrator { private function importSegments() { $imported_segments_count = 0; if($this->importStopped()) { + $this->segments_mapping = $this->getImportedMapping('segments'); return; } $this->log(__("Importing segments...", 'mailpoet')); @@ -308,6 +308,8 @@ class MP2Migrator { $this->progressbar->incrementCurrentCount($lists_count); } while(($lists != null) && ($lists_count > 0)); + $this->segments_mapping = $this->getImportedMapping('segments'); + $this->log(sprintf(_n("%d segment imported", "%d segments imported", $imported_segments_count, 'mailpoet'), $imported_segments_count)); } diff --git a/tests/unit/Config/MP2MigratorTest.php b/tests/unit/Config/MP2MigratorTest.php index cac3301576..f4c72349f6 100644 --- a/tests/unit/Config/MP2MigratorTest.php +++ b/tests/unit/Config/MP2MigratorTest.php @@ -133,9 +133,9 @@ class MP2MigratorTest extends MailPoetTest { 'created_at' => $timestamp, )); $this->invokeMethod($this->MP2Migrator, 'importSegments'); + $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); $table = MP_SEGMENTS_TABLE; - $segment = $wpdb->get_row("SELECT * FROM $table WHERE id=$id"); - expect($segment->id)->equals($id); + $segment = $wpdb->get_row("SELECT * FROM $table WHERE id=" . $importedSegmentsMapping[$id]); expect($segment->name)->equals($name); expect($segment->description)->equals($description); } @@ -195,7 +195,7 @@ class MP2MigratorTest extends MailPoetTest { $this->initImport(); $this->loadMP2Fixtures(); $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - expect(Subscriber::count())->equals(4); + expect(Subscriber::count())->equals(5); // 4 MP2 users + the current user // Check a subscriber data $this->initImport(); @@ -240,7 +240,7 @@ class MP2MigratorTest extends MailPoetTest { $this->loadMP2Fixtures(); $this->invokeMethod($this->MP2Migrator, 'importSegments'); $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - expect(SubscriberSegment::count())->equals(7); + expect(SubscriberSegment::count())->equals(8); // 7 + the current user belongs to WordPress users segment // Check a subscriber segment data @@ -278,10 +278,12 @@ class MP2MigratorTest extends MailPoetTest { $this->invokeMethod($this->MP2Migrator, 'importSegments'); $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); + $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); $importedSubscribersMapping = $this->MP2Migrator->getImportedMapping('subscribers'); $table = MP_SUBSCRIBER_SEGMENT_TABLE; + $segment_id = $importedSegmentsMapping[$list_id]; $subscriber_id = $importedSubscribersMapping[$user_id]; - $subscriber_segment = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriber_id' AND segment_id='$list_id'"); + $subscriber_segment = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriber_id' AND segment_id='$segment_id'"); expect($subscriber_segment)->notNull(); }