From ede86717c010d1996437fbc130dbdddbad608612 Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Tue, 29 Sep 2015 08:43:23 -0700 Subject: [PATCH] Issue #2500469 by svendecabooter, phenaproxima: Migration path for Aggregator 7.x --- .../d6_aggregator_feed.yml | 2 +- .../d6_aggregator_item.yml | 5 +- .../d7_aggregator_feed.yml | 20 ++++++ .../d7_aggregator_item.yml | 23 +++++++ .../source/{d6 => }/AggregatorFeed.php | 33 +++------ .../source/{d6 => }/AggregatorItem.php | 14 ++-- .../Migrate/d6/MigrateAggregatorFeedTest.php | 5 +- .../Migrate/d6/MigrateAggregatorItemTest.php | 4 +- .../Migrate/d7/MigrateAggregatorFeedTest.php | 50 ++++++++++++++ .../Migrate/d7/MigrateAggregatorItemTest.php | 50 ++++++++++++++ .../source/{d6 => }/AggregatorItemTest.php | 30 ++++----- .../migrate/source/d6/AggregatorFeedTest.php | 6 +- .../migrate/source/d7/AggregatorFeedTest.php | 67 +++++++++++++++++++ .../src/Tests/Table/d7/AggregatorFeed.php | 18 ++++- .../src/Tests/Table/d7/AggregatorItem.php | 13 +++- 15 files changed, 275 insertions(+), 65 deletions(-) create mode 100644 core/modules/aggregator/migration_templates/d7_aggregator_feed.yml create mode 100644 core/modules/aggregator/migration_templates/d7_aggregator_item.yml rename core/modules/aggregator/src/Plugin/migrate/source/{d6 => }/AggregatorFeed.php (67%) rename core/modules/aggregator/src/Plugin/migrate/source/{d6 => }/AggregatorItem.php (72%) create mode 100644 core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorFeedTest.php create mode 100644 core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorItemTest.php rename core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/{d6 => }/AggregatorItemTest.php (53%) create mode 100644 core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d7/AggregatorFeedTest.php diff --git a/core/modules/aggregator/migration_templates/d6_aggregator_feed.yml b/core/modules/aggregator/migration_templates/d6_aggregator_feed.yml index 361f35caacdd..cad155374a86 100644 --- a/core/modules/aggregator/migration_templates/d6_aggregator_feed.yml +++ b/core/modules/aggregator/migration_templates/d6_aggregator_feed.yml @@ -3,7 +3,7 @@ label: Aggregator feeds migration_tags: - Drupal 6 source: - plugin: d6_aggregator_feed + plugin: aggregator_feed process: fid: fid title: title diff --git a/core/modules/aggregator/migration_templates/d6_aggregator_item.yml b/core/modules/aggregator/migration_templates/d6_aggregator_item.yml index 6698c22e87e1..fb4040ab1240 100644 --- a/core/modules/aggregator/migration_templates/d6_aggregator_item.yml +++ b/core/modules/aggregator/migration_templates/d6_aggregator_item.yml @@ -3,14 +3,13 @@ label: Aggregator items migration_tags: - Drupal 6 source: - plugin: d6_aggregator_item + plugin: aggregator_item process: iid: iid fid: plugin: migration migration: d6_aggregator_feed - source: - - fid + source: fid title: title link: link author: author diff --git a/core/modules/aggregator/migration_templates/d7_aggregator_feed.yml b/core/modules/aggregator/migration_templates/d7_aggregator_feed.yml new file mode 100644 index 000000000000..5dbeb25eaf40 --- /dev/null +++ b/core/modules/aggregator/migration_templates/d7_aggregator_feed.yml @@ -0,0 +1,20 @@ +id: d7_aggregator_feed +label: Aggregator feeds +migration_tags: + - Drupal 7 +source: + plugin: aggregator_feed +process: + fid: fid + title: title + url: url + refresh: refresh + checked: checked + queued: queued + link: link + description: description + image: image + etag: etag + modified: modified +destination: + plugin: entity:aggregator_feed diff --git a/core/modules/aggregator/migration_templates/d7_aggregator_item.yml b/core/modules/aggregator/migration_templates/d7_aggregator_item.yml new file mode 100644 index 000000000000..9735e19da21f --- /dev/null +++ b/core/modules/aggregator/migration_templates/d7_aggregator_item.yml @@ -0,0 +1,23 @@ +id: d7_aggregator_item +label: Aggregator items +migration_tags: + - Drupal 7 +source: + plugin: aggregator_item +process: + iid: iid + fid: + plugin: migration + migration: d7_aggregator_feed + source: fid + title: title + link: link + author: author + description: description + timestamp: timestamp + guid: guid +destination: + plugin: entity:aggregator_item +migration_dependencies: + required: + - d7_aggregator_feed diff --git a/core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorFeed.php b/core/modules/aggregator/src/Plugin/migrate/source/AggregatorFeed.php similarity index 67% rename from core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorFeed.php rename to core/modules/aggregator/src/Plugin/migrate/source/AggregatorFeed.php index 4428862679e5..9dce5e97bf52 100644 --- a/core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorFeed.php +++ b/core/modules/aggregator/src/Plugin/migrate/source/AggregatorFeed.php @@ -2,18 +2,18 @@ /** * @file - * Contains \Drupal\aggregator\Plugin\migrate\source\d6\AggregatorFeed. + * Contains \Drupal\aggregator\Plugin\migrate\source\AggregatorFeed. */ -namespace Drupal\aggregator\Plugin\migrate\source\d6; +namespace Drupal\aggregator\Plugin\migrate\source; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** - * Drupal 6 feed source from database. + * Drupal feed source from database. * * @MigrateSource( - * id = "d6_aggregator_feed", + * id = "aggregator_feed", * source_provider = "aggregator" * ) */ @@ -23,30 +23,15 @@ class AggregatorFeed extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - $query = $this->select('aggregator_feed', 'af') - ->fields('af', array( - 'fid', - 'title', - 'url', - 'refresh', - 'checked', - 'link', - 'description', - 'image', - 'etag', - 'modified', - 'block', - )); - - $query->orderBy('fid'); - return $query; + return $this->select('aggregator_feed', 'af') + ->fields('af'); } /** * {@inheritdoc} */ public function fields() { - return array( + $fields = array( 'fid' => $this->t('The feed ID.'), 'title' => $this->t('Title of the feed.'), 'url' => $this->t('URL to the feed.'), @@ -59,6 +44,10 @@ public function fields() { 'modified' => $this->t('When the feed was last modified.'), 'block' => $this->t("Number of items to display in the feed's block."), ); + if ($this->getModuleSchemaVersion('system') >= 7000) { + $fields['queued'] = $this->t('Time when this feed was queued for refresh, 0 if not queued.'); + } + return $fields; } /** diff --git a/core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorItem.php b/core/modules/aggregator/src/Plugin/migrate/source/AggregatorItem.php similarity index 72% rename from core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorItem.php rename to core/modules/aggregator/src/Plugin/migrate/source/AggregatorItem.php index 1c4677eae935..3f94ceb9c092 100644 --- a/core/modules/aggregator/src/Plugin/migrate/source/d6/AggregatorItem.php +++ b/core/modules/aggregator/src/Plugin/migrate/source/AggregatorItem.php @@ -2,18 +2,18 @@ /** * @file - * Contains \Drupal\aggregator\Plugin\migrate\source\d6\AggregatorItem. + * Contains \Drupal\aggregator\Plugin\migrate\source\AggregatorItem. */ -namespace Drupal\aggregator\Plugin\migrate\source\d6; +namespace Drupal\aggregator\Plugin\migrate\source; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** - * Drupal 6 aggregator item source from database. + * Drupal aggregator item source from database. * * @MigrateSource( - * id = "d6_aggregator_item", + * id = "aggregator_item", * source_provider = "aggregator" * ) */ @@ -23,11 +23,9 @@ class AggregatorItem extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - $query = $this->select('aggregator_item', 'ai') - ->fields('ai', array('iid', 'fid', 'title', 'link', 'author', - 'description', 'timestamp', 'guid')) + return $this->select('aggregator_item', 'ai') + ->fields('ai') ->orderBy('iid'); - return $query; } /** diff --git a/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorFeedTest.php b/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorFeedTest.php index bf3f516d8772..df33d870b915 100644 --- a/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorFeedTest.php +++ b/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorFeedTest.php @@ -11,7 +11,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; /** - * Upgrade variables to aggregator_feed entities. + * Tests migration of aggregator feeds. * * @group migrate_drupal_6 */ @@ -35,9 +35,8 @@ protected function setUp() { * Tests migration of aggregator feeds. */ public function testAggregatorFeedImport() { - /** @var Feed $feed */ + /** @var \Drupal\aggregator\Entity\Feed $feed */ $feed = Feed::load(5); - $this->assertNotNull($feed->uuid()); $this->assertIdentical('Know Your Meme', $feed->title->value); $this->assertIdentical('en', $feed->language()->getId()); $this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->url->value); diff --git a/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorItemTest.php b/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorItemTest.php index 662d57529000..90a964bd0cde 100644 --- a/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorItemTest.php +++ b/core/modules/aggregator/src/Tests/Migrate/d6/MigrateAggregatorItemTest.php @@ -11,7 +11,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; /** - * Upgrade aggregator items. + * Tests migration of aggregator items. * * @group migrate_drupal_6 */ @@ -36,7 +36,7 @@ protected function setUp() { * Test Drupal 6 aggregator item migration to Drupal 8. */ public function testAggregatorItem() { - /** @var Item $item */ + /** @var \Drupal\aggregator\Entity\Item $item */ $item = Item::load(1); $this->assertIdentical('1', $item->id()); $this->assertIdentical('5', $item->getFeedId()); diff --git a/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorFeedTest.php b/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorFeedTest.php new file mode 100644 index 000000000000..024d5ee22ffc --- /dev/null +++ b/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorFeedTest.php @@ -0,0 +1,50 @@ +<?php + +/** + * @file + * Contains \Drupal\aggregator\Tests\Migrate\d7\MigrateAggregatorFeedTest. + */ + +namespace Drupal\aggregator\Tests\Migrate\d7; + +use Drupal\aggregator\Entity\Feed; +use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; + +/** + * Test migration to aggregator_feed entities. + * + * @group aggregator + */ +class MigrateAggregatorFeedTest extends MigrateDrupal7TestBase { + + public static $modules = array('aggregator'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('aggregator_feed'); + $this->executeMigration('d7_aggregator_feed'); + } + + /** + * Tests migration of aggregator feeds. + */ + public function testAggregatorFeedImport() { + /** @var \Drupal\aggregator\Entity\Feed $feed */ + $feed = Feed::load(1); + $this->assertIdentical('Know Your Meme', $feed->title->value); + $this->assertIdentical('en', $feed->language()->getId()); + $this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->url->value); + $this->assertIdentical('900', $feed->refresh->value); + $this->assertIdentical('1387659487', $feed->checked->value); + $this->assertIdentical('0', $feed->queued->value); + $this->assertIdentical('http://knowyourmeme.com', $feed->link->value); + $this->assertIdentical('New items added to the News Feed', $feed->description->value); + $this->assertIdentical('http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png', $feed->image->value); + $this->assertIdentical('"213cc1365b96c310e92053c5551f0504"', $feed->etag->value); + $this->assertIdentical('0', $feed->modified->value); + } + +} diff --git a/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorItemTest.php b/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorItemTest.php new file mode 100644 index 000000000000..27b4b8cd99b1 --- /dev/null +++ b/core/modules/aggregator/src/Tests/Migrate/d7/MigrateAggregatorItemTest.php @@ -0,0 +1,50 @@ +<?php + +/** + * @file + * Contains \Drupal\aggregator\Tests\Migrate\d7\MigrateAggregatorItemTest. + */ + +namespace Drupal\aggregator\Tests\Migrate\d7; + +use Drupal\aggregator\Entity\Item; +use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; + +/** + * Tests migration of aggregator items. + * + * @group aggregator + */ +class MigrateAggregatorItemTest extends MigrateDrupal7TestBase { + + public static $modules = array('aggregator'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('aggregator_feed'); + $this->installEntitySchema('aggregator_item'); + $this->executeMigration('d7_aggregator_feed'); + $this->executeMigration('d7_aggregator_item'); + } + + /** + * Test Drupal 7 aggregator item migration to Drupal 8. + */ + public function testAggregatorItem() { + /** @var \Drupal\aggregator\Entity\Item $item */ + $item = Item::load(1); + $this->assertIdentical('1', $item->id()); + $this->assertIdentical('1', $item->getFeedId()); + $this->assertIdentical('This (three) weeks in Drupal Core - January 10th 2014', $item->label()); + $this->assertIdentical('larowlan', $item->getAuthor()); + $this->assertIdentical("<h2 id='new'>What's new with Drupal 8?</h2>", $item->getDescription()); + $this->assertIdentical('https://groups.drupal.org/node/395218', $item->getLink()); + $this->assertIdentical('1389297196', $item->getPostedTime()); + $this->assertIdentical('en', $item->language()->getId()); + $this->assertIdentical('395218 at https://groups.drupal.org', $item->getGuid()); + } + +} diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorItemTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/AggregatorItemTest.php similarity index 53% rename from core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorItemTest.php rename to core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/AggregatorItemTest.php index 3db03598b408..7127e417dc81 100644 --- a/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorItemTest.php +++ b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/AggregatorItemTest.php @@ -2,28 +2,26 @@ /** * @file - * Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d6\AggregatorItemTest. + * Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\AggregatorItemTest. */ -namespace Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d6; +namespace Drupal\Tests\aggregator\Unit\Plugin\migrate\source; use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; /** - * Tests D6 aggregator item source plugin. + * Tests aggregator item source plugin. * * @group aggregator */ class AggregatorItemTest extends MigrateSqlSourceTestCase { - const PLUGIN_CLASS = 'Drupal\aggregator\Plugin\migrate\source\d6\AggregatorItem'; + const PLUGIN_CLASS = 'Drupal\aggregator\Plugin\migrate\source\AggregatorItem'; - // The fake Migration configuration entity. protected $migrationConfiguration = array( - // The ID of the entity, can be any string. 'id' => 'test', 'source' => array( - 'plugin' => 'd6_aggregator_item', + 'plugin' => 'aggregator_item', ), ); @@ -40,16 +38,12 @@ class AggregatorItemTest extends MigrateSqlSourceTestCase { ), ); - protected $databaseContents = array('aggregator_item' => array(array( - 'iid' => 1, - 'fid' => 1, - 'title' => 'This (three) weeks in Drupal Core - January 10th 2014', - 'link' => 'https://groups.drupal.org/node/395218', - 'author' => 'larowlan', - 'description' => "<h2 id='new'>What's new with Drupal 8?</h2>", - 'timestamp' => 1389297196, - 'guid' => '395218 at https://groups.drupal.org', - ), - )); + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['aggregator_item'] = $this->expectedResults; + parent::setUp(); + } } diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorFeedTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorFeedTest.php index 8dc00847864e..569c5a998d36 100644 --- a/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorFeedTest.php +++ b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d6/AggregatorFeedTest.php @@ -16,7 +16,7 @@ */ class AggregatorFeedTest extends MigrateSqlSourceTestCase { - const PLUGIN_CLASS = 'Drupal\aggregator\Plugin\migrate\source\d6\AggregatorFeed'; + const PLUGIN_CLASS = 'Drupal\aggregator\Plugin\migrate\source\AggregatorFeed'; protected $migrationConfiguration = array( 'id' => 'test', @@ -58,9 +58,7 @@ class AggregatorFeedTest extends MigrateSqlSourceTestCase { * {@inheritdoc} */ protected function setUp() { - foreach ($this->expectedResults as $k => $row) { - $this->databaseContents['aggregator_feed'][$k] = $row; - } + $this->databaseContents['aggregator_feed'] = $this->expectedResults; parent::setUp(); } diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d7/AggregatorFeedTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d7/AggregatorFeedTest.php new file mode 100644 index 000000000000..b6445219fc0b --- /dev/null +++ b/core/modules/aggregator/tests/src/Unit/Plugin/migrate/source/d7/AggregatorFeedTest.php @@ -0,0 +1,67 @@ +<?php + +/** + * @file + * Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d7\AggregatorFeedTest. + */ + +namespace Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d7; + +use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; + +/** + * Tests D7 aggregator feed source plugin. + * + * @group aggregator + */ +class AggregatorFeedTest extends MigrateSqlSourceTestCase { + + const PLUGIN_CLASS = 'Drupal\aggregator\Plugin\migrate\source\AggregatorFeed'; + + protected $migrationConfiguration = array( + 'id' => 'test', + 'source' => array( + 'plugin' => 'd7_aggregator_feed', + ), + ); + + protected $expectedResults = array( + array( + 'fid' => 1, + 'title' => 'feed title 1', + 'url' => 'http://example.com/feed.rss', + 'refresh' => 900, + 'checked' => 0, + 'queued' => 0, + 'link' => 'http://example.com', + 'description' => 'A vague description', + 'image' => '', + 'etag' => '', + 'modified' => 0, + 'block' => 5, + ), + array( + 'fid' => 2, + 'title' => 'feed title 2', + 'url' => 'http://example.net/news.rss', + 'refresh' => 1800, + 'checked' => 0, + 'queued' => 0, + 'link' => 'http://example.net', + 'description' => 'An even more vague description', + 'image' => '', + 'etag' => '', + 'modified' => 0, + 'block' => 5, + ), + ); + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['aggregator_feed'] = $this->expectedResults; + parent::setUp(); + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorFeed.php b/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorFeed.php index d337e7be07fe..593c1bcd9171 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorFeed.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorFeed.php @@ -116,8 +116,22 @@ public function load() { 'modified', 'block', )) - ->execute(); + ->values(array( + 'fid' => '1', + 'title' => 'Know Your Meme', + 'url' => 'http://knowyourmeme.com/newsfeed.rss', + 'refresh' => '900', + 'checked' => '1387659487', + 'queued' => '0', + 'link' => 'http://knowyourmeme.com', + 'description' => 'New items added to the News Feed', + 'image' => 'http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png', + 'hash' => '1c1e3b6c10ce02f226882aca11709051bba61df2b8eac17ceec5bf74048f1954', + 'etag' => '"213cc1365b96c310e92053c5551f0504"', + 'modified' => '0', + 'block' => '5', + ))->execute(); } } -#8e8447ae5f187d54c5849399ea7f0983 +#82e906f4d10bd7d1d4bab524e946df94 diff --git a/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorItem.php b/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorItem.php index b694da8d2cbe..9b976c290000 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorItem.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d7/AggregatorItem.php @@ -81,8 +81,17 @@ public function load() { 'timestamp', 'guid', )) - ->execute(); + ->values(array( + 'iid' => '1', + 'fid' => '1', + 'title' => 'This (three) weeks in Drupal Core - January 10th 2014', + 'link' => 'https://groups.drupal.org/node/395218', + 'author' => 'larowlan', + 'description' => "<h2 id='new'>What's new with Drupal 8?</h2>", + 'timestamp' => '1389297196', + 'guid' => '395218 at https://groups.drupal.org', + ))->execute(); } } -#45d66c3443a69e4c2180a0d653725d10 +#256de8124e809501854169d85111cd21 -- GitLab