SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Migrating without Migraines 
Oscar Merida 
October. 21, 2014
Content is nomadic 
Musketeers.me
Managing Content 
Musketeers.me 
Migrations 
• Technical process features 
• Automated 
• Safe 
• Adaptable 
• See also “Hitch your Wagon”, 2013 
• http://phpa.me/hitch-your-wagon
Musketeers.me 
Automated Photo by pubsubhashis
Musketeers.me 
Safe
Musketeers.me 
Adaptable
Migration Workflow 
Sources XML 
Musketeers.me 
Documents CMS
Built from many sources 
• One or more database tables 
• … or CSV, or XML, or… 
• Reference other content 
• Reference image, audio, & other files 
• Reference other systems 
• for example, Youtube for video 
Musketeers.me
Transform to XML 
• Represent fully built content and 
attributes 
• Clean up errors 
• Character encodings, HTML entities 
• Filenames & paths 
• Assign a unique identifier 
Musketeers.me
Import to Drupal 
• Use Feeds & Feeds XPath Parser modules 
• http://drupal.org/project/feeds_xpathparser 
• also JSON Parser, and others 
• UI to map XML to entity attributes & fields 
• UI for importing, deleting content 
Musketeers.me
What else do we need? 
• Access to source(s) 
• Command line PHP to transform it to XML 
• https://github.com/omerida/importtools 
• … patience. 
Musketeers.me
Importing Author Profiles 
• We need to import profiles for 
authors on our site. 
• Authors are not users, just a 
biographical profile (content type) 
• Data is provided via a CSV file 
Musketeers.me
Sample CSV data 
! 
first name,last 
name,email,city,country,date_joined,company,bio,id,tags 
Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri 
Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin 
non massa non ante bibendum ullamcorper. Duis cursus, diam at 
pretium aliquet, metus urna convallis",1,"contributor, author, " 
Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo 
Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. 
Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. 
Integer in magna. Phasellus dolor elit, pellentesque a, facilisis 
non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, 
Musketeers.me
Sample CSV data 
! 
first name,last 
name,email,city,country,date_joined,company,bio,id,tags 
Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri 
Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin 
non massa non ante bibendum ullamcorper. Duis cursus, diam at 
pretium aliquet, metus urna convallis",1,"contributor, author, " 
Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo 
Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. 
Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. 
Integer in magna. Phasellus dolor elit, pellentesque a, facilisis 
non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, 
Musketeers.me
Sample CSV data 
! 
first name,last 
name,email,city,country,date_joined,company,bio,id,tags 
Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri 
Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin 
non massa non ante bibendum ullamcorper. Duis cursus, diam at 
pretium aliquet, metus urna convallis",1,"contributor, author, " 
Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo 
Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. 
Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. 
Integer in magna. Phasellus dolor elit, pellentesque a, facilisis 
non, bibendum sed, est. Nunc laoreet lectus quis massa.”,2, 
Musketeers.me
Sample CSV data 
! 
first name,last 
name,email,city,country,date_joined,company,bio,id,tags 
Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri 
Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin 
non massa non ante bibendum ullamcorper. Duis cursus, diam at 
pretium aliquet, metus urna convallis",1,"contributor, author, " 
Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo 
Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. 
Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. 
Integer in magna. Phasellus dolor elit, pellentesque a, facilisis 
non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, 
Musketeers.me
Sample CSV data 
! 
first name,last 
name,email,city,country,date_joined,company,bio,id,tags 
Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri 
Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin 
non massa non ante bibendum ullamcorper. Duis cursus, diam at 
pretium aliquet, metus urna convallis",1,"contributor, author, " 
Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo 
Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. 
Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. 
Integer in magna. Phasellus dolor elit, pellentesque a, facilisis 
non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, 
Musketeers.me
Musketeers.me 
1. Parse CSV 
// read in our Sample CSV file 
// and clean up incoming data with sampleParser 
$csv = new readCsv(__DIR__ . '/sample.csv'); 
$csv->setKey('id'); 
$items = $csv->getArray('ProfileParser');
2. Clean up incoming 
function profileParser($item) { 
// skip profiles without an email 
if (empty($item['email'])) return false; 
Musketeers.me 
! 
// create a first+last item 
$item['last_first'] = $item['last_name'] . ', ' . $item['first_name']; 
! 
// cleanup & split the tags column into an array 
if (isset($item['tags'])) { 
$tags = explode(',', $item['tags']); 
$tags = array_filter($tags); 
$tags = array_map('trim', $tags); 
$item['tags'] = $tags; 
} 
! 
// clean date_joined format 
$date = new DateTime($item['date_joined']); 
$item['date_joined_clean'] = $date->format('Y-m-d'); 
! 
return $item; 
}
3. Convert to XML 
// output XML 
$xml = new toXml("profiles", "profile"); 
$xml->setHandler("tags", "tagHandler"); 
$xml->convert($items); 
echo $xml->saveXML(); 
Musketeers.me
4. Save XML Output 
Musketeers.me 
$ php csv2xml.php > profiles.xml 
<?xml version="1.0"?>! 
<profiles>! 
<profile>! 
<first_name>Whilemina</first_name>! 
<last_name>Benton</last_name>! 
<email>sollicitudin.orci@arcuiaculisenim.ca</email>! 
<city>Ansfelden</city>! 
<country>Sri Lanka</country>! 
<date_joined>12/25/13</date_joined>! 
<company>Vivamus Institute</company>! 
<bio>amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. ! 
Duis cursus, diam at pretium aliquet, metus urna convallis</bio>! 
<id>1</id>! 
<roles>! 
<role>contributor</role>! 
<role>author</role>! 
</roles>! 
<last_first>Benton, Whilemina</last_first>! 
<date_joined_clean>2013-12-25</date_joined_clean>! 
</profile>
Our Profile Content Type 
• Text fields: First Name, Last Name, City, 
Country, Company 
• Email field: E-mail 
• Date field: Date Joined 
• Long Text: bio 
• List: Tags (roles) 
• Integer: Legacy ID 
Musketeers.me
Musketeers.me
Step 4. Configure Feeds 
• Basic: Disable periodic import 
• Fetcher: File Upload 
• Parser: XPath XML Parser 
• Processor: Node processor 
Musketeers.me
5. Configure Processor 
• Settings 
• Bundle: Target content type 
• Update: Update existing nodes 
• Text format: HTML 
• Expire Nodes: never 
Musketeers.me
6. Map Source to Target 
Musketeers.me
7. Map Inputs with XPath 
Musketeers.me
An XPath Primer 
• Used to query XML documents 
• A path can return multiple nodes 
• /profiles/profile - give me all profile nodes 
• Can test for attributes, elements, and more 
• http://github.com/GeorgeMac/xpath-primer 
Musketeers.me
8. Run the Import 
Musketeers.me
Advanced Feeds Tricks 
• Provide a URL to an image, audio, or 
other media file, and it’ll download 
automatically. 
• Can create entity references 
• As long as your GUIDs are set 
• Can import to Field Collection 
• https://drupal.org/project/field_collection_feeds 
Musketeers.me
hook_feeds_presave 
• Clean up data on import 
• Can also use regular node hooks 
function grad_importers_feeds_presave(FeedsSource $source, $entity, $item) {! 
if ('publications' == $source->id) {! 
// ensure yes/no fields are imported! 
$entity->field_submitted_web[LANGUAGE_NONE][0]['value'] = (int) $item['xpathparser:5'];! 
$entity->field_media_promotion[LANGUAGE_NONE][0]['value'] = (int) $item['xpathparser:6'];! 
Musketeers.me 
! 
// don't lose freeform notes but import the values cleanly! 
$notes = array_filter(array($item['xpathparser:8'], $item['xpathparser:12']));! 
$entity->field_history_notes[LANGUAGE_NONE][0]['value'] = join("n", $notes);! 
}! 
}
hook_feeds_presave II 
• Extract data from a field, assign it to another 
function foo_feeds_presave(FeedsSource $source, $entity, $item) {! 
if ('news_feed' == $source->id) {! 
// get link and title out of the description field! 
$doc = new DOMDocument();! 
$x = @$doc->loadHTML($item['xpathparser:2']);! 
Musketeers.me 
! 
$links = $doc->getElementsByTagName('a');! 
if ($link = $links->item(0)) {! 
$entity->field_link['und'][0]['title'] = $link->nodeValue;! 
$entity->field_link['und'][0]['url'] ! 
= $link->attributes->getNamedItem('href')->nodeValue;! 
}! 
}! 
}
Creating an Entity Reference 
• Map a source to 
a Feeds GUID 
! 
! 
• Set an XPATH 
query to read the 
GUID 
Musketeers.me
Entity Reference XML 
<scholars> ! 
<scholar>! 
<scholar_id>b36c6b08b402c12bd3a11657420cd5dd</scholar_id>! 
<scholar_name>Sammy Zahran, PhD</scholar_name>! 
</scholar>! 
</scholars>! 
<program_id>ee01cb8d56dbd67bf89c3c4fcf69e2f5</program_id>! 
</publication> 
Musketeers.me
What about Drupal 8? 
• Import API is in core 
• Based on Migrate API 
• http://groups.drupal.org/imp 
• Porting Feeds module 
• http://drupal.org/node/1960800 
Musketeers.me
What did we learn? 
• Decouple your source from import 
• Sources will change … versioning! 
• Transform input sources to XML 
• Clean up data with PHP before it gets to 
Drupal. 
• Quicker & easier to run more than one 
import 
Musketeers.me
Thank You. 
• php[architect] - http://phparch.com 
• Magazine, books, trainings, and … 
• php[world] - this November 
• http://world.phparch.com 
• PHP Foundation for Drupal 8 
• 2 days of training 
• http://phpa.me/drupal8dec14
Musketeers.me 
Questions? 
@omerida on twitter

