Download - Moving In: how to port your content from * to Drupal

Transcript
Page 1: Moving In: how to port your content from * to Drupal

Moving Inhow to port your content from * to drupal

emma jane hogbin

Page 2: Moving In: how to port your content from * to Drupal

the sock economythe sock economydrupal.org/user/1773drupal.org/user/1773

photo by: morten.dk

Page 3: Moving In: how to port your content from * to Drupal

there are three steps to success on (drupal) moving day...

Page 4: Moving In: how to port your content from * to Drupal

1. start with a1. start with afresh drupal installationfresh drupal installation

photo: julishannon

Page 5: Moving In: how to port your content from * to Drupal

2. be neat and tidy2. be neat and tidyto avoid disaster laterto avoid disaster later

photo by: bringo

Page 6: Moving In: how to port your content from * to Drupal

3. aim to have happy users3. aim to have happy usersat all stages of the moveat all stages of the move

photo by: waderockett

Page 7: Moving In: how to port your content from * to Drupal

What does it mean to move?1. Assessing the databases

2. The Export3. Preparing Drupal for the new content (CCK)

4. Import modules5. Importing content “by hand”

Page 8: Moving In: how to port your content from * to Drupal

1. Assessing the databases

Page 9: Moving In: how to port your content from * to Drupal

examine your database­ what is the db software?

­ is there a tool to export content?­ what formats can you export content to?

­ how is your content stored in the database?­ do you need to move user accounts as well?

Page 10: Moving In: how to port your content from * to Drupal

examine drupal’s db­ what content type(s) are you using?

­ what are the tables you need to place content into?

Page 11: Moving In: how to port your content from * to Drupal

