See also #2692247: Pre-existing 'forum' content type prevents forum module installation

Problem/Motivation

In a D8 site with the book module not installed:

  1. Manually create a node type with machine name "book". Or, perform a migration from a site with a "book" content type.
  2. Go to the Extend page and try to install the book module.
  3. "Unable to install Book, core.entity_form_display.node.book.default, core.entity_view_display.node.book.default, core.entity_view_display.node.book.teaser, field.field.node.book.body, node.type.book already exist in active configuration.">

Proposed resolution

Move all node and field configuration from config/install to config/optional.

Remaining tasks

Do it.

User interface changes

None.

API changes

None.

Data model changes

None.

Original report

I have a Drupal 7 installation, for which I'm exploring possibilities of migrating to Drupal8.

Of the many things, one that looks core to Drupal8 issue is the 'book' module. In drupal 7, I have a collection of pages organized as the book. After migration to Drupal8, only the 1st leaf of the book is displayed. The rest of the contents are not interlinked.

On looking at the modules page, I noticed that the 'book' module was not enabled. Trying to enabled it resulted in the following error:

Unable to install Book, core.entity_form_display.node.book.default, core.entity_view_display.node.book.default, core.entity_view_display.node.book.teaser, core.entity_view_mode.node.print, field.field.node.book.body, node.type.book already exist in active configuration.

Screenshot of error attached.

screenshot

Steps to reproduce

  1. Install drupal 7 and populate it with content organizing it as a book
  2. Migrate to Drupal 8 as has been documented
  3. Check basic website status by clicking on the book
  4. Check modules page. you may notice that 'book' module is inactive
  5. try activating it and you may get an error like i've mentioned in the screenshot.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

riteshsarraf created an issue. See original summary.

mikeryan’s picture

You must enable the book module *before* running the upgrade process for the book hierarchy info to be migrated. See Preparing an upgrade, "Enable required modules" section.

As for the consequences of not enabling the module first, the forum module has the same issue: #2692247: Pre-existing 'forum' content type prevents forum module installation.

riteshsarraf’s picture

Thank you very much for the info @mikeryan. I surely must have missed that paragraph tagged "Enable required Modules". I'll try this again this weekend on a fresh setup, and update this bug report accordingly.

riteshsarraf’s picture

I tried it again today.
As you advised, I enabled the 'Book' module prior to initiating the migration.

It did report seeing the 'Book' content. But the final presentation of the data in Drupal8 is not accordingly.