Mais conteĂşdo relacionado

Semelhante a Migrate without migranes

IELTS Writing Tips And Tricks The Ultimate Guid
IELTS Writing Tips And Tricks The Ultimate GuidIELTS Writing Tips And Tricks The Ultimate Guid
IELTS Writing Tips And Tricks The Ultimate GuidBrenda Potter
 
Good Essay Transition Sentences. Online assignment writing service.
Good Essay Transition Sentences. Online assignment writing service.Good Essay Transition Sentences. Online assignment writing service.
Good Essay Transition Sentences. Online assignment writing service.Blanca Richardson
 
How To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreHow To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreShannon Wright
 
How To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreHow To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreStacy Johnson
 
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!Serdar Basegmez
 
Fantastic How To Write Synthesis E
Fantastic How To Write Synthesis EFantastic How To Write Synthesis E
Fantastic How To Write Synthesis EJessica Howard
 
Running head PRIVACY1PRIVACY 4.docx
Running head PRIVACY1PRIVACY 4.docxRunning head PRIVACY1PRIVACY 4.docx
Running head PRIVACY1PRIVACY 4.docxtoltonkendal
 
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)Simon Willison
 
CMS content
CMS contentCMS content
CMS contentiemail808
 
My Parents Essay Writing Essay Writing My Parents
My Parents Essay Writing Essay Writing My ParentsMy Parents Essay Writing Essay Writing My Parents
My Parents Essay Writing Essay Writing My ParentsLisa Brewer
 
