ݺߣ

ݺߣShare a Scribd company logo
Tricky Migrations
Stephanie Leary   sillybean.net   @sleary
Who am I?
? sillybean.net

? @sleary

? slideshare.net/
  stephanieleary
Ive imported from...
? Blogger         ? Joomla

? Movable Type    ? Drupal

? Textpattern     ? Twitter

? LiveJournal     ? Gallery2

? WordPress.com   ? Delicious

? CSV files       ? HTML files
HTML Import
Tricky Migrations
Tricky Migrations
Tricky Migrations
Gallery2 Importer
Tricky Migrations
Tricky Migrations
Tricky Migrations
Tricky Migrations
Secrets of
Happy Importing
Preparation
? Back up
? Prepare to undo
? Import on development server
 ? Or turn on maintenance mode
? Turn off crossposting plugins
? Use absolute URLs for linked files
Plugins
? DB Backup
 http://wordpress.org/extend/plugins/wp-db-backup/

? Mass Page Remover
 http://wordpress.org/extend/plugins/mass-page-remover/

? WordPress Reset
 http://wordpress.org/extend/plugins/wordpress-reset/

? Maintenance Mode
 http://wordpress.org/extend/plugins/maintenance-mode/
WordPress export
? Posts, pages, comments, authors
? Uploads optional
? No settings
? No menus in 3.0 (fixed in 3.1)
? Category slug issues
? Custom post types and taxonomies
Uncommon imports
? Twitter
  http://wordpress.org/extend/plugins/twitter-importer/

? Delicious
  http://wordpress.org/extend/plugins/delicious-xml-importer/

? Gallery2
  http://wordpress.org/extend/plugins/gallery2-importer/

? HTML
  http://wordpress.org/extend/plugins/import-html-pages/
Uncommon imports
? Joomla/Mambo
 ?   1.0 to WP 2.7x: http://tinyurl.com/joom2wp

 ?   1.5 to WP 3.0x: http://wordpress.org/extend/plugins/
     joomla-15-importer/

? Drupal
 ?   6.x to WP 2.7x: http://tinyurl.com/dru6wp2

 ?   5.x to WP 2.7x: http://tinyurl.com/dru5wp2

? CSV
 http://wordpress.org/extend/plugins/csv-importer/
Custom imports
? Other MySQL-based CMSs
  http://yoast.com/importing-from-another-mysql-into-wordpress/
  http://codex.wordpress.org/Function_Reference/wp_insert_post/


1. Fetch data from old database
2. Build $post array
3. wp_insert_post ( $post );
while
($row = mysql_fetch_array($results,MYSQL_ASSOC)) {
    $post = array();
    $post[ 'post_status' ] = 'draft';
    $post[ 'post_author' ] = $row[ 'user' ];
    $post[ 'post_date' ] = $row[ 'date' ];
    $post[ 'post_title' ] = $row[ 'title' ];
    $post[ 'post_content' ] = $row[ 'content' ];
    wp_insert_post( $post );
}
Writing an import plugin
? Import class
? class Gallery2_Import extends WP_Importer
 ? form: greet()
 ? get posts: get_posts()
 ? clean up & insert: process_posts()
After importing
? Search & Replace
  http://wordpress.org/extend/plugins/search-and-replace/

? Redirection
  http://wordpress.org/extend/plugins/redirection/

? Add Linked Images to Gallery
  http://wordpress.org/extend/plugins/add-linked-images-
  to-gallery-v01/
Single Install
      
  Network
Second verse...
? Back up
? Prepare to undo
? Migrate on development server
XML or MySQL?
? XML pros         ? MySQL pros

 ? simple           ? complete

 ? limited          ? complicated

 ? slug bug         ? merging users

 ? skipped users    ? manual edits
Moving databases
? export all tables except
  users, usermeta
? change table prefixes
? change wp_userroles option
  name to match new table prefix
? change wp_* fields in wp_usermeta
  table to match prefix
Moving user tables
? Export users, usermeta
 ? or specific rows
? Manually change IDs
? Stab yourself in the eye with a fork


? http://sillybean.net/?p=6187
Compromise
? Use WordPress export to move
  content and taxonomies
? Have it create or map new users
? Move only the wp_options table
  by hand
Character sets
? define('DB_CHARSET', 'latin1');
? Try to convert the old db
 ? work with a copy!
 ? Alter the table
   http://codesnippets.joyent.com/posts/show/306

 ? Export Latin1, import UTF-8
   http://alexking.org/blog/2008/03/06/mysql-latin1-utf8-
   conversion
After migrating
? Move static files
? Change upload file paths
  http://yoursite.com/wp-content/
  http://yoursite.com/files/

 ? options
 ? posts
 ? theme files
Combining .htaccess
<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^one.foo.com$ [NC]

Redirect /forms.html http://one.foo.com/forms/   [R=301,NC]

RewriteCond %{HTTP_HOST} ^two.foo.com$ [NC]

Redirect /about.html http://two.foo.com/about/ [R=301,NC]

</IfModule>
?
Thank you.
     Stephanie Leary
     sillybean.net
     @sleary

More Related Content

