0

I currently have a database with the following schema:

Table: Articles Columns: ID, Title, Author, Content

Table: Authors Columns: ID, AuthorName, EmailAddress

Table: Categories Columns: ID, CategoryName

I'm interested in moving this over to Drupal. I do NOT actually need to preserve the authors or categories tables because we are revamping those sections in the migration. However I DO need to save certain rows (or all, if easier) of the articles table. This includes keeping the author ID linked to it. I'm willing to do manual queries in order to select which rows I want to move over to the new table, but I'm not sure exactly where I should do this. So my question is: How can I move these articles over to Drupal in the easiest, most seamless fashion?

  • Is your Author a user? If so, do you have an email address for each author? – Triskelion Jul 17 '13 at 19:40
  • The authors (only 2 of them) have email addresses associated with them in the database. I'll edit the original post to include that, as I forgot to put it. – muttley91 Jul 17 '13 at 19:49
  • What do you mean by "is the author a user"? – muttley91 Jul 17 '13 at 19:49
  • I've yet to use it, but have heard great things about Migrate, maybe that would be the easiest? – Chris Rockwell Jul 17 '13 at 19:53
  • I'll give it a shot. I'd like to be able to get the articles imported in a format that would allow me to apply modules to them. The tool we tried already got the content in, but the way it did it does not allow us to apply modules (things like Colorbox) to previous articles. I may post another question regarding this. Thanks. – muttley91 Jul 17 '13 at 20:08
2

You can create nodes from external databases using the Feeds SQL module (requires Feeds). You should create a content type for the fields you want to import, and use the Feeds UI to select the external database table(s), add a query, and map the output to the fields in your content type.

Here are a couple of settings that you need:

Preparation: add your new source database to settings.php:

$databases = array (
  'default' =>
  array (
    'default' =>
    array (
      'database' => 'drupal_database',
      'username' => 'drupal',
      'password' => 'password',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
  'database_to_migrate' =>
  array (
    'default' =>
    array (
      'database' => 'database_to_migrate',
      'username' => 'migrateusername',
      'password' => 'password',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
)

Now: go to the Feeds UI, and start configuring:

1. Basic - attach to - your new content type
   Import on submission - checked

2. Fetcher - click "Change" -> select "SQL fetcher", save

3. SQL Fetcher - click "Change" - select your source database

4. Parser - click "Change" -> select "SQL Parser", save

5. SQL parser - click "Change" -> Enter your query, select your database, save
   Verify that your query performed as expected, results are displayed.

6. Processor - select "Node Processor" for nodes

7. Node Processor - Settings: Here, you can choose the content type (again), 
   the author associated with the new node, format, expiration, and other parameters.

8. Node Processor - mapping: Here, you have to map the fields from the sql query
   to the fields in your content type. After you save, you can map the next field

Since you only have a couple of users/authors, you could create accounts for them manually. In your SQL query, you can select the users as well as the content/title/etc., and the new articles will then be associated with the appropriate authors.

This has worked well for me with a limited number of nodes (<1000). For large-number of nodes, I ran into time-out issues, and had to add a limit to the SQL query. Eventually, I just created a drush script to add the nodes from the command line (I had to add >50,000 nodes).

Edited to add: I used this with Drupal 7. Please read the documentation for the modules for updated information: https://drupal.org/project/feeds, https://drupal.org/project/feeds_sql

  • I should only have around 200-300 articles to port over, so I shouldn't have issues there. Thanks! – muttley91 Jul 17 '13 at 20:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.