Example Of A Literature Review For A Research Paper
Example Of A Literature Review For A Research PaperExample Of A Literature Review For A Research Paper
Example Of A Literature Review For A Research PaperNicole Kathol
 
Distillery Credentials May 2014 PDF
Distillery Credentials May 2014 PDFDistillery Credentials May 2014 PDF
Distillery Credentials May 2014 PDFSam Jeffries
 
AUS IT Handbook - Fall 2012
AUS IT Handbook - Fall 2012AUS IT Handbook - Fall 2012
AUS IT Handbook - Fall 2012Ali Khawaja
 
40 Minutes on Business Model Innovation
40 Minutes on Business Model Innovation40 Minutes on Business Model Innovation
40 Minutes on Business Model InnovationAlexander Osterwalder
 
Computing at SC&I
Computing at SC&IComputing at SC&I
Computing at SC&IRU asis&t
 
Next generation content intelligence (BeeCon 2017)
Next generation content intelligence (BeeCon 2017)Next generation content intelligence (BeeCon 2017)
Next generation content intelligence (BeeCon 2017)Francesco Corti
 
Scaling drupal with confidence - Tweentribune Casestudy
Scaling drupal with confidence - Tweentribune CasestudyScaling drupal with confidence - Tweentribune Casestudy
Scaling drupal with confidence - Tweentribune CasestudyEbizon Net Info Pvt. Ltd.
 
