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

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Recently uploaded (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

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)