`

Using MySQLCommand Line Magic

Page 12: Moving In: how to port your content from * to Drupal

Drupal 5 tables

Page 13: Moving In: how to port your content from * to Drupal

mysql> describe node;+­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­­­­­­­­­­+| Field    | Type             | Null | Key | Default | Extra          |+­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­­­­­­­­­­+| nid      | int(10) unsigned | NO   | PRI | NULL    | auto_increment | | vid      | int(10) unsigned | NO   | PRI | 0       |                | | type     | varchar(32)      | NO   | MUL |         |                | | title    | varchar(128)     | NO   | MUL |         |                | | uid      | int(11)          | NO   | MUL | 0       |                | | status   | int(11)          | NO   | MUL | 1       |                | | created  | int(11)          | NO   | MUL | 0       |                | | changed  | int(11)          | NO   | MUL | 0       |                | | comment  | int(11)          | NO   |     | 0       |                | | promote  | int(11)          | NO   | MUL | 0       |                | | moderate | int(11)          | NO   | MUL | 0       |                | | sticky   | int(11)          | NO   |     | 0       |                | +­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­­­­­­­­­­+12 rows in set (0.00 sec)

Page 14: Moving In: how to port your content from * to Drupal

mysql> describe node_revisions;+­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+| Field     | Type             | Null | Key | Default | Extra |+­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+| nid       | int(10) unsigned | NO   | MUL |         |       | | vid       | int(10) unsigned | NO   | PRI |         |       | | uid       | int(11)          | NO   | MUL | 0       |       | | title     | varchar(128)     | NO   |     |         |       | | body      | longtext         | NO   |     |         |       | | teaser    | longtext         | NO   |     |         |       | | log       | longtext         | NO   |     |         |       | | timestamp | int(11)          | NO   |     | 0       |       | | format    | int(11)          | NO   |     | 0       |       | +­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+9 rows in set (0.00 sec)

Page 15: Moving In: how to port your content from * to Drupal

plan your move!­ write yourself notes describing the process­ cross off the steps as you complete them

Page 16: Moving In: how to port your content from * to Drupal

2. Exporting useful data

Page 17: Moving In: how to port your content from * to Drupal

export tools ­ every database has its own export tool

­ if you are exporting from MySQL use mysqldump­ export to CSV where possible

(comma separated values)

Page 18: Moving In: how to port your content from * to Drupal

exporting content: the dumphttp://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

You can also use PHPMyAdmin if it’s installed!

MySQL to MySQLejhogbin@bilbo:~$ mysqldump ­u root ­p [dbname] \

> oldsite.sql

MySQL to CSV (local machine only)ejhogbin@bilbo:~$ mysqldump ­u root ­p

­­fields­terminated­by=,­­tab=[outputdirectory]­­tables [dbname] [tablename] > table.txt

Import into MySQLejhogbin@bilbo:~$ mysql ­u root ­p [newdatabase] \

< oldsite.sql

Page 19: Moving In: how to port your content from * to Drupal

3. Preparing Drupalfor the new content (CCK)

Page 20: Moving In: how to port your content from * to Drupal

Installing CCK­ modules (CCK, image, date, etc)

­ creating content types

Page 21: Moving In: how to port your content from * to Drupal

4. Import modules

Page 22: Moving In: how to port your content from * to Drupal

Drupal import toolshttp://drupal.org/project/Modules/category/64

­ html_import, node_import and user_import­ importing from WordPress? I used wp2drupal (4.7); try wordpress_import

Page 23: Moving In: how to port your content from * to Drupal

import_html­ modules: path, import_html­ in Ubuntu:  sudo apt­get install php5­xsl

(yes, even though it says XML support is enabled in the phpinfo() test file)­ review the settings (keep the defaults)­ copy the site to a local directory

(use wget to generate a flat site if necessary)­ proceed with the import­ set the path to the local directory where your static site lives­ check “more settings” to set the user and default settings for each node­ play with XSL template file if necessary (and you feel like an XML pro)­ click “next” and choose the files to import­ click import­ check for errors­ enjoy your imported content

Page 24: Moving In: how to port your content from * to Drupal

start page: import_html

Page 25: Moving In: how to port your content from * to Drupal

choose what to import

Page 26: Moving In: how to port your content from * to Drupal

choose the files to import

Page 27: Moving In: how to port your content from * to Drupal

success!(I’m actually overwriting the initial import on this second attempt.)

Page 28: Moving In: how to port your content from * to Drupal

node_import­ modules: node_import­ prepare your CSV file to import­ prepare your Drupal installation to receive the imported data­ proceed to: admin/content/node_import­ choose the CSV file that contains the data ­ choose your content type (e.g. page or story)­ match the data in your CSV file to data­ run the import ­ node_import runs on cron and may take

several hours for very large amounts of content

Page 29: Moving In: how to port your content from * to Drupal

upload your CSV file

Page 30: Moving In: how to port your content from * to Drupal

match data to drupal fields

Page 31: Moving In: how to port your content from * to Drupal

set node author

Page 32: Moving In: how to port your content from * to Drupal

user_import­ basically the same as node_import­ upload your CSV file and match fields onto drupal’s database­ user profile data must be uploaded separately into nodes

(ask me later, we’re probably running short on time)

Page 33: Moving In: how to port your content from * to Drupal

passwords: oh the headaches­ if you’re lucky they’re stored as plain text in the other db­ if they’re encrypted hopefully it’s with MySQL’s md5() function­ drupal stores passwords with the md5() mysql function­ back up the user table and convert passwords from plain text to md5()

mysql> create table users2 select * from users;mysql> update users2 set pass = md5(pass);

Page 34: Moving In: how to port your content from * to Drupal

5. Importing content “by hand”

Page 35: Moving In: how to port your content from * to Drupal

importing plain vanilla content1. import the data into temporary tables

2. using the insert/select command copy the data into node and node_revisions

3. update the sequences table to show the next nid

Page 36: Moving In: how to port your content from * to Drupal

importing CSV data

mysql > create table tmpdata(tmpid int, key1 int, key2 int);

mysql > load data local infile '/home/emmajane/data/data.csv'into table tmpdatafields terminated by ','optionally enclosed by '"'lines terminated by '\n'(tmpid, key1, key2);

Page 37: Moving In: how to port your content from * to Drupal

create “story” node stubs

mysql> insert ignorenode (nid, vid, uid, title, type)select tmpdata.nid, tmpdata.nid,tmpdata.uid, tmpdata.pagetitle,"story"

from tmpdata;

Page 38: Moving In: how to port your content from * to Drupal

mysql> insert ignorenode_revisions (nid, vid, uid, title,body, timestamp, format)

select tmpdata.nid, tmpdata.nid,tmpdata.uid, tmpdata.pagetitle,tmpdata.pagecontent,unix_timestamp(now()), 1

from tmpdata;

insert the body/description into node_revisions

Page 39: Moving In: how to port your content from * to Drupal

update sequences (v5)mysql> select nid from node

order by nid DESC limit 1;+­­­­­­­+| nid   |+­­­­­­­+| 18325 | +­­­­­­­+

mysql> update sequencesset id = 18325where name = “node_nid”;

mysql> update sequencesset id = 18325where name = “node_revisions_vid”;

Page 40: Moving In: how to port your content from * to Drupal

photo by: cromaphoto by: croma

SRSLY! Do not forget!Bad things happen when you

fail to update sequences.

Page 41: Moving In: how to port your content from * to Drupal

importing special content1. import the data into temporary tables

2. using the insert/select command copy the data into node and node_revisions

3. copy special content into CCK tables4. update the sequences table to show the next nid

Page 42: Moving In: how to port your content from * to Drupal

CCK content­ use Drupal to create CCK tables

­ examine the structure­ copy your content into the new tables

Page 43: Moving In: how to port your content from * to Drupal

cck tables

mysql> show tables;| content_type_ad                | | content_type_faq               | | content_type_forum             | | content_type_page              | | content_type_pattern           | | content_type_quotes            | | content_type_story             |  

Page 44: Moving In: how to port your content from * to Drupal

cck tables

mysql> describe content_type_pattern;+­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+| Field                     | Type             | Null | Key | Default | Extra |+­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+| vid                       | int(10) unsigned | NO   | PRI | 0       |       | | nid                       | int(10) unsigned | NO   |     | 0       |       | | field_byline_value        | longtext         | YES  |     | NULL    |       | | field_intro_value         | longtext         | YES  |     | NULL    |       | | field_intro_format        | int(10) unsigned | NO   |     | 0       |       | | field_materials_value     | longtext         | YES  |     | NULL    |       | | field_finished_size_value | longtext         | YES  |     | NULL    |       | | field_gauge_value         | longtext         | YES  |     | NULL    |       | | field_notes_value         | longtext         | YES  |     | NULL    |       | | field_notes_format        | int(10) unsigned | NO   |     | 0       |       | | field_contributor_nid_uid | int(11)          | YES  |     | NULL    |       | +­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­+­­­­­­­+

Page 45: Moving In: how to port your content from * to Drupal

Moving Content Summary1. Assess the situation and plan your move

2. Export content to a useful format3. Create the new home for your content

4. Use the import modules OR5. Importing content “by hand”