SlideShare a Scribd company logo
1 of 23
Ashok Modi (BTMash) – Drupal LA – March 2011 Migrating content to drupal – Migrate Module
Agenda Different Methods Steps to Work with Migrate Hooks Build a Class Description Source Adding Mapping Additional Data drush commands Q & A
Disclaimer Code Heavy! You may fall asleep. New territory! Talk about one *small* aspect of migration (migrating nodes) Not talking about creating own DestinationHandlers Possibly not talking about creating own FieldHandlers (depends on time) Can walk through an example migration that I did if preferred. Ask questions? It will make the presentation less terrible 
Possible method – by hand Should be accurate Get all files Mapping / everything works Time consuming Not feasible if you have a lot of content. Good way to test interns / punish coworkers (?)
Possible methods – Node Export Node Export (http://drupal.org/project/node_export) Has 7.x branch But no way to update content from 6.x -> 7.x No way to go back *easy* to set up (requires exact setup between source and destination in field names, etc)
Possible Methods - Feeds Really good method Map fields from source to destination Can import RSS / Atom / Various types of feeds Also flat files such as CSV Well documented Other than flat files, requires a feed source Might run into issues if content is updated in source *might be tricky in another cms*
Method demonstrated - Migrate Already defined many possible import sources XML, JSON, CSV, Databases (any currently supported by Drupal!) Can import many different types of content Users, Nodes, Comments, Taxonomy, Files … all core entities Can define your own import handler (not covered in presentation) Can define own method for importing custom fields Current already defined for all core field types Has support for Media Module importing Patch underway for getting date import Can define your own field handler (possibly not covered in presentation) Drush integration Rollback, Status Updates, Limited import. Caveat – Confusing documentation Only a status UI – all mapping must be done in code.
Assumptions made for presentation Migrating from a database Files directory for source are on same machine as the destination site directory
Steps to work with Migrate Let Migrate know about your module (1 hook!) Build a Migration Class Give it a description Let Migrate know what you’re getting content from. Let Migrate know about the type of content. Map the fields the migrate class it going to fill. (Optional) Massage / Add any fields you couldn’t get in the initial mapping (query).
Step 1: Hook Implement one hook – hook_migrate_api Provide the api version number (currently at version 2) That’s it! function mymodule_migrate_api() {   return array(     ‘api’ => 2,   ); }
Step 2: Build a Class Implement classes Class defines type of content that will be imported class NodeContentTypeMigration extends Migration { public function __construct() {   parent::__construct();   … } public function prepareRow($current_row) {   … } }
Step 2: Build a Class (functions inside) public function __construct() {…} Constructor for the class Allows migrate to know content type (user, node, tags) Where content is mapped from (db, csv, xml, etc) All the mappings coming in (fields) (optional)public function prepareRow($current_row) {…} Any extra data (things that cannot be pulled in a single query(?)) Massage any of the data that was pulled in (clean up text, clean up links, etc)
Step 2a: Create a description Create a description Class Description Any additional source fields (not found in initial query) Initial source -> destination mapping (what is the key in the source db?) $this->description = t(“Import all nodes of type PAGE”); Define Source Fields Fields that may not be getting pulled in via your query or in the flat file data but will be getting migrated somehow $source_fields = array(     'nid' => t('The node ID of the page'),     ’my_files' => t(’The set of files in a field for this node'), );
Off course: query source database Set up query (if need be, switch DBs using Database::getConnection) $query = Database::getConnection('for_migration', 'default'); Then write out rest of the query Alternatively, if source db is on same machine as destination db, use mysql db shortcut db_select(MY_MIGRATION_DATABASE_NAME .’.table_name’, ‘t’)
Step 2b: Call to grab data NOTE: This is only for migrations from databases Set up query (if need be, switch DBs using Database::getConnection) $query = db_select(MY_MIGRATION_DATABASE_NAME .'.node', 'n’) 	->fields('n', array('nid', 'vid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky', 'tnid', 'translate')) 	->condition('n.type', 'page', '=');     $query->join(MY_MIGRATION_DATABASE_NAME .'.node_revisions', 'nr', 'n.vid = nr.vid');     $query->addField('nr', 'body'); $query->addField('nr', 'teaser'); $query->join(MY_MIGRATION_DATABASE_NAME .'.users', 'u', 'n.uid = u.uid');     $query->addField('u', 'name');     $query->orderBy('n.changed');
Step 2b: Why the orderby? Migrate module has a feature called ‘highwater’ It is a key to designate and figure out if a piece of content needs to be updated rather than inserted. Means content can be updated! $this->highwaterField = array( 	'name' => 'changed',  	'alias' => 'n’, );
Step 2c: Mappings Add a ‘mapping’ (this is for tracking relationships between the rows from the source db and the rows that will come in the destination site) – essentially key of source DB.  $this->map = new MigrateSQLMap( 	$this->machineName,  	array(         		'nid' => array( 			'type' => 'int’, 			'unsigned' => TRUE,  			'not null' => TRUE, 			'description' => 'D6 Unique Node ID’, 			'alias' => 'n',  		) 	), 	MigrateDestinationNode::getKeySchema());
Step 2c: Mappings (cont’d) Now let the migrate module know what kind of mapping is being performed. $this->source = new MigrateSourceSQL($query, $source_fields); Along with the type of content $this->destination = new MigrateDestinationNode('page'); .
Step 2d: Map Fields Usually follows the form $this->addFieldMapping(‘destination_field_name’, ‘source_field_name’);  $this->addFieldMapping('revision_uid', 'uid'); Can provide default values  $this->addFieldMapping('pathauto_perform_alias')->defaultValue('1'); Can provide no value $this->addFieldMapping('path')->issueGroup(t('DNM')); Can provide arguments and separators for certain field types (body, file, etc require this methodology)
Step 3: Additional data / cleanup Optional public function prepareRow($current_row) Use it to add any additional data / cleanup any fields that were mapped in. // Get the correct uid based on username & set author id for node to uid $user_query = db_select('users', 'u’) 	->fields('u', array('uid'))     	->condition('u.name', $username, '=');   $results = $user_query->execute();   foreach ($results as $row) {     	$current_row->uid = $current_row->revision_uid = $row->uid; 	break; }
Drush Commands (the important ones) drush ms – List various migration import classes drush mi <importclass> - Import content drush mr <importclass> - Rollback content Options --idlist=id1,id2,… - Import content with specific IDs --itemlimit=n – Only import up to ‘n’ items --feedback=“n seconds” – Show status report every ‘n’ seconds --feedback=“n items” – Show status report every ‘n’ items
Resources http://drupal.org/project/migrate http://drupal.org/node/415260 Look at the example modules  http://drupal.org/project/migrate_extras http://drupal.org/project/wordpress_migrate http://cyrve.com/import (drush documentation)  http://goo.gl/3e1Jm(additional documentation to be added to core project) http://goo.gl/2qDLh (another example module)
Questions? Thank you 

More Related Content

What's hot

Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Scriptccherubino
 
Hive - SerDe and LazySerde
Hive - SerDe and LazySerdeHive - SerDe and LazySerde
Hive - SerDe and LazySerdeZheng Shao
 
Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startupsbmlever
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App EngineRyan Morlok
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeKonrad Malawski
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Rails 3 ActiveRecord
Rails 3 ActiveRecordRails 3 ActiveRecord
Rails 3 ActiveRecordBlazing Cloud
 
Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1ArangoDB Database
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
 
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...Cloudera, Inc.
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Barry DeCicco
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logsStefan Krawczyk
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String FunctionsAvanitrambadiya
 

What's hot (20)

Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Script
 
Hive - SerDe and LazySerde
Hive - SerDe and LazySerdeHive - SerDe and LazySerde
Hive - SerDe and LazySerde
 
Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startups
 
Scalding for Hadoop
Scalding for HadoopScalding for Hadoop
Scalding for Hadoop
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App Engine
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of code
 
Field api.From d7 to d8
Field api.From d7 to d8Field api.From d7 to d8
Field api.From d7 to d8
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
 
Rails 3 ActiveRecord
Rails 3 ActiveRecordRails 3 ActiveRecord
Rails 3 ActiveRecord
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1Rupy2012 ArangoDB Workshop Part1
Rupy2012 ArangoDB Workshop Part1
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logs
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 
Pig
PigPig
Pig
 

Viewers also liked

Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalRachel Jaro
 
Drupal 6 to 7 migration guide
Drupal 6 to 7 migration guideDrupal 6 to 7 migration guide
Drupal 6 to 7 migration guideEbizon
 
Drupalcampchicago2010.rachel.datamigration.
Drupalcampchicago2010.rachel.datamigration.Drupalcampchicago2010.rachel.datamigration.
Drupalcampchicago2010.rachel.datamigration.Promet Source
 
JIIT PORTAL based on Drupal
JIIT PORTAL based on DrupalJIIT PORTAL based on Drupal
JIIT PORTAL based on DrupalPrashant Saini
 
Drupal for Non-Developers
Drupal for Non-DevelopersDrupal for Non-Developers
Drupal for Non-DevelopersJeff Pompliano
 
Best Practices for Migrating a Legacy-Based CMS to Drupal
Best Practices for Migrating a Legacy-Based CMS to DrupalBest Practices for Migrating a Legacy-Based CMS to Drupal
Best Practices for Migrating a Legacy-Based CMS to DrupalAcquia
 
Cms an overview
Cms an overviewCms an overview
Cms an overviewkmusthu
 
Out With the Old, in With the Open-source: Brainshark's Complete CMS Migration
Out With the Old, in With the Open-source: Brainshark's Complete CMS MigrationOut With the Old, in With the Open-source: Brainshark's Complete CMS Migration
Out With the Old, in With the Open-source: Brainshark's Complete CMS MigrationAcquia
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksAcquia
 
Content migration - CSV to Drupal 8
Content migration -  CSV to Drupal 8Content migration -  CSV to Drupal 8
Content migration - CSV to Drupal 8Hector Iribarne
 
T44u 2015, content migration
T44u 2015, content migrationT44u 2015, content migration
T44u 2015, content migrationTerminalfour
 

Viewers also liked (14)

Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to Drupal
 
Drupal 6 to 7 migration guide
Drupal 6 to 7 migration guideDrupal 6 to 7 migration guide
Drupal 6 to 7 migration guide
 
Drupalcampchicago2010.rachel.datamigration.
Drupalcampchicago2010.rachel.datamigration.Drupalcampchicago2010.rachel.datamigration.
Drupalcampchicago2010.rachel.datamigration.
 
JIIT PORTAL based on Drupal
JIIT PORTAL based on DrupalJIIT PORTAL based on Drupal
JIIT PORTAL based on Drupal
 
Drupal for Non-Developers
Drupal for Non-DevelopersDrupal for Non-Developers
Drupal for Non-Developers
 
Cms
CmsCms
Cms
 
Best Practices for Migrating a Legacy-Based CMS to Drupal
Best Practices for Migrating a Legacy-Based CMS to DrupalBest Practices for Migrating a Legacy-Based CMS to Drupal
Best Practices for Migrating a Legacy-Based CMS to Drupal
 
Content Migration to Drupal 8
Content Migration to Drupal 8Content Migration to Drupal 8
Content Migration to Drupal 8
 
Cms an overview
Cms an overviewCms an overview
Cms an overview
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Out With the Old, in With the Open-source: Brainshark's Complete CMS Migration
Out With the Old, in With the Open-source: Brainshark's Complete CMS MigrationOut With the Old, in With the Open-source: Brainshark's Complete CMS Migration
Out With the Old, in With the Open-source: Brainshark's Complete CMS Migration
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
 
Content migration - CSV to Drupal 8
Content migration -  CSV to Drupal 8Content migration -  CSV to Drupal 8
Content migration - CSV to Drupal 8
 
T44u 2015, content migration
T44u 2015, content migrationT44u 2015, content migration
T44u 2015, content migration
 

Similar to Drupal content-migration

Compass Framework
Compass FrameworkCompass Framework
Compass FrameworkLukas Vlcek
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleJohan Gant
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
Data migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleData migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleSrijan Technologies
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeRick Copeland
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!OSCON Byrum
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardJAX London
 
Go Faster With Native Compilation
Go Faster With Native CompilationGo Faster With Native Compilation
Go Faster With Native CompilationPGConf APAC
 
Go faster with_native_compilation Part-2
Go faster with_native_compilation Part-2Go faster with_native_compilation Part-2
Go faster with_native_compilation Part-2Rajeev Rastogi (KRR)
 
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit Jain
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit JainApache Hadoop India Summit 2011 talk "Hive Evolution" by Namit Jain
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit JainYahoo Developer Network
 

Similar to Drupal content-migration (20)

Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate module
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
Data migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleData migration to Drupal using Migrate Module
Data migration to Drupal using Migrate Module
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForge
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Migrate
MigrateMigrate
Migrate
 
Hadoop ecosystem
Hadoop ecosystemHadoop ecosystem
Hadoop ecosystem
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Doctrine and NoSQL
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
 
Go Faster With Native Compilation
Go Faster With Native CompilationGo Faster With Native Compilation
Go Faster With Native Compilation
 
Go faster with_native_compilation Part-2
Go faster with_native_compilation Part-2Go faster with_native_compilation Part-2
Go faster with_native_compilation Part-2
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit Jain
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit JainApache Hadoop India Summit 2011 talk "Hive Evolution" by Namit Jain
Apache Hadoop India Summit 2011 talk "Hive Evolution" by Namit Jain
 
Hadoop ecosystem
Hadoop ecosystemHadoop ecosystem
Hadoop ecosystem
 

More from Ashok Modi

Drupal Camp LA 2011: Typography modules for Drupal
Drupal Camp LA 2011: Typography modules for DrupalDrupal Camp LA 2011: Typography modules for Drupal
Drupal Camp LA 2011: Typography modules for DrupalAshok Modi
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceAshok Modi
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingAshok Modi
 
CalArts presentation
CalArts presentationCalArts presentation
CalArts presentationAshok Modi
 
Drupal Camp LA 2010: Moderating Content in Drupal
Drupal Camp LA 2010: Moderating Content in DrupalDrupal Camp LA 2010: Moderating Content in Drupal
Drupal Camp LA 2010: Moderating Content in DrupalAshok Modi
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityAshok Modi
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityAshok Modi
 
Zimmertwins Presentation
Zimmertwins PresentationZimmertwins Presentation
Zimmertwins PresentationAshok Modi
 

More from Ashok Modi (10)

Drupal Camp LA 2011: Typography modules for Drupal
Drupal Camp LA 2011: Typography modules for DrupalDrupal Camp LA 2011: Typography modules for Drupal
Drupal Camp LA 2011: Typography modules for Drupal
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performance
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizing
 
Entity cache
Entity cacheEntity cache
Entity cache
 
Hacking core
Hacking coreHacking core
Hacking core
 
CalArts presentation
CalArts presentationCalArts presentation
CalArts presentation
 
Drupal Camp LA 2010: Moderating Content in Drupal
Drupal Camp LA 2010: Moderating Content in DrupalDrupal Camp LA 2010: Moderating Content in Drupal
Drupal Camp LA 2010: Moderating Content in Drupal
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and Scalability
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and Scalability
 
Zimmertwins Presentation
Zimmertwins PresentationZimmertwins Presentation
Zimmertwins Presentation
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Drupal content-migration

  • 1. Ashok Modi (BTMash) – Drupal LA – March 2011 Migrating content to drupal – Migrate Module
  • 2. Agenda Different Methods Steps to Work with Migrate Hooks Build a Class Description Source Adding Mapping Additional Data drush commands Q & A
  • 3. Disclaimer Code Heavy! You may fall asleep. New territory! Talk about one *small* aspect of migration (migrating nodes) Not talking about creating own DestinationHandlers Possibly not talking about creating own FieldHandlers (depends on time) Can walk through an example migration that I did if preferred. Ask questions? It will make the presentation less terrible 
  • 4. Possible method – by hand Should be accurate Get all files Mapping / everything works Time consuming Not feasible if you have a lot of content. Good way to test interns / punish coworkers (?)
  • 5. Possible methods – Node Export Node Export (http://drupal.org/project/node_export) Has 7.x branch But no way to update content from 6.x -> 7.x No way to go back *easy* to set up (requires exact setup between source and destination in field names, etc)
  • 6. Possible Methods - Feeds Really good method Map fields from source to destination Can import RSS / Atom / Various types of feeds Also flat files such as CSV Well documented Other than flat files, requires a feed source Might run into issues if content is updated in source *might be tricky in another cms*
  • 7. Method demonstrated - Migrate Already defined many possible import sources XML, JSON, CSV, Databases (any currently supported by Drupal!) Can import many different types of content Users, Nodes, Comments, Taxonomy, Files … all core entities Can define your own import handler (not covered in presentation) Can define own method for importing custom fields Current already defined for all core field types Has support for Media Module importing Patch underway for getting date import Can define your own field handler (possibly not covered in presentation) Drush integration Rollback, Status Updates, Limited import. Caveat – Confusing documentation Only a status UI – all mapping must be done in code.
  • 8. Assumptions made for presentation Migrating from a database Files directory for source are on same machine as the destination site directory
  • 9. Steps to work with Migrate Let Migrate know about your module (1 hook!) Build a Migration Class Give it a description Let Migrate know what you’re getting content from. Let Migrate know about the type of content. Map the fields the migrate class it going to fill. (Optional) Massage / Add any fields you couldn’t get in the initial mapping (query).
  • 10. Step 1: Hook Implement one hook – hook_migrate_api Provide the api version number (currently at version 2) That’s it! function mymodule_migrate_api() { return array( ‘api’ => 2, ); }
  • 11. Step 2: Build a Class Implement classes Class defines type of content that will be imported class NodeContentTypeMigration extends Migration { public function __construct() { parent::__construct(); … } public function prepareRow($current_row) { … } }
  • 12. Step 2: Build a Class (functions inside) public function __construct() {…} Constructor for the class Allows migrate to know content type (user, node, tags) Where content is mapped from (db, csv, xml, etc) All the mappings coming in (fields) (optional)public function prepareRow($current_row) {…} Any extra data (things that cannot be pulled in a single query(?)) Massage any of the data that was pulled in (clean up text, clean up links, etc)
  • 13. Step 2a: Create a description Create a description Class Description Any additional source fields (not found in initial query) Initial source -> destination mapping (what is the key in the source db?) $this->description = t(“Import all nodes of type PAGE”); Define Source Fields Fields that may not be getting pulled in via your query or in the flat file data but will be getting migrated somehow $source_fields = array( 'nid' => t('The node ID of the page'), ’my_files' => t(’The set of files in a field for this node'), );
  • 14. Off course: query source database Set up query (if need be, switch DBs using Database::getConnection) $query = Database::getConnection('for_migration', 'default'); Then write out rest of the query Alternatively, if source db is on same machine as destination db, use mysql db shortcut db_select(MY_MIGRATION_DATABASE_NAME .’.table_name’, ‘t’)
  • 15. Step 2b: Call to grab data NOTE: This is only for migrations from databases Set up query (if need be, switch DBs using Database::getConnection) $query = db_select(MY_MIGRATION_DATABASE_NAME .'.node', 'n’) ->fields('n', array('nid', 'vid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky', 'tnid', 'translate')) ->condition('n.type', 'page', '='); $query->join(MY_MIGRATION_DATABASE_NAME .'.node_revisions', 'nr', 'n.vid = nr.vid'); $query->addField('nr', 'body'); $query->addField('nr', 'teaser'); $query->join(MY_MIGRATION_DATABASE_NAME .'.users', 'u', 'n.uid = u.uid'); $query->addField('u', 'name'); $query->orderBy('n.changed');
  • 16. Step 2b: Why the orderby? Migrate module has a feature called ‘highwater’ It is a key to designate and figure out if a piece of content needs to be updated rather than inserted. Means content can be updated! $this->highwaterField = array( 'name' => 'changed', 'alias' => 'n’, );
  • 17. Step 2c: Mappings Add a ‘mapping’ (this is for tracking relationships between the rows from the source db and the rows that will come in the destination site) – essentially key of source DB. $this->map = new MigrateSQLMap( $this->machineName, array( 'nid' => array( 'type' => 'int’, 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'D6 Unique Node ID’, 'alias' => 'n', ) ), MigrateDestinationNode::getKeySchema());
  • 18. Step 2c: Mappings (cont’d) Now let the migrate module know what kind of mapping is being performed. $this->source = new MigrateSourceSQL($query, $source_fields); Along with the type of content $this->destination = new MigrateDestinationNode('page'); .
  • 19. Step 2d: Map Fields Usually follows the form $this->addFieldMapping(‘destination_field_name’, ‘source_field_name’); $this->addFieldMapping('revision_uid', 'uid'); Can provide default values $this->addFieldMapping('pathauto_perform_alias')->defaultValue('1'); Can provide no value $this->addFieldMapping('path')->issueGroup(t('DNM')); Can provide arguments and separators for certain field types (body, file, etc require this methodology)
  • 20. Step 3: Additional data / cleanup Optional public function prepareRow($current_row) Use it to add any additional data / cleanup any fields that were mapped in. // Get the correct uid based on username & set author id for node to uid $user_query = db_select('users', 'u’) ->fields('u', array('uid')) ->condition('u.name', $username, '='); $results = $user_query->execute(); foreach ($results as $row) { $current_row->uid = $current_row->revision_uid = $row->uid; break; }
  • 21. Drush Commands (the important ones) drush ms – List various migration import classes drush mi <importclass> - Import content drush mr <importclass> - Rollback content Options --idlist=id1,id2,… - Import content with specific IDs --itemlimit=n – Only import up to ‘n’ items --feedback=“n seconds” – Show status report every ‘n’ seconds --feedback=“n items” – Show status report every ‘n’ items
  • 22. Resources http://drupal.org/project/migrate http://drupal.org/node/415260 Look at the example modules http://drupal.org/project/migrate_extras http://drupal.org/project/wordpress_migrate http://cyrve.com/import (drush documentation) http://goo.gl/3e1Jm(additional documentation to be added to core project) http://goo.gl/2qDLh (another example module)