Sample Expository Essay On Sociology. Online assignment writing service.
Sample Expository Essay On Sociology. Online assignment writing service.Sample Expository Essay On Sociology. Online assignment writing service.
Sample Expository Essay On Sociology. Online assignment writing service.Wendy Robertson
 

Semelhante a Migrate without migranes (20)

IELTS Writing Tips And Tricks The Ultimate Guid
IELTS Writing Tips And Tricks The Ultimate GuidIELTS Writing Tips And Tricks The Ultimate Guid
IELTS Writing Tips And Tricks The Ultimate Guid
 
Good Essay Transition Sentences. Online assignment writing service.
Good Essay Transition Sentences. Online assignment writing service.Good Essay Transition Sentences. Online assignment writing service.
Good Essay Transition Sentences. Online assignment writing service.
 
How To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreHow To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School Tre
 
How To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School TreHow To Write An Informative Essay Middle School Tre
How To Write An Informative Essay Middle School Tre
 
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
ICONUK 2016: REST Assured, Freeing Your Domino Data Has Never Been That Easy!
 
jQuery mobile
jQuery mobilejQuery mobile
jQuery mobile
 
Fantastic How To Write Synthesis E
Fantastic How To Write Synthesis EFantastic How To Write Synthesis E
Fantastic How To Write Synthesis E
 
Running head PRIVACY1PRIVACY 4.docx
Running head PRIVACY1PRIVACY 4.docxRunning head PRIVACY1PRIVACY 4.docx
Running head PRIVACY1PRIVACY 4.docx
 
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
 
CMS content
CMS contentCMS content
CMS content
 
My Parents Essay Writing Essay Writing My Parents
My Parents Essay Writing Essay Writing My ParentsMy Parents Essay Writing Essay Writing My Parents
My Parents Essay Writing Essay Writing My Parents
 
Example Of A Literature Review For A Research Paper
Example Of A Literature Review For A Research PaperExample Of A Literature Review For A Research Paper
Example Of A Literature Review For A Research Paper
 
Distillery Credentials May 2014 PDF
Distillery Credentials May 2014 PDFDistillery Credentials May 2014 PDF
Distillery Credentials May 2014 PDF
 
AUS IT Handbook - Fall 2012
AUS IT Handbook - Fall 2012AUS IT Handbook - Fall 2012
AUS IT Handbook - Fall 2012
 
40 Minutes on Business Model Innovation
40 Minutes on Business Model Innovation40 Minutes on Business Model Innovation
40 Minutes on Business Model Innovation
 
Business Model Innovation
Business Model InnovationBusiness Model Innovation
Business Model Innovation
 
Computing at SC&I
Computing at SC&IComputing at SC&I
Computing at SC&I
 
Next generation content intelligence (BeeCon 2017)
Next generation content intelligence (BeeCon 2017)Next generation content intelligence (BeeCon 2017)
Next generation content intelligence (BeeCon 2017)
 
Scaling drupal with confidence - Tweentribune Casestudy
Scaling drupal with confidence - Tweentribune CasestudyScaling drupal with confidence - Tweentribune Casestudy
Scaling drupal with confidence - Tweentribune Casestudy
 
Sample Expository Essay On Sociology. Online assignment writing service.
Sample Expository Essay On Sociology. Online assignment writing service.Sample Expository Essay On Sociology. Online assignment writing service.
Sample Expository Essay On Sociology. Online assignment writing service.
 

Mais de Oscar Merida

Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7Oscar Merida
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeOscar Merida
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupalOscar Merida
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development EnvironmentsOscar Merida
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development EnvironmentsOscar Merida
 

Mais de Oscar Merida (8)

PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 

Último

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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂşjo
 

