SlideShare a Scribd company logo
Staging Drupal

Managing Your Project in Multiple
        Environments
Introduction
• Chris Pliakas
   – drupal.org: cpliakas
   – Twitter: @cpliakas
• Michelle Lauer
   – drupal.org: miche
   – Twitter: @lauermichelle
• CommonPlaces e-Solutions, LLC
   – Twitter: @CommonPlaces
   – New Hampshire, United States
Why are we here
• Discuss the challenges with developing a site in
  multiple environments
• Offer some solutions
• Goals of our process and tools used across multiple
  environments
   – Allow for seamless code integration (syncing)
   – Increase efficiency of distributing database
     changes
   – Minimize downtime and errors while updating
     the production site
Why Stage Drupal?
• Websites are becoming increasingly complex.
• Transition to traditional software development
  cycle.
• Multiple engineers/designers working on the same
  project.
• Proper staging avoids conflicts, separates
  development from production.
Multiple Environments
• Proper staging requires development, QA, and
  production locations.
• Each developer has a separate copy of the
  application in an isolated location.
• Flow is like a pipeline, development → QA →
  production.
• Drupal is portable
• How to stage Drupal?
Managing Code
        With Source Control
• Source control is essential in the staging process.
• Manages changes to the code over time.
• We recommend a standard “tags, branches, trunk”
  repository layout.
• We separate core code from project code.
• rsync -avC –delete –exclude=dir src/ dst
What Files Should Be Under
         Source Control?
•   Separate code from user generated content.
•   Create “templates” for environment specific files.
•   Store database snapshots?
•   Update code frequently to prevent conflicts.
•   Check production for modifications.
Porting the Database
• Database snapshot and files tied together
• Mysqldump, pg_dump, *MyAdmin applications,
  contributed solutions.
• Restore database, clear cache.
• Multisite considerations.
Code Release Cycle
• Developers import snapshot, commit changes.
• Changes promoted to QA, tested thoroughly.
• Admin steps, adding content tested on QA.
• Code is tagged.
• Code updated on production, manual changes
  made again.
• Alpha, beta, stable release cycles.
Automate Administrative
     Tasks Through Code
• When
  – Multiple sandboxes needing the same database
    changes
  – Phased approach to release features
• Why
  – Easily share changes among sandboxes
  – Seamlessly add functionality to an active site
  – Version control
A Systematic Approach
• Step 1
   – Take a database snapshot with Demonstration
     Site module (drupal.org/project/demo)
• Step 2
   – Write it down!
   – Separate out by sub-projects.
   – Be explicit and exact
   – For example, installing “Reroute Email”
“Admin List” example
• ADMIN
  – [reroute email]
     • Enable Reroute Email module
       (admin/build/modules)
     • Configure Reroute Email
       (admin/settings/reroute_email)
        – dev@company.com
A Systematic Approach
• Step 3 – Choice Time
   – How long is your admin list?
   – Would it be faster for you to write a script that
     all developers can run in their sandboxes and
     also can be used on production?
   – What is the best use of time here?
   – It really is a judgment call. The more you write
     database update scripts, the faster you become.
A Systematic Approach
• Benefits of writing an update script
   – All changes can be accessed in version control
     and more easily debugged
   – Test your deployment process several times as
     part of QA
   – You write it once and use it in as many
     environments as you need
The “Site Module”
• MYSITE.module.
• Site specific configurations: hook_form_alter() and
  hook_nodeapi().
• Use hook_update_N() in MYSITE.install to make
  database changes across many development
  environments.
• This “site module” is NOT intended to live outside
  of its site or be installed anywhere other than its
  site.
The “Site Module”
• The correct way to work with an install file is that
  for every update function, you amend the install
  function so that newly installed modules behave
  correctly. 
• That being said, my recommendations for a
  MYSITE.install file are to NOT be used for any other
  module you create – just the “site module”.
MYSITE.install
• New update function to replicate our “Admin List”.
• Configurations saved in the {variable} table.
   function mymodule_update_N() {
     $ret = array();
     module_rebuild_cache();
     $mods = array('reroute_email');
     drupal_install_modules($mods);
     variable_set(REROUTE_EMAIL_ADDRESS,
      'mymail@company.com'));
     return $ret;
   }
Use Drupal Functions
• Examples vs direct sql query
   – variable_set();
   – node_submit(); node_save();