Tricky Migrations

  • 1. Tricky Migrations Stephanie Leary sillybean.net @sleary
  • 2. Who am I? ? sillybean.net ? @sleary ? slideshare.net/ stephanieleary
  • 3. Ive imported from... ? Blogger ? Joomla ? Movable Type ? Drupal ? Textpattern ? Twitter ? LiveJournal ? Gallery2 ? WordPress.com ? Delicious ? CSV files ? HTML files
  • 14. Preparation ? Back up ? Prepare to undo ? Import on development server ? Or turn on maintenance mode ? Turn off crossposting plugins ? Use absolute URLs for linked files
  • 15. Plugins ? DB Backup http://wordpress.org/extend/plugins/wp-db-backup/ ? Mass Page Remover http://wordpress.org/extend/plugins/mass-page-remover/ ? WordPress Reset http://wordpress.org/extend/plugins/wordpress-reset/ ? Maintenance Mode http://wordpress.org/extend/plugins/maintenance-mode/
  • 16. WordPress export ? Posts, pages, comments, authors ? Uploads optional ? No settings ? No menus in 3.0 (fixed in 3.1) ? Category slug issues ? Custom post types and taxonomies
  • 17. Uncommon imports ? Twitter http://wordpress.org/extend/plugins/twitter-importer/ ? Delicious http://wordpress.org/extend/plugins/delicious-xml-importer/ ? Gallery2 http://wordpress.org/extend/plugins/gallery2-importer/ ? HTML http://wordpress.org/extend/plugins/import-html-pages/
  • 18. Uncommon imports ? Joomla/Mambo ? 1.0 to WP 2.7x: http://tinyurl.com/joom2wp ? 1.5 to WP 3.0x: http://wordpress.org/extend/plugins/ joomla-15-importer/ ? Drupal ? 6.x to WP 2.7x: http://tinyurl.com/dru6wp2 ? 5.x to WP 2.7x: http://tinyurl.com/dru5wp2 ? CSV http://wordpress.org/extend/plugins/csv-importer/
  • 19. Custom imports ? Other MySQL-based CMSs http://yoast.com/importing-from-another-mysql-into-wordpress/ http://codex.wordpress.org/Function_Reference/wp_insert_post/ 1. Fetch data from old database 2. Build $post array 3. wp_insert_post ( $post );
  • 20. while ($row = mysql_fetch_array($results,MYSQL_ASSOC)) { $post = array(); $post[ 'post_status' ] = 'draft'; $post[ 'post_author' ] = $row[ 'user' ]; $post[ 'post_date' ] = $row[ 'date' ]; $post[ 'post_title' ] = $row[ 'title' ]; $post[ 'post_content' ] = $row[ 'content' ]; wp_insert_post( $post ); }
  • 21. Writing an import plugin ? Import class ? class Gallery2_Import extends WP_Importer ? form: greet() ? get posts: get_posts() ? clean up & insert: process_posts()
  • 22. After importing ? Search & Replace http://wordpress.org/extend/plugins/search-and-replace/ ? Redirection http://wordpress.org/extend/plugins/redirection/ ? Add Linked Images to Gallery http://wordpress.org/extend/plugins/add-linked-images- to-gallery-v01/
  • 23. Single Install Network
  • 24. Second verse... ? Back up ? Prepare to undo ? Migrate on development server
  • 25. XML or MySQL? ? XML pros ? MySQL pros ? simple ? complete ? limited ? complicated ? slug bug ? merging users ? skipped users ? manual edits
  • 26. Moving databases ? export all tables except users, usermeta ? change table prefixes ? change wp_userroles option name to match new table prefix ? change wp_* fields in wp_usermeta table to match prefix
  • 27. Moving user tables ? Export users, usermeta ? or specific rows ? Manually change IDs ? Stab yourself in the eye with a fork ? http://sillybean.net/?p=6187
  • 28. Compromise ? Use WordPress export to move content and taxonomies ? Have it create or map new users ? Move only the wp_options table by hand
  • 29. Character sets ? define('DB_CHARSET', 'latin1'); ? Try to convert the old db ? work with a copy! ? Alter the table http://codesnippets.joyent.com/posts/show/306 ? Export Latin1, import UTF-8 http://alexking.org/blog/2008/03/06/mysql-latin1-utf8- conversion
  • 30. After migrating ? Move static files ? Change upload file paths http://yoursite.com/wp-content/ http://yoursite.com/files/ ? options ? posts ? theme files
  • 31. Combining .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^one.foo.com$ [NC] Redirect /forms.html http://one.foo.com/forms/ [R=301,NC] RewriteCond %{HTTP_HOST} ^two.foo.com$ [NC] Redirect /about.html http://two.foo.com/about/ [R=301,NC] </IfModule>
  • 32. ?
  • 33. Thank you. Stephanie Leary sillybean.net @sleary

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. I&amp;#x2019;m not going to talk much about the HTML import plugin because I&amp;#x2019;d like to get to some other things today, but you can come find me tonight if you want to know whether it&amp;#x2019;ll work in your situation.\n
  6. \n
  7. \n
  8. \n
  9. \n
  10. Some importers ask you to upload a file. Others ask for credentials so they can fetch data from an external API. This one asks for database connection info. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. The older Joomla and Drupal import scripts haven&amp;#x2019;t been updated to work with WordPress 3, so you&amp;#x2019;ll need to grab an older version from the release archive, do your import, then upgrade.\n
  19. \n
  20. \n
  21. These are the three main parts of any import script. You might also have functions to fetch authors, comments, and anything else you need to pull out of your old database. The dispatch() function displays greet() and then moves on to import(), which calls all the other functions in turn. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n