Product SiteDocumentation Site

Chapter 8. Import book into Drupal

8.1. How to build a CSV file for Drupal import
8.2. The publican.cfg file
8.3. Drupal Import Guide
8.3.1. How to add a menu block
8.3.2. Setting up Node import
8.3.3. How to import book
8.3.4. How to update book
Publican 3.1 has a new functionality which allow user to create and import a book into Drupal. All xml files in a book are transformed into a single CSV file which will later be used to import into Drupal.

8.1. How to build a CSV file for Drupal import

The CSV File consists of information that tells Drupal how to import the book. Each row in the CSV file represents a html page.
Use the $ publican build command to create the CSV file for Drupal import. Before running the command, use the cd command to change into the directory where your book is located. For example, if you have a book call "User_Guide" in your home directory, then run the following command.
$ cd User_Guide/
$ publican build --langs en-US --formats=drupal-book
After running the command, you will see CSV file is created in the tmp/en-US/drupal-book/ directory.
Publican stores all the output files in /tmp/en-US/drupal-book/ directory. This directory contains the following files:
  • CSV file - The naming convention of the file is $product-$version-$docname-$lang-$edition.csv
  • en-US directory - contains all the html images.
  • tar.gz file - the archive of both CSV file and en-US directory.

Important — Use version control system

After running the $ publican build --langs en-US --formats=drupal-book command, you will notice that the xml files in the en-US directory had been changed. This is because Publican added a 'Conformance' attribute for every xml tag that has id. This attribute contains a number which is unique across xml files in the book. If you are using a version control system like git for your xml files, then you need to commit the changes so that the number won't get reset when other users run it. These unique numbers are very important, because they are use as the url path in drupal. Besides, Publican also created a database file name max_unique_id.db in the en-US directory. This database file is use to track the current maximum unique number in the book, so that Publican can know where you are up to and add a new unique number for your newly created Chapter or Section. Therefore, it is very important to add the database file to the version control and commit it if there is any change. If you add a new section in the xml, don't set the 'Comformance' attribute yourself as that will make the database outdated. Just leave it for publican to set it.