diff --git a/core/modules/book/migration_templates/d6_book.yml b/core/modules/book/migration_templates/d6_book.yml index dca43b1..4150094 100644 --- a/core/modules/book/migration_templates/d6_book.yml +++ b/core/modules/book/migration_templates/d6_book.yml @@ -3,7 +3,7 @@ label: Books migration_tags: - Drupal 6 source: - plugin: d6_book + plugin: book process: nid: nid 'book/bid': bid @@ -21,3 +21,4 @@ destination: migration_dependencies: required: - d6_node:* + - d6_menu_links diff --git a/core/modules/book/migration_templates/d7_book.yml b/core/modules/book/migration_templates/d7_book.yml new file mode 100644 index 0000000..80f616e --- /dev/null +++ b/core/modules/book/migration_templates/d7_book.yml @@ -0,0 +1,24 @@ +id: d7_book +label: Books +migration_tags: + - Drupal 7 +source: + plugin: book +process: + nid: nid + 'book/bid': bid + 'book/weight': weight + 'book/pid': + - + plugin: skip_on_empty + method: process + source: plid + - + plugin: migration + migration: d7_book +destination: + plugin: book +migration_dependencies: + required: + - d7_node:* + - d7_menu_links diff --git a/core/modules/book/migration_templates/d7_book_settings.yml b/core/modules/book/migration_templates/d7_book_settings.yml new file mode 100644 index 0000000..ca45fd1 --- /dev/null +++ b/core/modules/book/migration_templates/d7_book_settings.yml @@ -0,0 +1,17 @@ +id: d7_book_settings +label: Drupal 7 book configuration +migration_tags: + - Drupal 7 +source: + plugin: variable + variables: + - book_child_type + - book_block_mode + - book_allowed_types +process: + child_type: book_child_type + 'block/navigation/mode': book_block_mode + allowed_types: book_allowed_types +destination: + plugin: config + config_name: book.settings diff --git a/core/modules/book/src/Plugin/migrate/source/Book.php b/core/modules/book/src/Plugin/migrate/source/Book.php new file mode 100644 index 0000000..71554d4 --- /dev/null +++ b/core/modules/book/src/Plugin/migrate/source/Book.php @@ -0,0 +1,69 @@ +select('book', 'b')->fields('b', array('nid', 'bid')); + $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); + $ml_fields = array('mlid', 'plid', 'weight', 'has_children', 'depth'); + for ($i = 1; $i <= 9; $i++) { + $field = "p$i"; + $ml_fields[] = $field; + $query->orderBy($field); + } + $query->fields('ml', $ml_fields); + return $query; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['mlid']['type'] = 'integer'; + $ids['mlid']['alias'] = 'ml'; + return $ids; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'nid' => $this->t('Node ID'), + 'bid' => $this->t('Book ID'), + 'mlid' => $this->t('Menu link ID'), + 'plid' => $this->t('Parent link ID'), + 'weight' => $this->t('Weight'), + 'p1' => $this->t('The first mlid in the materialized path.'), + 'p2' => $this->t('The second mlid in the materialized path.'), + 'p3' => $this->t('The third mlid in the materialized path.'), + 'p4' => $this->t('The fourth mlid in the materialized path.'), + 'p5' => $this->t('The fifth mlid in the materialized path.'), + 'p6' => $this->t('The sixth mlid in the materialized path.'), + 'p7' => $this->t('The seventh mlid in the materialized path.'), + 'p8' => $this->t('The eight mlid in the materialized path.'), + 'p9' => $this->t('The nine mlid in the materialized path.'), + ); + } + +} diff --git a/core/modules/book/src/Plugin/migrate/source/d6/Book.php b/core/modules/book/src/Plugin/migrate/source/d6/Book.php deleted file mode 100644 index a1ecbb6..0000000 --- a/core/modules/book/src/Plugin/migrate/source/d6/Book.php +++ /dev/null @@ -1,68 +0,0 @@ -select('book', 'b')->fields('b', array('nid', 'bid')); - $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); - $ml_fields = array('mlid', 'plid', 'weight', 'has_children', 'depth'); - for ($i = 1; $i <= 9; $i++) { - $field = "p$i"; - $ml_fields[] = $field; - $query->orderBy($field); - } - $query->fields('ml', $ml_fields); - return $query; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['mlid']['type'] = 'integer'; - $ids['mlid']['alias'] = 'ml'; - return $ids; - } - - /** - * {@inheritdoc} - */ - public function fields() { - return array( - 'nid' => $this->t('Node ID'), - 'bid' => $this->t('Book ID'), - 'mlid' => $this->t('Menu link ID'), - 'plid' => $this->t('Parent link ID'), - 'weight' => $this->t('Weight'), - 'p1' => $this->t('The first mlid in the materialized path.'), - 'p2' => $this->t('The second mlid in the materialized path.'), - 'p3' => $this->t('The third mlid in the materialized path.'), - 'p4' => $this->t('The fourth mlid in the materialized path.'), - 'p5' => $this->t('The fifth mlid in the materialized path.'), - 'p6' => $this->t('The sixth mlid in the materialized path.'), - 'p7' => $this->t('The seventh mlid in the materialized path.'), - 'p8' => $this->t('The eight mlid in the materialized path.'), - 'p9' => $this->t('The nine mlid in the materialized path.'), - ); - } - -} diff --git a/core/modules/book/src/Tests/Migrate/d7/MigrateBookConfigsTest.php b/core/modules/book/src/Tests/Migrate/d7/MigrateBookConfigsTest.php new file mode 100644 index 0000000..71043c6 --- /dev/null +++ b/core/modules/book/src/Tests/Migrate/d7/MigrateBookConfigsTest.php @@ -0,0 +1,56 @@ +installConfig(self::$modules); + $migration = entity_load('migration', 'd7_book_settings'); + $dumps = array( + $this->getDumpDirectory() . '/Variable.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests migration of book variables to book.settings.yml. + */ + public function testBookSettings() { + $config = $this->config('book.settings'); + $this->assertIdentical('book', $config->get('child_type')); + $this->assertIdentical('all pages', $config->get('block.navigation.mode')); + $this->assertIdentical(array('book'), $config->get('allowed_types')); + $this->assertConfigSchema(\Drupal::service('config.typed'), 'book.settings', $config->get()); + } + +} diff --git a/core/modules/book/src/Tests/Migrate/d7/MigrateBookTest.php b/core/modules/book/src/Tests/Migrate/d7/MigrateBookTest.php new file mode 100644 index 0000000..69cdc5c --- /dev/null +++ b/core/modules/book/src/Tests/Migrate/d7/MigrateBookTest.php @@ -0,0 +1,69 @@ +installSchema('book', ['book']); + $this->installSchema('node', ['node_access']); + // @TODO: get this in D7 MigrateDrupal7TestBase + //$this->migrateContent(); + $this->executeMigration('d6_book'); + } + + /** + * + * @TODO: update for D7 + * + * Tests the Drupal 6 book structure to Drupal 8 migration. + */ + public function testBook() { + $nodes = Node::loadMultiple(array(4, 5, 6, 7, 8)); + $this->assertIdentical('4', $nodes[4]->book['bid']); + $this->assertIdentical('0', $nodes[4]->book['pid']); + + $this->assertIdentical('4', $nodes[5]->book['bid']); + $this->assertIdentical('4', $nodes[5]->book['pid']); + + $this->assertIdentical('4', $nodes[6]->book['bid']); + $this->assertIdentical('5', $nodes[6]->book['pid']); + + $this->assertIdentical('4', $nodes[7]->book['bid']); + $this->assertIdentical('5', $nodes[7]->book['pid']); + + $this->assertIdentical('8', $nodes[8]->book['bid']); + $this->assertIdentical('0', $nodes[8]->book['pid']); + + $tree = \Drupal::service('book.manager')->bookTreeAllData(4); + $this->assertIdentical('4', $tree['49990 Node 4 4']['link']['nid']); + $this->assertIdentical('5', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['link']['nid']); + $this->assertIdentical('6', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['link']['nid']); + $this->assertIdentical('7', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['link']['nid']); + $this->assertIdentical(array(), $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['below']); + $this->assertIdentical(array(), $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['below']); + } + +} diff --git a/core/modules/book/tests/src/Unit/Plugin/migrate/source/BookTest.php b/core/modules/book/tests/src/Unit/Plugin/migrate/source/BookTest.php new file mode 100644 index 0000000..0f690cb --- /dev/null +++ b/core/modules/book/tests/src/Unit/Plugin/migrate/source/BookTest.php @@ -0,0 +1,91 @@ + 'test', + 'source' => array( + 'plugin' => 'book', + ), + ); + + protected $expectedResults = array( + array( + 'nid' => '4', + 'bid' => '4', + 'mlid' => '1', + 'plid' => '0', + 'weight' => '-10', + 'p1' => '1', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + ), + ); + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['book'] = array( + array( + 'mlid' => '1', + 'nid' => '4', + 'bid' => '4', + ), + ); + $this->databaseContents['menu_links'] = array( + array( + 'menu_name' => 'book-toc-1', + 'mlid' => '1', + 'plid' => '0', + 'link_path' => 'node/4', + 'router_path' => 'node/%', + 'link_title' => 'Test top book title', + 'options' => 'a:0:{}', + 'module' => 'book', + 'hidden' => '0', + 'external' => '0', + 'has_children' => '1', + 'expanded' => '0', + 'weight' => '-10', + 'depth' => '1', + 'customized' => '0', + 'p1' => '1', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + ), + ); + parent::setUp(); + } + +} diff --git a/core/modules/book/tests/src/Unit/Plugin/migrate/source/d6/BookTest.php b/core/modules/book/tests/src/Unit/Plugin/migrate/source/d6/BookTest.php deleted file mode 100644 index ffd98e1..0000000 --- a/core/modules/book/tests/src/Unit/Plugin/migrate/source/d6/BookTest.php +++ /dev/null @@ -1,90 +0,0 @@ - 'test', - 'source' => array( - 'plugin' => 'd6_book', - ), - ); - - protected $expectedResults = array( - array( - 'nid' => '4', - 'bid' => '4', - 'mlid' => '1', - 'plid' => '0', - 'weight' => '-10', - 'p1' => '1', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - ), - ); - - /** - * {@inheritdoc} - */ - protected function setUp() { - $this->databaseContents['book'] = array( - array( - 'mlid' => '1', - 'nid' => '4', - 'bid' => '4', - ), - ); - $this->databaseContents['menu_links'] = array( - array( - 'menu_name' => 'book-toc-1', - 'mlid' => '1', - 'plid' => '0', - 'link_path' => 'node/4', - 'router_path' => 'node/%', - 'link_title' => 'Test top book title', - 'options' => 'a:0:{}', - 'module' => 'book', - 'hidden' => '0', - 'external' => '0', - 'has_children' => '1', - 'expanded' => '0', - 'weight' => '-10', - 'depth' => '1', - 'customized' => '0', - 'p1' => '1', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - ), - ); - parent::setUp(); - } - -}