• Less error prone
   – Inserting or updating data
   – Several tables at once
   – Lock tables
   – Serialize data
   – Clear cache
MYSITE.install Examples
• 5 development sandboxes, a testing server and
  production.
• 5 critical nodes that you need to add and that
  must be in every environment.
• That would be 35 instances of manually creating a
  node. How tedious! Especially when you can write
  it once for everyone.
Start Building
• You have to do it manually in one sandbox first
• Install Node Export
   – drupal.org/project/node_export
• Install Content Copy
   – drupal.org/project/cck
• Create Content Types and Taxonomies.
• Link taxonomies to content types either via
  taxonomy interface or as a CCK field
• Create nodes
Content Types
• Create a folder in your module called
  “content_types”
• Create a file in that folder called “my_type.cck”
• Export the type (admin/content/types/export)
• Put the contents of this export into your new file.
   – You don't need <?php
Content Types
$modulepath = drupal_get_path ('module',
  'drupalconparis2009');
$cck_definition_file =
  $modulepath."/content_types/my_type.cck";
$form_state['values']['type_name'] = '<create>';
$form_state['values']['macro'] =
  file_get_contents($cck_definition_file);
include_once(drupal_get_path('module',
  'node') .'/content_types.inc');
include_once(drupal_get_path('module',
  'content_copy')
  .'/content_copy.module');
drupal_execute("content_copy_import_form",
  $form_state);
content_clear_type_cache();
Vocabulary
$voc = array();
$voc['name'] = 'shuswi';
$voc['description'] = '';
$voc['nodes'] = array('page'=>'page',
  'story'=>'story');
