diff -u b/core/modules/shortcut/migration_templates/d7_shortcut.yml b/core/modules/shortcut/migration_templates/d7_shortcut.yml --- b/core/modules/shortcut/migration_templates/d7_shortcut.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut.yml @@ -1,5 +1,5 @@ id: d7_shortcut -label: Drupal 7 shortcut links +label: Shortcut links migration_tags: - Drupal 7 source: @@ -8,16 +8,9 @@ uri_scheme: 'internal:/' process: shortcut_set: - - - plugin: migration - migration: d7_shortcut_set - source: - - menu_name - - - plugin: extract - field: shortcut_set - index: - - 0 + plugin: migration + migration: d7_shortcut_set + source: menu_name title: link_title weight: weight link: diff -u b/core/modules/shortcut/migration_templates/d7_shortcut_set.yml b/core/modules/shortcut/migration_templates/d7_shortcut_set.yml --- b/core/modules/shortcut/migration_templates/d7_shortcut_set.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut_set.yml @@ -1,5 +1,5 @@ id: d7_shortcut_set -label: Drupal 7 shortcut sets +label: Shortcut sets migration_tags: - Drupal 7 source: diff -u b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml --- b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml @@ -1,5 +1,5 @@ id: d7_shortcut_set_users -label: Drupal 7 Shortcut set user mapping +label: Shortcut set user mapping migration_tags: - Drupal 7 source: @@ -9,27 +9,14 @@ - plugin: migration migration: d7_user - source: - - uid + source: uid - - plugin: default_value - default_value: [1] - - - plugin: extract - field: uid - index: - - 0 + plugin: skip_on_empty + method: row set_name: - - - plugin: migration - migration: d7_shortcut_set - source: - - set_name - - - plugin: extract - field: set_name - index: - - 0 + plugin: migration + migration: d7_shortcut_set + source: set_name destination: plugin: shortcut_set_users migration_dependencies: diff -u b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php --- b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php +++ b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php @@ -8,8 +8,6 @@ namespace Drupal\shortcut\Plugin\migrate\destination; use Drupal\shortcut\ShortcutSetStorageInterface; -use Drupal\shortcut\ShortcutSetInterface; -use Drupal\Core\Database\Connection; use Drupal\user\Entity\User; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Row; @@ -25,14 +23,7 @@ class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPluginInterface { /** - * Active database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $database; - - /** - * The shortcut_set storage. + * The shortcut set storage handler. * * @var \Drupal\shortcut\ShortcutSetStorageInterface */ @@ -49,14 +40,11 @@ * The plugin implementation definition. * @param MigrationInterface $migration * The migration. - * @param \Drupal\Core\Database\Connection $database - * The database connection. * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage - * The shortcut_set entity storage class. + * The shortcut_set entity storage handler. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Connection $database, ShortcutSetStorageInterface $shortcut_set_storage) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ShortcutSetStorageInterface $shortcut_set_storage) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); - $this->database = $database; $this->shortcutSetStorage = $shortcut_set_storage; } @@ -69,7 +57,6 @@ $plugin_id, $plugin_definition, $migration, - $container->get('database'), $container->get('entity.manager')->getStorage('shortcut_set') ); } @@ -78,8 +65,14 @@ * {@inheritdoc} */ public function getIds() { - $ids['uid']['type'] = 'integer'; - return $ids; + return array( + 'set_name' => array( + 'type' => 'string', + ), + 'uid' => array( + 'type' => 'integer', + ), + ); } /** @@ -98,11 +91,11 @@ public function import(Row $row, array $old_destination_id_values = array()) { + /** @var \Drupal\shortcut\ShortcutSetInterface $set */ $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name')); - if ($set) { - $account = User::load($row->getDestinationProperty('uid')); - if ($account) { - $this->shortcutSetStorage->assignUser($set, $account); - } - } - return array($account->id()); + /** @var \Drupal\user\UserInterface $account */ + $account = User::load($row->getDestinationProperty('uid')); + $this->shortcutSetStorage->assignUser($set, $account); + + return array($set->id(), $account->id()); } + } diff -u b/core/modules/shortcut/src/Plugin/migrate/source/d7/Shortcut.php b/core/modules/shortcut/src/Plugin/migrate/source/d7/Shortcut.php --- b/core/modules/shortcut/src/Plugin/migrate/source/d7/Shortcut.php +++ b/core/modules/shortcut/src/Plugin/migrate/source/d7/Shortcut.php @@ -17,6 +17,7 @@ * ) */ class Shortcut extends DrupalSqlBase { + /** * {@inheritdoc} */ @@ -49,2 +50,3 @@ } + } diff -u b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php --- b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php +++ b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php @@ -17,12 +17,12 @@ * ) */ class ShortcutSet extends DrupalSqlBase { + /** * {@inheritdoc} */ public function query() { - return $this->select('shortcut_set', 'ss') - ->fields('ss', array('set_name', 'title')); + return $this->select('shortcut_set', 'ss')->fields('ss'); } /** @@ -44,2 +44,3 @@ } + } diff -u b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSetUsers.php b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSetUsers.php --- b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSetUsers.php +++ b/core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSetUsers.php @@ -17,12 +17,12 @@ * ) */ class ShortcutSetUsers extends DrupalSqlBase { + /** * {@inheritdoc} */ public function query() { - return $this->select('shortcut_set_users', 'ssu') - ->fields('ssu', array('uid', 'set_name')); + return $this->select('shortcut_set_users', 'ssu')->fields('ssu'); } /** @@ -41,5 +41,12 @@ public function getIds() { - $ids['uid']['type'] = 'integer'; - return $ids; + return array( + 'set_name' => array( + 'type' => 'string', + ), + 'uid' => array( + 'type' => 'integer', + ), + ); } + } diff -u b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php --- b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php +++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php @@ -7,8 +7,6 @@ namespace Drupal\shortcut\Tests\Migrate\d7; -use Drupal\shortcut\Entity\Shortcut; -use Drupal\shortcut\ShortcutInterface; use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\ShortcutSetInterface; use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; @@ -52,27 +50,28 @@ public function testShortcutSetMigration() { - // Check if 2 shortcut sets got migrated. - $shortcut_sets = ShortcutSet::loadMultiple(); - $this->assertIdentical(count($shortcut_sets), 2); - $this->assertEntity($shortcut_sets['default'], 'default', 'Default'); - $this->assertEntity($shortcut_sets['shortcut_set_2'], 'shortcut_set_2', 'Alternative shortcut set'); + $this->assertEntity('default', 'Default', 2); + $this->assertEntity('shortcut_set_2', 'Alternative shortcut set', 2); } /** * Asserts various aspects of a shortcut set entity. - * @param \Drupal\shortcut\Entity\ShortcutSet $shortcut_set - * The shortcut_set entity. + * * @param string $id - * The expected shortcut_set ID. + * The expected shortcut set ID. * @param string $label - * The expected shortcut_set label. + * The expected shortcut set label. + * @param int $expected_size + * The number of shortcuts expected to be in the set. */ - protected function assertEntity($shortcut_set, $id, $label) { + protected function assertEntity($id, $label, $expected_size) { + $shortcut_set = ShortcutSet::load($id); $this->assertTrue($shortcut_set instanceof ShortcutSetInterface); + /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */ $this->assertIdentical($id, $shortcut_set->id()); $this->assertIdentical($label, $shortcut_set->label()); - // Check if shortcut_set contains 2 migrated shortcuts + // Check the number of shortcuts in the set. $shortcuts = $shortcut_set->getShortcuts(); - $this->assertIdentical(count($shortcuts), 2); + $this->assertIdentical(count($shortcuts), $expected_size); } + } diff -u b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php --- b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php +++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php @@ -8,10 +8,6 @@ namespace Drupal\shortcut\Tests\Migrate\d7; use Drupal\user\Entity\User; -use Drupal\shortcut\Entity\Shortcut; -use Drupal\shortcut\ShortcutInterface; -use Drupal\shortcut\Entity\ShortcutSet; -use Drupal\shortcut\ShortcutSetInterface; use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; /** @@ -60,4 +56,6 @@ $shortcut_set = shortcut_current_displayed_set($account); + /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */ $this->assertIdentical('shortcut_set_2', $shortcut_set->id()); } + } diff -u b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php --- b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php +++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php @@ -47,34 +47,33 @@ /** + * Asserts various aspects of a shortcut entity. + * + * @param int $id + * The shortcut ID. + * @param string $title + * The expected title of the shortcut. + * @param int $weight + * The expected weight of the shortcut. + * @param string $url + * The expected URL of the shortcut. + */ + protected function assertEntity($id, $title, $weight, $url) { + $shortcut = Shortcut::load($id); + $this->assertTrue($shortcut instanceof ShortcutInterface); + /** @var \Drupal\shortcut\ShortcutInterface $shortcut */ + $this->assertIdentical($title, $shortcut->getTitle()); + $this->assertIdentical($weight, $shortcut->getWeight()); + $this->assertIdentical($url, $shortcut->getUrl()->toString()); + } + + /** * Test the shortcut migration. */ public function testShortcutMigration() { - // Check if 4 shortcuts got migrated. - $shortcuts = Shortcut::loadMultiple(); - $this->assertIdentical(count($shortcuts), 4); - // Check if the 4 shortcuts were migrated correctly. - $shortcut = $shortcuts[1]; - $this->assertTrue($shortcut instanceof ShortcutInterface); - $this->assertIdentical('Add content', $shortcut->getTitle()); - $this->assertIdentical('-20', $shortcut->getWeight()); - $this->assertIdentical('/node/add', $shortcut->getUrl()->toString()); - - $shortcut = $shortcuts[2]; - $this->assertTrue($shortcut instanceof ShortcutInterface); - $this->assertIdentical('Find content', $shortcut->getTitle()); - $this->assertIdentical('-19', $shortcut->getWeight()); - $this->assertIdentical('/admin/content', $shortcut->getUrl()->toString()); - - $shortcut = $shortcuts[3]; - $this->assertTrue($shortcut instanceof ShortcutInterface); - $this->assertIdentical('Help', $shortcut->getTitle()); - $this->assertIdentical('-49', $shortcut->getWeight()); - $this->assertIdentical('/admin/help', $shortcut->getUrl()->toString()); - - $shortcut = $shortcuts[4]; - $this->assertTrue($shortcut instanceof ShortcutInterface); - $this->assertIdentical('People', $shortcut->getTitle()); - $this->assertIdentical('-50', $shortcut->getWeight()); - $this->assertIdentical('/admin/people', $shortcut->getUrl()->toString()); + $this->assertEntity(1, 'Add content', '-20', '/node/add'); + $this->assertEntity(2, 'Find content', '-19', '/admin/content'); + $this->assertEntity(3, 'Help', '-49', '/admin/help'); + $this->assertEntity(4, 'People', '-50', '/admin/people'); } + } diff -u b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetTest.php b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetTest.php --- b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetTest.php +++ b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetTest.php @@ -18,12 +18,12 @@ const PLUGIN_CLASS = 'Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet'; - protected $migrationConfiguration = array( + protected $migrationConfiguration = [ 'id' => 'test', - 'source' => array( + 'source' => [ 'plugin' => 'd7_shortcut_set', - ), - ); + ], + ]; protected $expectedResults = [ [ @@ -38,9 +38,6 @@ protected function setUp() { - $this->databaseContents['shortcut_set'][] = array( - 'set_name' => 'shortcut-set-2', - 'title' => 'Alternative shortcut set', - ); - + $this->databaseContents['shortcut_set'] = $this->expectedResults; parent::setUp(); } + } diff -u b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetUsersTest.php b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetUsersTest.php --- b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetUsersTest.php +++ b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutSetUsersTest.php @@ -18,12 +18,12 @@ const PLUGIN_CLASS = 'Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSetUsers'; - protected $migrationConfiguration = array( + protected $migrationConfiguration = [ 'id' => 'test', - 'source' => array( + 'source' => [ 'plugin' => 'd7_shortcut_set_users', - ), - ); + ], + ]; protected $expectedResults = [ [ @@ -38,9 +38,6 @@ protected function setUp() { - $this->databaseContents['shortcut_set_users'][] = array( - 'uid' => '2', - 'set_name' => 'shortcut-set-2', - ); - + $this->databaseContents['shortcut_set_users'] = $this->expectedResults; parent::setUp(); } + } diff -u b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutTest.php b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutTest.php --- b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutTest.php +++ b/core/modules/shortcut/tests/src/Unit/Plugin/migrate/source/d7/ShortcutTest.php @@ -18,12 +18,12 @@ const PLUGIN_CLASS = 'Drupal\shortcut\Plugin\migrate\source\d7\Shortcut'; - protected $migrationConfiguration = array( + protected $migrationConfiguration = [ 'id' => 'test', - 'source' => array( + 'source' => [ 'plugin' => 'd7_shortcut', - ), - ); + ], + ]; protected $expectedResults = [ [ @@ -39,7 +39,7 @@ * {@inheritdoc} */ protected function setUp() { - $this->databaseContents['menu_links'][] = array( + $this->databaseContents['menu_links'][] = [ 'menu_name' => 'shortcut-set-2', 'mlid' => '473', 'plid' => '0', @@ -67,6 +67,7 @@ 'updated' => '0', - ); + ]; parent::setUp(); } + }