migrate_drupal_ui	04/30/2016 - 14:40	Upgraded Node revisions (Feed item) (processed 0 items…	Ritesh Raj Sarraf	
migrate_drupal_ui	04/30/2016 - 14:40	Upgraded Node revisions (Feed) (processed 0 items total)	Ritesh Raj Sarraf	
migrate_drupal_ui	04/30/2016 - 14:40	Upgraded Node revisions (Book page) (processed 37 items…	Ritesh Raj Sarraf	
migrate_drupal_ui	04/30/2016 - 14:40	Upgraded Node revisions (Blog entry) (processed 122…	Ritesh Raj Sarraf	
migrate_drupal_ui	04/30/2016 - 14:40	

screenshot

Even after I enabled the 'book' module in d8, at the migration page (screenshot) it reported it as missing. Is it to assume that the migrate module currently doesn't have an upgrade path for the 'Book' module's content ?

mediameriquat’s picture

I migrated a fairly simple D7 site to D8. The book module was properly activated on D8 before proceeding, but the migration of the book hierarchy failed.

I had to manually rebuild my books, after making sure all relevant content types can be included in admin/structure/book/settings. Of course, this would not have been a solution if I had dozens of books containing hundreds of pages.

riteshsarraf’s picture

@mediameriquat

THere is a bug with Drupal. It is referenced in this bug report.

But I wish they did a proper release than a half baked one. Bare features like migration of data generated from core modules break. :-(

mikeryan’s picture

Title: cannot enable book module » Pre-existing 'book' content type prevents book module installation
Version: 8.1.0 » 8.2.x-dev
Component: migration system » book.module
Issue summary: View changes

Updating the title/issue summary to reflect the current understanding and the corresponding fix we've made to the forum module: #2692247: Pre-existing 'forum' content type prevents forum module installation

mikeryan’s picture

Issue tags: +Novice

Marking as a novice task - if you follow the forum example, this should be straight-forward.

Peacog’s picture

I've made a patch for this, following the forum example.

riteshsarraf’s picture

Hello @Peacog,

So what happens next now?
I'm not versed with Drupal's process but we have a bug and we have a patch.

We need a review of the patch (presumably by someone from the Drupal core team?).
And currently the bug is marked as 'Unassigned'.

Peacog’s picture

Hi @riteshsarraf

Now we need a few people to use the patch and report back here whether it works or not, whether it passes coding standings, etc. If the patch seems OK eventually a core maintainer will review it and commit. It doesn't need to be assigned to anyone.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank you for your contribution!

One thing we could add here is some automated test to ensure the installation bug, as described in the issue is actually fixed.
So:

  1. Add a core/modules/book/src/Tests/BookInstallationTest.php
  2. Unlike core/modules/book/src/Tests/BookTest.php don't install the book module automatically
  3. Instead create a content type called book
  4. After that install the book module and ensure its actually possible
dawehner’s picture

double post

Peacog’s picture

I've added the test as suggested in #14. The tests-only patch will fail with a PreExistingConfigException exception, and the full patch should pass. I don't have much experience writing tests so I don't know if I need to output some kind of message when the test passes. If so, what's the best way to do that?

The last submitted patch, 15: drupal-check-existing-book-2714497-15-tests-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: drupal-check-existing-book-2714497-15.patch, failed testing.

Peacog’s picture

Status: Needs work » Needs review
FileSize
12.06 KB

Here's another go at the full patch. The tests-only patch from #15 is OK.

borisson_’s picture

The test-only patch shows the failure as expected but it crashes with an exception.

It can be

try {
  $this->container->get('module_installer')->install(['book']);
} catch (\Exception $e) {
  $this->fail("Can't install book module");
}

I also checked the patch for coding standards / documentation and I did find a couple of things to be improved.

  1. +++ b/core/modules/book/src/Tests/BookInstallTest.php
    @@ -0,0 +1,40 @@
    + * Test installation of Book module
    

    This needs a period at the end.

  2. +++ b/core/modules/book/src/Tests/BookInstallTest.php
    @@ -0,0 +1,40 @@
    +  /**
    +   * Modules to install.
    +   *
    +   * @var array
    +   */
    

    This should use {@inheritdoc} instead of the full description.

  3. +++ b/core/modules/book/src/Tests/BookInstallTest.php
    @@ -0,0 +1,40 @@
    +   * Tests that Book module can be installed if content type with machine name
    +   * 'book' already exists
    

    The first line of a docblock should be only 1 line of max 80 cols. So the comment should be rewritten.

  4. +++ b/core/modules/book/src/Tests/BookInstallTest.php
    @@ -0,0 +1,40 @@
    +    // Install the Book module
    

    This comment should also have a period at the end.

Peacog’s picture

Thanks for the review @borisson_.

I've fixed it so that the tests-only patch now catches the expected exception. As for coding standards:

1. Fixed
2. {@inheritdoc} is not needed because the comment refers to a variable declaration, not a method.
3. The first line of the docblock is already less than 80 characters so I've left that unchanged too.
4. Fixed

Peacog’s picture

The last submitted patch, 20: drupal-check-existing-book-2714497-20-tests-only.patch, failed testing.

mangy.fox’s picture

Patch #20 no longer applies cleanly, so re-rolled against current 8.3.x.

I also added a new summary for the install test, to comply with coding standards.

Sophie.SK’s picture

FileSize
90.39 KB

Patch applied locally and works perfectly.

Attached is a screenshot showing the module being successfully enabled (with existing Book content type and patch applied).

Sophie.SK’s picture

Status: Needs review » Reviewed & tested by the community

Whoops, forgot status update!

Sophie.SK’s picture

Issue tags: +mssprintjan17

  • catch committed c021387 on 8.3.x
    Issue #2714497 by Peacog, mangy.fox, riteshsarraf, Sophie.SK: Pre-...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.