$voc['multiple'] = 1;
$voc['required'] = 0;
$voc['relations'] = 1;
$voc['hierarchy'] = 1;
$voc['weight'] = 0;
taxonomy_save_vocabulary($voc);
Terms
$vid = db_result(db_query("SELECT vid FROM
  {vocabulary} WHERE name = '%s'", 'shuswi'));
$shuswi[] = 'bipagi';
$shuswi[] = 'jiphobre';
$shuswi[] = 'slid';
foreach ($shuswi as $k=>$v) {
  $term = array();
  $term['vid'] = $vid;
  $term['name'] = $v;
  $term['description'] = "";
  $term['weight'] = 0;
  taxonomy_save_term($term);
}
Exporting Nodes
• Create a folder in your module called “nodes”
• Create a file in it called nodes_20090904.inc
• Go to Administer Content (admin/content/node)
• Check the nodes you want to export
• Select “Export” from the bulk operation dropdown
   – This returns an array of your node content
• Paste this code in your file
   – You don't need <?php
Importing Nodes
//content arrays
$modulepath = drupal_get_path ('module','drupalconparis2009');
$nodes_file = $modulepath. "/nodes/nodes_20090904.inc";
eval('$nodes = '.file_get_contents($nodes_file).';');
//save nodes
foreach ($nodes as $node_array) {
   unset($node_array['nid']);
   unset($node_array['vid']);
   unset($node_array['#_export_node_encode_object']);
   unset($node_array['menu']);
   foreach($node_array['taxonomy'] as $term) {
     $term = (object)$term;
   }
   $node_object = node_submit($node_array);
   node_save($node_object);
}
Export Views
• Version control because they are no longer in the
  database
• Facilitates multiple sandboxes being in sync
• Create a folder in your site module called ‘views’
• Enable Views Export
• Export each view individually, create a file called
  myview_name.inc
         <?php
         //your exported code here
         $views[$view->name] = $view;
Views in Code – Site Module
function mymodule_views_api() {
  return array(
     'api' => 2,
     'path' => drupal_get_path('module',mymodule) .
       '/views/*.inc',
  );
}
function mymodule_views_default_views() {
  $path = './'. drupal_get_path('module',mymodule)
     '/views/*.inc';
  foreach (glob($path) as $views_filename) {
      require_once($views_filename);
  }
  return $views;
}
Register Your New Views
• Clear views cache (admin/build/views/tools)
   – This one tells the site that you have views in
     code as well – now your previously placed views
     generated blocks won’t get confused.
• “Revert” all the views that you just saved into
  code. This will remove them from the database.
• Clear views cache again
   – This one ensures that your site is only looking
     for the views in code.
Permissions
• Permissions API
   – drupal.org/project/permissions_api
• After all modules have been installed so you know
  the names of all permissions and roles
 $permissions = array(
    'create mytype content',
    'edit own mytype content',
    'delete own mytype content',
 );
 permissions_grant_permissions('authenticated user',
    $permissions);
Testing Your Install Script
• Take another database snapshot
• Reload the fresh database copy you took before
  you started (without all those administrative
  changes)
• Run your update script – mysite.com/update.php
• In the dropdown of your site module, select the N
  of your script
Testing Your Install Script
• If there are errors
   – Debug them and make changes
   – Reset your database (admin/build/demo/reset)
   – Run update.php again
• Make sure your configurations, taxonomies,
  content all look as expected.
• When your team syncs their code and runs
  update.php, they will now have a slew of database
  changes instantly!
Recap
• Sometimes takes longer to write and test (and
  reload DB) than to just email a list of admin steps
  to your development team and repeat on
  production.
• Remember, to be officially correct, all updates
  should go also go in the install function. That way
  the module can stand on its own.
• CCK types must be in separate file
Recap
• Must add bottom line to exported view in
  mymodule/views/myview.inc
   – $views[$view->name] = $view;
• Need two Views functions in your module
• Must unset the nid & vid on a node import because
  node_save looks for an those to determine if it is
  performing and update or insert
• If you get timeout errors, separate your updates
  into several functions
Drupal Tools
• Devel: Generate: drupal.org/project/devel
• Demonstration Site: drupal.org/project/demo
• Node Export: drupal.org/project/node_export
• Permissions API:
  drupal.org/project/permissions_api
• Views Export: drupal.org/project/views
• CCK: Content Copy: drupal.org/project/cck
• Drush: drupal.org/project/drush
More Options
• Blocks: Follow similar methodology as Content
  Types by using the form function
   – block_add_block_form
• drupal.org/project/variable_dump
• drupal.org/project/exportables
• drupal.org/project/transformations
• drupal.org/project/migrate
• drupal.org/project/deploy
• drupal.org/project/autopilot
• drupal.org/project/features
Questions & Answers
• Download this presentation
   – www.CommonPlaces.com/Resources
• Follow the presenters on Twitter
   – Chris: @CPliakas
   – Michelle: @LauerMichelle
   – CommonPlaces: @CommonPlaces
Questions & Answers
• Download this presentation
   – www.CommonPlaces.com/Resources
• Follow the presenters on Twitter
   – Chris: @CPliakas
   – Michelle: @LauerMichelle
   – CommonPlaces: @CommonPlaces

More Related Content

What's hot

Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
Ignacio Sánchez Holgueras
 
Simple Build Tool
Simple Build ToolSimple Build Tool
Simple Build Tool
David Galichet
 
Using Puppet - Real World Configuration Management
Using Puppet - Real World Configuration ManagementUsing Puppet - Real World Configuration Management
Using Puppet - Real World Configuration Management
James Turnbull
 
One drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp CaceresOne drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp Caceres
hernanibf
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
Jeff Geerling
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
Fabio Fumarola
 
Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013
OpenNebula Project
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
Jeevesh Pandey
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
Arnaud LEMAIRE
 
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Leonid Vasilyev  "Building, deploying and running production code at Dropbox"Leonid Vasilyev  "Building, deploying and running production code at Dropbox"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
IT Event
 
Yet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment PresentationYet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment Presentation
digital006
 
Introduction in Apache Maven2
Introduction in Apache Maven2Introduction in Apache Maven2
Introduction in Apache Maven2
Heiko Scherrer
 
Undine: Turnkey Drupal Development Environments
Undine: Turnkey Drupal Development EnvironmentsUndine: Turnkey Drupal Development Environments
Undine: Turnkey Drupal Development Environments
David Watson
 
3 Git
3 Git3 Git
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
Khan625
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
Atlassian
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
Matt Ray
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLA
Jesus Manuel Olivas
 
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
IT Event
 
DevOps for database
DevOps for databaseDevOps for database
DevOps for database
Osama Mustafa
 

What's hot (20)

Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Simple Build Tool
Simple Build ToolSimple Build Tool
Simple Build Tool
 
Using Puppet - Real World Configuration Management
Using Puppet - Real World Configuration ManagementUsing Puppet - Real World Configuration Management
Using Puppet - Real World Configuration Management
 
One drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp CaceresOne drupal to rule them all - Drupalcamp Caceres
One drupal to rule them all - Drupalcamp Caceres
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
 
Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
 
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Leonid Vasilyev  "Building, deploying and running production code at Dropbox"Leonid Vasilyev  "Building, deploying and running production code at Dropbox"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
 
Yet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment PresentationYet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment Presentation
 
Introduction in Apache Maven2
Introduction in Apache Maven2Introduction in Apache Maven2
Introduction in Apache Maven2
 
Undine: Turnkey Drupal Development Environments
Undine: Turnkey Drupal Development EnvironmentsUndine: Turnkey Drupal Development Environments
Undine: Turnkey Drupal Development Environments
 
3 Git
3 Git3 Git
3 Git
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLA
 
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
 
DevOps for database
DevOps for databaseDevOps for database
DevOps for database
 

Viewers also liked

Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Chris Charlton
 
Create Website In Indian Languages using drupal
Create Website In Indian Languages using drupalCreate Website In Indian Languages using drupal
Create Website In Indian Languages using drupal
drupalindia
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
Wingston
 
Building Archivable Websites
Building Archivable WebsitesBuilding Archivable Websites
Building Archivable Websites
nullhandle
 
Drupal Migration
Drupal MigrationDrupal Migration
Drupal Migration
永对 陈
 
Recipes for Drupal distributions
Recipes for Drupal distributionsRecipes for Drupal distributions
Recipes for Drupal distributions
Lakshmi Narasimhan Parthasarathy
 
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehillGeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
Nikhil Deshpande
 
Migrate
MigrateMigrate
Migrate
Zivtech, LLC
 
Moving In: how to port your content from * to Drupal
Moving In: how to port your content from * to DrupalMoving In: how to port your content from * to Drupal
Moving In: how to port your content from * to Drupal
Emma Jane Hogbin Westby
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-Translator
Dashamir Hoxha
 
Moving Drupal to the Cloud
Moving Drupal to the CloudMoving Drupal to the Cloud
Moving Drupal to the Cloud
Ari Davidow
 
Drupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows AzureDrupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows Azure
Ford AntiTrust
 
Data migration to Drupal using the migrate module
Data migration to Drupal using the migrate moduleData migration to Drupal using the migrate module
Data migration to Drupal using the migrate module
Luc Bézier
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
drupalindia
 
Content Staging in Drupal 8
Content Staging in Drupal 8Content Staging in Drupal 8
Content Staging in Drupal 8
Dick Olsson
 
Managing Translation Workflows in Drupal 7
Managing Translation Workflows in Drupal 7Managing Translation Workflows in Drupal 7
Managing Translation Workflows in Drupal 7
Suzanne Dergacheva
 
Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to Drupal
Rachel Jaro
 

Viewers also liked (17)

Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
 
Create Website In Indian Languages using drupal
Create Website In Indian Languages using drupalCreate Website In Indian Languages using drupal
Create Website In Indian Languages using drupal
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
 
Building Archivable Websites
Building Archivable WebsitesBuilding Archivable Websites
Building Archivable Websites
 
Drupal Migration
Drupal MigrationDrupal Migration
Drupal Migration
 
Recipes for Drupal distributions
Recipes for Drupal distributionsRecipes for Drupal distributions
Recipes for Drupal distributions
 
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehillGeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
 
Migrate
MigrateMigrate
Migrate
 
Moving In: how to port your content from * to Drupal
Moving In: how to port your content from * to DrupalMoving In: how to port your content from * to Drupal
Moving In: how to port your content from * to Drupal
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-Translator
 
Moving Drupal to the Cloud
Moving Drupal to the CloudMoving Drupal to the Cloud
Moving Drupal to the Cloud
 
Drupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows AzureDrupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows Azure
 
Data migration to Drupal using the migrate module
Data migration to Drupal using the migrate moduleData migration to Drupal using the migrate module
Data migration to Drupal using the migrate module
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
Content Staging in Drupal 8
Content Staging in Drupal 8Content Staging in Drupal 8
Content Staging in Drupal 8
 
Managing Translation Workflows in Drupal 7
Managing Translation Workflows in Drupal 7Managing Translation Workflows in Drupal 7
Managing Translation Workflows in Drupal 7
 
Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to Drupal
 

Similar to Staging Drupal 8 31 09 1 3

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 and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
Nuvole
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp Bratislava
Gábor Hojtsy
 
Power of Azure Devops
Power of Azure DevopsPower of Azure Devops
Power of Azure Devops
Azure Riyadh User Group
 
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Building a Drupal Distribution using Features, Drush Make, Installation Profi...Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Ben Shell
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Anupam Ranku
 
Drupal security
Drupal securityDrupal security
Drupal security
Jozef Toth
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security right
Gábor Hojtsy
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
Magento Dev
 
Drupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 versionDrupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 version
David Lanier
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
Piotr Pelczar
 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
indiver
 
Fluo CICD OpenStack Summit
Fluo CICD OpenStack SummitFluo CICD OpenStack Summit
Fluo CICD OpenStack Summit
Miguel Zuniga
 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
Michaela Murray
 
PowerShellForDBDevelopers
PowerShellForDBDevelopersPowerShellForDBDevelopers
PowerShellForDBDevelopers
Bryan Cafferky
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
hernanibf
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
lottepitcher
 
End_to_End_DevOps.pptx
End_to_End_DevOps.pptxEnd_to_End_DevOps.pptx
End_to_End_DevOps.pptx
CristianoSouza80853
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
kidtangerine
 

Similar to Staging Drupal 8 31 09 1 3 (20)

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 and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp Bratislava
 
Power of Azure Devops
Power of Azure DevopsPower of Azure Devops
Power of Azure Devops
 
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Building a Drupal Distribution using Features, Drush Make, Installation Profi...Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
 
Drupal security
Drupal securityDrupal security
Drupal security
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security right
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
 
Drupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 versionDrupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 version
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
 
Fluo CICD OpenStack Summit
Fluo CICD OpenStack SummitFluo CICD OpenStack Summit
Fluo CICD OpenStack Summit
 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
 
PowerShellForDBDevelopers
PowerShellForDBDevelopersPowerShellForDBDevelopers
PowerShellForDBDevelopers
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
 
End_to_End_DevOps.pptx
End_to_End_DevOps.pptxEnd_to_End_DevOps.pptx
End_to_End_DevOps.pptx
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
 

More from Drupalcon Paris

The State Of Rdf In Drupal 7
The State Of Rdf In Drupal 7The State Of Rdf In Drupal 7
The State Of Rdf In Drupal 7
Drupalcon Paris
 
Web Typography Fundamentals
Web Typography FundamentalsWeb Typography Fundamentals
Web Typography Fundamentals
Drupalcon Paris
 
Taxonomy Everywhere
Taxonomy EverywhereTaxonomy Everywhere
Taxonomy Everywhere
Drupalcon Paris
 
State Of Drupal September 2009
State Of Drupal September 2009State Of Drupal September 2009
State Of Drupal September 2009
Drupalcon Paris
 
Sketching
SketchingSketching
Sketching
Drupalcon Paris
 
Rd Fa In Drupal
Rd Fa In DrupalRd Fa In Drupal
Rd Fa In Drupal
Drupalcon Paris
 
Localize Drupal Org
Localize Drupal OrgLocalize Drupal Org
Localize Drupal Org
Drupalcon Paris
 
Presentation Edipresse Experience Drupalcon
Presentation Edipresse Experience DrupalconPresentation Edipresse Experience Drupalcon
Presentation Edipresse Experience Drupalcon
Drupalcon Paris
 
Praes
PraesPraes
20minutes Quart
20minutes Quart20minutes Quart
20minutes Quart
Drupalcon Paris
 
Enterprise Sitemanagement 2
Enterprise Sitemanagement 2Enterprise Sitemanagement 2
Enterprise Sitemanagement 2Drupalcon Paris
 
Field Api Drupalcon Paris
Field Api Drupalcon ParisField Api Drupalcon Paris
Field Api Drupalcon Paris
Drupalcon Paris
 
Drupalcon2009 Heuer3
Drupalcon2009 Heuer3Drupalcon2009 Heuer3
Drupalcon2009 Heuer3
Drupalcon Paris
 
Danbri Drupalcon Export
Danbri Drupalcon ExportDanbri Drupalcon Export
Danbri Drupalcon Export
Drupalcon Paris
 
Building Community
Building CommunityBuilding Community
Building Community
Drupalcon Paris
 
How To Contribute To Drupal Drupal - DrupalCon Paris
How To Contribute To Drupal Drupal - DrupalCon ParisHow To Contribute To Drupal Drupal - DrupalCon Paris
How To Contribute To Drupal Drupal - DrupalCon Paris
Drupalcon Paris
 

More from Drupalcon Paris (16)

The State Of Rdf In Drupal 7
The State Of Rdf In Drupal 7The State Of Rdf In Drupal 7
The State Of Rdf In Drupal 7
 
Web Typography Fundamentals
Web Typography FundamentalsWeb Typography Fundamentals
Web Typography Fundamentals
 
Taxonomy Everywhere
Taxonomy EverywhereTaxonomy Everywhere
Taxonomy Everywhere
 
State Of Drupal September 2009
State Of Drupal September 2009State Of Drupal September 2009
State Of Drupal September 2009
 
Sketching
SketchingSketching
Sketching
 
Rd Fa In Drupal
Rd Fa In DrupalRd Fa In Drupal
Rd Fa In Drupal
 
Localize Drupal Org
Localize Drupal OrgLocalize Drupal Org
Localize Drupal Org
 
Presentation Edipresse Experience Drupalcon
Presentation Edipresse Experience DrupalconPresentation Edipresse Experience Drupalcon
Presentation Edipresse Experience Drupalcon
 
Praes
PraesPraes
Praes
 
20minutes Quart
20minutes Quart20minutes Quart
20minutes Quart
 
Enterprise Sitemanagement 2
Enterprise Sitemanagement 2Enterprise Sitemanagement 2
Enterprise Sitemanagement 2
 
Field Api Drupalcon Paris
Field Api Drupalcon ParisField Api Drupalcon Paris
Field Api Drupalcon Paris
 
Drupalcon2009 Heuer3
Drupalcon2009 Heuer3Drupalcon2009 Heuer3
Drupalcon2009 Heuer3
 
Danbri Drupalcon Export
Danbri Drupalcon ExportDanbri Drupalcon Export
Danbri Drupalcon Export
 
Building Community
Building CommunityBuilding Community
Building Community
 
How To Contribute To Drupal Drupal - DrupalCon Paris
How To Contribute To Drupal Drupal - DrupalCon ParisHow To Contribute To Drupal Drupal - DrupalCon Paris
How To Contribute To Drupal Drupal - DrupalCon Paris
 

Staging Drupal 8 31 09 1 3

  • 1. Staging Drupal Managing Your Project in Multiple Environments
  • 2. Introduction • Chris Pliakas – drupal.org: cpliakas – Twitter: @cpliakas • Michelle Lauer – drupal.org: miche – Twitter: @lauermichelle • CommonPlaces e-Solutions, LLC – Twitter: @CommonPlaces – New Hampshire, United States
  • 3. Why are we here • Discuss the challenges with developing a site in multiple environments • Offer some solutions • Goals of our process and tools used across multiple environments – Allow for seamless code integration (syncing) – Increase efficiency of distributing database changes – Minimize downtime and errors while updating the production site
  • 4. Why Stage Drupal? • Websites are becoming increasingly complex. • Transition to traditional software development cycle. • Multiple engineers/designers working on the same project. • Proper staging avoids conflicts, separates development from production.
  • 5. Multiple Environments • Proper staging requires development, QA, and production locations. • Each developer has a separate copy of the application in an isolated location. • Flow is like a pipeline, development → QA → production. • Drupal is portable • How to stage Drupal?
  • 6. Managing Code With Source Control • Source control is essential in the staging process. • Manages changes to the code over time. • We recommend a standard “tags, branches, trunk” repository layout. • We separate core code from project code. • rsync -avC –delete –exclude=dir src/ dst
  • 7. What Files Should Be Under Source Control? • Separate code from user generated content. • Create “templates” for environment specific files. • Store database snapshots? • Update code frequently to prevent conflicts. • Check production for modifications.
  • 8. Porting the Database • Database snapshot and files tied together • Mysqldump, pg_dump, *MyAdmin applications, contributed solutions. • Restore database, clear cache. • Multisite considerations.
  • 9. Code Release Cycle • Developers import snapshot, commit changes. • Changes promoted to QA, tested thoroughly. • Admin steps, adding content tested on QA. • Code is tagged. • Code updated on production, manual changes made again. • Alpha, beta, stable release cycles.
  • 10. Automate Administrative Tasks Through Code • When – Multiple sandboxes needing the same database changes – Phased approach to release features • Why – Easily share changes among sandboxes – Seamlessly add functionality to an active site – Version control
  • 11. A Systematic Approach • Step 1 – Take a database snapshot with Demonstration Site module (drupal.org/project/demo) • Step 2 – Write it down! – Separate out by sub-projects. – Be explicit and exact – For example, installing “Reroute Email”
  • 12. “Admin List” example • ADMIN – [reroute email] • Enable Reroute Email module (admin/build/modules) • Configure Reroute Email (admin/settings/reroute_email) – dev@company.com
  • 13. A Systematic Approach • Step 3 – Choice Time – How long is your admin list? – Would it be faster for you to write a script that all developers can run in their sandboxes and also can be used on production? – What is the best use of time here? – It really is a judgment call. The more you write database update scripts, the faster you become.
  • 14. A Systematic Approach • Benefits of writing an update script – All changes can be accessed in version control and more easily debugged – Test your deployment process several times as part of QA – You write it once and use it in as many environments as you need
  • 15. The “Site Module” • MYSITE.module. • Site specific configurations: hook_form_alter() and hook_nodeapi(). • Use hook_update_N() in MYSITE.install to make database changes across many development environments. • This “site module” is NOT intended to live outside of its site or be installed anywhere other than its site.
  • 16. The “Site Module” • The correct way to work with an install file is that for every update function, you amend the install function so that newly installed modules behave correctly.  • That being said, my recommendations for a MYSITE.install file are to NOT be used for any other module you create – just the “site module”.
  • 17. MYSITE.install • New update function to replicate our “Admin List”. • Configurations saved in the {variable} table. function mymodule_update_N() { $ret = array(); module_rebuild_cache(); $mods = array('reroute_email'); drupal_install_modules($mods); variable_set(REROUTE_EMAIL_ADDRESS, 'mymail@company.com')); return $ret; }
  • 18. Use Drupal Functions • Examples vs direct sql query – variable_set(); – node_submit(); node_save(); • Less error prone – Inserting or updating data – Several tables at once – Lock tables – Serialize data – Clear cache
  • 19. MYSITE.install Examples • 5 development sandboxes, a testing server and production. • 5 critical nodes that you need to add and that must be in every environment. • That would be 35 instances of manually creating a node. How tedious! Especially when you can write it once for everyone.
  • 20. Start Building • You have to do it manually in one sandbox first • Install Node Export – drupal.org/project/node_export • Install Content Copy – drupal.org/project/cck • Create Content Types and Taxonomies. • Link taxonomies to content types either via taxonomy interface or as a CCK field • Create nodes
  • 21. Content Types • Create a folder in your module called “content_types” • Create a file in that folder called “my_type.cck” • Export the type (admin/content/types/export) • Put the contents of this export into your new file. – You don't need <?php
  • 22. Content Types $modulepath = drupal_get_path ('module', 'drupalconparis2009'); $cck_definition_file = $modulepath."/content_types/my_type.cck"; $form_state['values']['type_name'] = '<create>'; $form_state['values']['macro'] = file_get_contents($cck_definition_file); include_once(drupal_get_path('module', 'node') .'/content_types.inc'); include_once(drupal_get_path('module', 'content_copy') .'/content_copy.module'); drupal_execute("content_copy_import_form", $form_state); content_clear_type_cache();
  • 23. Vocabulary $voc = array(); $voc['name'] = 'shuswi'; $voc['description'] = ''; $voc['nodes'] = array('page'=>'page', 'story'=>'story'); $voc['multiple'] = 1; $voc['required'] = 0; $voc['relations'] = 1; $voc['hierarchy'] = 1; $voc['weight'] = 0; taxonomy_save_vocabulary($voc);
  • 24. Terms $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", 'shuswi')); $shuswi[] = 'bipagi'; $shuswi[] = 'jiphobre'; $shuswi[] = 'slid'; foreach ($shuswi as $k=>$v) { $term = array(); $term['vid'] = $vid; $term['name'] = $v; $term['description'] = ""; $term['weight'] = 0; taxonomy_save_term($term); }
  • 25. Exporting Nodes • Create a folder in your module called “nodes” • Create a file in it called nodes_20090904.inc • Go to Administer Content (admin/content/node) • Check the nodes you want to export • Select “Export” from the bulk operation dropdown – This returns an array of your node content • Paste this code in your file – You don't need <?php
  • 26. Importing Nodes //content arrays $modulepath = drupal_get_path ('module','drupalconparis2009'); $nodes_file = $modulepath. "/nodes/nodes_20090904.inc"; eval('$nodes = '.file_get_contents($nodes_file).';'); //save nodes foreach ($nodes as $node_array) { unset($node_array['nid']); unset($node_array['vid']); unset($node_array['#_export_node_encode_object']); unset($node_array['menu']); foreach($node_array['taxonomy'] as $term) { $term = (object)$term; } $node_object = node_submit($node_array); node_save($node_object); }
  • 27. Export Views • Version control because they are no longer in the database • Facilitates multiple sandboxes being in sync • Create a folder in your site module called ‘views’ • Enable Views Export • Export each view individually, create a file called myview_name.inc <?php //your exported code here $views[$view->name] = $view;
  • 28. Views in Code – Site Module function mymodule_views_api() { return array( 'api' => 2, 'path' => drupal_get_path('module',mymodule) . '/views/*.inc', ); } function mymodule_views_default_views() { $path = './'. drupal_get_path('module',mymodule) '/views/*.inc'; foreach (glob($path) as $views_filename) { require_once($views_filename); } return $views; }
  • 29. Register Your New Views • Clear views cache (admin/build/views/tools) – This one tells the site that you have views in code as well – now your previously placed views generated blocks won’t get confused. • “Revert” all the views that you just saved into code. This will remove them from the database. • Clear views cache again – This one ensures that your site is only looking for the views in code.
  • 30. Permissions • Permissions API – drupal.org/project/permissions_api • After all modules have been installed so you know the names of all permissions and roles $permissions = array( 'create mytype content', 'edit own mytype content', 'delete own mytype content', ); permissions_grant_permissions('authenticated user', $permissions);
  • 31. Testing Your Install Script • Take another database snapshot • Reload the fresh database copy you took before you started (without all those administrative changes) • Run your update script – mysite.com/update.php • In the dropdown of your site module, select the N of your script
  • 32. Testing Your Install Script • If there are errors – Debug them and make changes – Reset your database (admin/build/demo/reset) – Run update.php again • Make sure your configurations, taxonomies, content all look as expected. • When your team syncs their code and runs update.php, they will now have a slew of database changes instantly!
  • 33. Recap • Sometimes takes longer to write and test (and reload DB) than to just email a list of admin steps to your development team and repeat on production. • Remember, to be officially correct, all updates should go also go in the install function. That way the module can stand on its own. • CCK types must be in separate file
  • 34. Recap • Must add bottom line to exported view in mymodule/views/myview.inc – $views[$view->name] = $view; • Need two Views functions in your module • Must unset the nid & vid on a node import because node_save looks for an those to determine if it is performing and update or insert • If you get timeout errors, separate your updates into several functions
  • 35. Drupal Tools • Devel: Generate: drupal.org/project/devel • Demonstration Site: drupal.org/project/demo • Node Export: drupal.org/project/node_export • Permissions API: drupal.org/project/permissions_api • Views Export: drupal.org/project/views • CCK: Content Copy: drupal.org/project/cck • Drush: drupal.org/project/drush
  • 36. More Options • Blocks: Follow similar methodology as Content Types by using the form function – block_add_block_form • drupal.org/project/variable_dump • drupal.org/project/exportables • drupal.org/project/transformations • drupal.org/project/migrate • drupal.org/project/deploy • drupal.org/project/autopilot • drupal.org/project/features
  • 37. Questions & Answers • Download this presentation – www.CommonPlaces.com/Resources • Follow the presenters on Twitter – Chris: @CPliakas – Michelle: @LauerMichelle – CommonPlaces: @CommonPlaces
  • 38. Questions & Answers • Download this presentation – www.CommonPlaces.com/Resources • Follow the presenters on Twitter – Chris: @CPliakas – Michelle: @LauerMichelle – CommonPlaces: @CommonPlaces