Último (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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Migrate without migranes

  • 1. Migrating without Migraines Oscar Merida October. 21, 2014
  • 2. Content is nomadic Musketeers.me
  • 3. Managing Content Musketeers.me Migrations • Technical process features • Automated • Safe • Adaptable • See also “Hitch your Wagon”, 2013 • http://phpa.me/hitch-your-wagon
  • 7. Migration Workflow Sources XML Musketeers.me Documents CMS
  • 8. Built from many sources • One or more database tables • … or CSV, or XML, or… • Reference other content • Reference image, audio, & other files • Reference other systems • for example, Youtube for video Musketeers.me
  • 9. Transform to XML • Represent fully built content and attributes • Clean up errors • Character encodings, HTML entities • Filenames & paths • Assign a unique identifier Musketeers.me
  • 10. Import to Drupal • Use Feeds & Feeds XPath Parser modules • http://drupal.org/project/feeds_xpathparser • also JSON Parser, and others • UI to map XML to entity attributes & fields • UI for importing, deleting content Musketeers.me
  • 11. What else do we need? • Access to source(s) • Command line PHP to transform it to XML • https://github.com/omerida/importtools • … patience. Musketeers.me
  • 12. Importing Author Profiles • We need to import profiles for authors on our site. • Authors are not users, just a biographical profile (content type) • Data is provided via a CSV file Musketeers.me
  • 13. Sample CSV data ! first name,last name,email,city,country,date_joined,company,bio,id,tags Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet, metus urna convallis",1,"contributor, author, " Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, Musketeers.me
  • 14. Sample CSV data ! first name,last name,email,city,country,date_joined,company,bio,id,tags Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet, metus urna convallis",1,"contributor, author, " Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, Musketeers.me
  • 15. Sample CSV data ! first name,last name,email,city,country,date_joined,company,bio,id,tags Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet, metus urna convallis",1,"contributor, author, " Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa.”,2, Musketeers.me
  • 16. Sample CSV data ! first name,last name,email,city,country,date_joined,company,bio,id,tags Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet, metus urna convallis",1,"contributor, author, " Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, Musketeers.me
  • 17. Sample CSV data ! first name,last name,email,city,country,date_joined,company,bio,id,tags Whilemina,Benton,sollicitudin.orci@arcuiaculisenim.ca,Ansfelden,Sri Lanka,12/25/13,Vivamus Institute,"amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet, metus urna convallis",1,"contributor, author, " Kim,Sellers,amet.ultricies@ultriciesdignissim.com,Cabo de Santo Agostinho,Burundi,06/26/14,Maecenas Ornare Foundation,"eget massa. Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa.",2, Musketeers.me
  • 18. Musketeers.me 1. Parse CSV // read in our Sample CSV file // and clean up incoming data with sampleParser $csv = new readCsv(__DIR__ . '/sample.csv'); $csv->setKey('id'); $items = $csv->getArray('ProfileParser');
  • 19. 2. Clean up incoming function profileParser($item) { // skip profiles without an email if (empty($item['email'])) return false; Musketeers.me ! // create a first+last item $item['last_first'] = $item['last_name'] . ', ' . $item['first_name']; ! // cleanup & split the tags column into an array if (isset($item['tags'])) { $tags = explode(',', $item['tags']); $tags = array_filter($tags); $tags = array_map('trim', $tags); $item['tags'] = $tags; } ! // clean date_joined format $date = new DateTime($item['date_joined']); $item['date_joined_clean'] = $date->format('Y-m-d'); ! return $item; }
  • 20. 3. Convert to XML // output XML $xml = new toXml("profiles", "profile"); $xml->setHandler("tags", "tagHandler"); $xml->convert($items); echo $xml->saveXML(); Musketeers.me
  • 21. 4. Save XML Output Musketeers.me $ php csv2xml.php > profiles.xml <?xml version="1.0"?>! <profiles>! <profile>! <first_name>Whilemina</first_name>! <last_name>Benton</last_name>! <email>sollicitudin.orci@arcuiaculisenim.ca</email>! <city>Ansfelden</city>! <country>Sri Lanka</country>! <date_joined>12/25/13</date_joined>! <company>Vivamus Institute</company>! <bio>amet nulla. Donec non justo. Proin non massa non ante bibendum ullamcorper. ! Duis cursus, diam at pretium aliquet, metus urna convallis</bio>! <id>1</id>! <roles>! <role>contributor</role>! <role>author</role>! </roles>! <last_first>Benton, Whilemina</last_first>! <date_joined_clean>2013-12-25</date_joined_clean>! </profile>
  • 22. Our Profile Content Type • Text fields: First Name, Last Name, City, Country, Company • Email field: E-mail • Date field: Date Joined • Long Text: bio • List: Tags (roles) • Integer: Legacy ID Musketeers.me
  • 24. Step 4. Configure Feeds • Basic: Disable periodic import • Fetcher: File Upload • Parser: XPath XML Parser • Processor: Node processor Musketeers.me
  • 25. 5. Configure Processor • Settings • Bundle: Target content type • Update: Update existing nodes • Text format: HTML • Expire Nodes: never Musketeers.me
  • 26. 6. Map Source to Target Musketeers.me
  • 27. 7. Map Inputs with XPath Musketeers.me
  • 28. An XPath Primer • Used to query XML documents • A path can return multiple nodes • /profiles/profile - give me all profile nodes • Can test for attributes, elements, and more • http://github.com/GeorgeMac/xpath-primer Musketeers.me
  • 29. 8. Run the Import Musketeers.me
  • 30. Advanced Feeds Tricks • Provide a URL to an image, audio, or other media file, and it’ll download automatically. • Can create entity references • As long as your GUIDs are set • Can import to Field Collection • https://drupal.org/project/field_collection_feeds Musketeers.me
  • 31. hook_feeds_presave • Clean up data on import • Can also use regular node hooks function grad_importers_feeds_presave(FeedsSource $source, $entity, $item) {! if ('publications' == $source->id) {! // ensure yes/no fields are imported! $entity->field_submitted_web[LANGUAGE_NONE][0]['value'] = (int) $item['xpathparser:5'];! $entity->field_media_promotion[LANGUAGE_NONE][0]['value'] = (int) $item['xpathparser:6'];! Musketeers.me ! // don't lose freeform notes but import the values cleanly! $notes = array_filter(array($item['xpathparser:8'], $item['xpathparser:12']));! $entity->field_history_notes[LANGUAGE_NONE][0]['value'] = join("n", $notes);! }! }
  • 32. hook_feeds_presave II • Extract data from a field, assign it to another function foo_feeds_presave(FeedsSource $source, $entity, $item) {! if ('news_feed' == $source->id) {! // get link and title out of the description field! $doc = new DOMDocument();! $x = @$doc->loadHTML($item['xpathparser:2']);! Musketeers.me ! $links = $doc->getElementsByTagName('a');! if ($link = $links->item(0)) {! $entity->field_link['und'][0]['title'] = $link->nodeValue;! $entity->field_link['und'][0]['url'] ! = $link->attributes->getNamedItem('href')->nodeValue;! }! }! }
  • 33. Creating an Entity Reference • Map a source to a Feeds GUID ! ! • Set an XPATH query to read the GUID Musketeers.me
  • 34. Entity Reference XML <scholars> ! <scholar>! <scholar_id>b36c6b08b402c12bd3a11657420cd5dd</scholar_id>! <scholar_name>Sammy Zahran, PhD</scholar_name>! </scholar>! </scholars>! <program_id>ee01cb8d56dbd67bf89c3c4fcf69e2f5</program_id>! </publication> Musketeers.me
  • 35. What about Drupal 8? • Import API is in core • Based on Migrate API • http://groups.drupal.org/imp • Porting Feeds module • http://drupal.org/node/1960800 Musketeers.me
  • 36. What did we learn? • Decouple your source from import • Sources will change … versioning! • Transform input sources to XML • Clean up data with PHP before it gets to Drupal. • Quicker & easier to run more than one import Musketeers.me
  • 37. Thank You. • php[architect] - http://phparch.com • Magazine, books, trainings, and … • php[world] - this November • http://world.phparch.com • PHP Foundation for Drupal 8 • 2 days of training • http://phpa.me/drupal8dec14