SlideShare a Scribd company logo
Building and Maintaining a
Distribution in Drupal 7 with Features

       Antonio De Marco       Andrea Pescetti


                 http://nuvole.org
                   @nuvoleweb
Nuvole: Our Team
Clients in Europe and USA
Working with Drupal Distributions
Serving International Organizations
Serving International Organizations
Drupal Distributions
Drupal Distribution
A pre-packaged Drupal installation meant to address a
                specific use case.
Popular Distributions
D6




Open Atrium
D6




Managing News
D6




COD
D6




Videola
D6




OpenPublish
D7




OpenPublic
Products are Preconfigured.
        Distributions are Products
Products are Repeatable.
      Distributions are Products
Products Must be Maintained.
          Distributions are Products
Products Need to be Upgraded.
            Distributions are Products
They make things
Minimally   Preconfigured and Repeatable
            What about Installation Pro les?
Building and Maintaining a  Distribution in Drupal 7 with Features
Syntactically, no difference.
    Not all Pro les are Distributions
Pro les              Distributions




Ready to build upon       Ready to use
   Focus on Developers    Focus on Final User
Core              Code                   Con guration
           Modules, Themes, etc...




       +                             +

       Yet it is Drupal
Con guration


Storing Con guration
 ‣   Drupal traditionally stores
     configuration in database.
 ‣   But distributions cannot ship their
     default configuration this way.
Con guration

Con guration in Database:
Major Drawbacks
 ‣   Severe limits on repeatability
     ‣   Database Engine
     ‣   Table prefixes
     ‣   “Dirty” state
Con guration

Con guration in Database:
Major Drawbacks
 ‣   Difficult to upgrade
 ‣   Content and configuration are
     mixed in database
 ‣   Hard to maintain for developers
     ‣   Not ideal for a distributed team
     ‣   Easy to lose control
Store Con guration in Code
Con guration in Code:
Major Bene ts
 ‣   Configuration is generated via
     database-agnostic PHP code
 ‣   Clean installation procedure
 ‣   Clear upgrade path
Con guration in Code:
Major Bene ts
 ‣   Easier to maintain for developers
 ‣   Code can be versioned
 ‣   Conflicts can be solved
 ‣   Content and settings are separated
Building a Distribution
       Packaging the code
Meet...


               Your Drupal Shop Distro




...your distro buddy!
Bootstrap




A Make le to get your code   A Pro le to manage the installation
       Make le                   Installation Pro le
Make le
Core


              Modules
Contributed, Custom, Patched




               Themes



 External Libraries




                   A distribution’s building blocks
drupal.org                 github.com




             example.com
The best way to package code
       Introducing Drush Make
Building and Maintaining a  Distribution in Drupal 7 with Features
Introducing Drush Make

 ‣   A single .info file to describe
     modules, dependencies and
     patches
 ‣   A one-line command to download
     contrib and custom code:
     libraries, modules, themes, etc...
 ‣   A trustworthy reference index for
     your project
Make le close-up
distro.make - drupalissimo.make
distro.make
Package Core and Pro le
; distro.make
; Usage:
; $ drush make distro.make [directory]
;

api = 2
core = 7.x

projects[drupal][type] = core
projects[drupal][version] = "7.7"

; Make system directories configurable to allow tests in profiles/[name]/modules
; http://drupal.org/node/911354
projects[drupal][patch][911354] = http://drupal.org/files/issues/911354.43.patch

; Missing drupal_alter() for text formats and filters
; http://drupal.org/node/903730
projects[drupal][patch][903730] = http://drupal.org/files/issues/drupal.filter-al

; Use vocabulary machine name for permissions
; http://drupal.org/node/995156
projects[drupal][patch][995156] = http://drupal.org/files/issues/995156-5_portabl
$ drush make distro.make drupalissimo

Project information for drupal retrieved.
drupal downloaded from http://ftp.drupal.org/files/projects/drupal-7.7.tar.gz.
drupal patched with 911354.43.patch.
drupal patched with drupal.filter-alter.82.patch.
drupal patched with 995156-5_portable_taxonomy_permissions.patch.
Generated PATCHES.txt file for drupal
Where is my installation pro le?
...

api = 2
core = 7.x

projects[drupal][type] = core
projects[drupal][version] = "7.7"

; Make system directories configurable to allow tests in profiles/[name]/modules
; http://drupal.org/node/911354
projects[drupal][patch][911354] = http://drupal.org/files/issues/911354.43.patch

; Missing drupal_alter() for text formats and filters
; http://drupal.org/node/903730
projects[drupal][patch][903730] = http://drupal.org/files/issues/drupal.filter-al

; Use vocabulary machine name for permissions
; http://drupal.org/node/995156
projects[drupal][patch][995156] = http://drupal.org/files/issues/995156-5_portabl


projects[drupalissimo][type] = profile
projects[drupalissimo][download][type] = git
projects[drupalissimo][download][url] = git://github.com/nuvoleweb/drupalissimo.
$ git clone git@github.com:nuvoleweb/drupalissimo.git drupalissimo
...
$ ls -l drupalissimo
total 16
-rw-r--r-- 1 ademarco staff     1.1K Aug 15 07:59 README.txt
-rw-r--r--@ 1 ademarco staff    1.2K Aug 15 07:58 distro.make
-rw-r--r-- 1 ademarco staff     2.1K Aug 15 07:59 drupalissimo.install
-rw-r--r--@ 1 ademarco staff    498B Aug 15 07:58 drupalissimo.make
-rw-r--r-- 1 ademarco staff     3.2K Aug 15 07:59 drupalissimo.profile
drupalissimo.make
 Package my distribution
api = 2
core = 7.x

; Modules =====================================================================

projects[admin][subdir] = contrib
projects[admin][version] = 2.0-beta3

projects[context][subdir] = contrib
projects[context][version] = 3.0-beta1

...

; Features ====================================================================

projects[drupalissimo_core][type] = module
projects[drupalissimo_core][subdir] = features
projects[drupalissimo_core][download][type] = "git"
projects[drupalissimo_core][download][url] = "git://github.com/nuvoleweb/drupal

projects[drupalissimo_blog][type] = module
projects[drupalissimo_blog][subdir] = features
projects[drupalissimo_blog][download][type] = "git"
projects[drupalissimo_blog][download][url] = "git://github.com/nuvoleweb/drupal
Build Kit
Extendable distribution, reusable .make file
Building and Maintaining a  Distribution in Drupal 7 with Features
; distro.make
;
; $ drush make distro.make [directory]
;

api = 2
core = 7.x

; Include Build Kit distro makefile via URL
includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.

projects[drupalissimo][type] = profile
projects[drupalissimo][download][type] = git
projects[drupalissimo][download][url] = git://github.com/nuvoleweb/drupalissimo.
;
; drupalissimo.make
;

api = 2
core = 7.x

; Include Build Kit install profile makefile via URL
includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.

; Features ====================================================================

projects[drupalissimo_core][type] = module
projects[drupalissimo_core][subdir] = features
projects[drupalissimo_core][download][type] = "git"
projects[drupalissimo_core][download][url] = "git://github.com/nuvoleweb/drupali

projects[drupalissimo_blog][type] = module
projects[drupalissimo_blog][subdir] = features
projects[drupalissimo_blog][download][type] = "git"
projects[drupalissimo_blog][download][url] = "git://github.com/nuvoleweb/drupali
Installation Pro le
Pro les: just like modules

 ‣   An .info file to specify
     dependencies
 ‣   An .install file to perform
     installation tasks and upgrades
 ‣   Fully customizable via .profile files
drupalissimo.info
name = Drupalissimo
core = 7.x
description = Drupalissimo installation profile.

; Core
dependencies[]   =   book
dependencies[]   =   block
dependencies[]   =   contact
dependencies[]   =   dblog
dependencies[]   =   field_ui
dependencies[]   =   file
...

; Contrib
dependencies[] = admin
dependencies[] = colorbox
dependencies[] = ds
...

; Features
dependencies[] = drupalissimo_core
dependencies[] = drupalissimo_blog
drupalissimo.pro le
   A quick APIs overview
/**
 * Implements hook_form_FORM_ID_alter().
 */
function drupalissimo_form_install_configure_form_alter(&$form, $form_state) {

    $form['site_information']['site_name']
         ['#default_value'] = 'Drupalissimo';
    $form['site_information']
         ['site_mail']['#default_value'] = 'info@drupalissimo.com';

    $form['admin_account']['account']
         ['name']['#default_value'] = 'admin';
    $form['admin_account']['account']
         ['mail']['#default_value'] = 'dev@nuvole.org';

    $form['update_notifications']
         ['update_status_module']['#default_value'] = array(1 => FALSE, 2 => FALSE
}
Building and Maintaining a  Distribution in Drupal 7 with Features
/**
  * Implements hook_install_tasks()
  */
function drupalissimo_install_tasks() {
   return array(
      'drupalissimo_create_terms' => array(
         'display_name' => st('Create taxonomy terms'),
      ),
      'drupalissimo_configure_site_features' => array(
         'display_name' => st('Configure site features'),
      ),
   );
}
Building and Maintaining a  Distribution in Drupal 7 with Features
/**
 * Implements hook_install_tasks() callback
 */
function drupalissimo_create_terms() {
  $terms = array();
  $vocabulary = taxonomy_vocabulary_machine_name_load('category');

    $terms[] = 'Solution';
    $terms[] = 'Client';
    $terms[] = 'Use case';

    foreach ($terms as $name) {
      $term = new stdClass();
      $term->vid = $vocabulary->vid;
      $term->name = $name;
      taxonomy_term_save($term);
    }
}
/**
 * Implements hook_install_tasks() callback
 */
function drupalissimo_configure_site_features() {

    // Create user roles
    $role = new stdClass();
    $role->name = 'editor';
    user_role_save($role);

    // Revert features
    $features = features_get_features();
    foreach ($features as $name => $feature) {
      if ($feature->status) {
        features_revert(array($name => array('variable', 'user_permission')));
      }
    }
    cache_clear_all();

    // Enable custom theme
    theme_enable(array('drupalissimo'));
    variable_set('theme_default', 'drupalissimo');
}
Building a Distribution
   Packaging Con guration
Features
The best way to package configuration
Building and Maintaining a  Distribution in Drupal 7 with Features
What is a feature?
‣   A collection of Drupal elements
    which taken together satisfy a
    certain use-case.
‣   A modular piece of functionality for
    a Drupal site.
‣   A way to export configuration into
    PHP code, in the form of a module.
‣   http://drupal.org/project/features
Con guration in Database
Packaged as Features
Creating a Feature
Building and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with Features
It’s all in the feature’s .info le
          Features are Modules
core = "7.x"
description = "Core feature, stuff we need all the time."
dependencies[] = "colorbox"
dependencies[] = "ds"
dependencies[] = "features"
dependencies[] = "insert"
dependencies[] = "markdown"
dependencies[] = "menu"
dependencies[] = "pathauto"
dependencies[] = "strongarm"
dependencies[] = "token"
features[ctools][] = "ds:ds:1"
features[ctools][] = "strongarm:strongarm:1"
features[ds_view_modes][] = "core_small_teaser"
features[filter][] = "core_rich_text"
features[menu_custom][] = "main-menu"
features[menu_links][] = "main-menu:<front>"
features[user_permission][] = "access content"
features[user_permission][] = "use text format core_rich_text"
features[variable][] = "admin_toolbar"
features[variable][] = "date_format_long"
...
Features Boundaries
Package functionalities in a logical way
De ning a Feature boundary

‣   One site, one Feature?
‣   Well you could, but don't do it!
‣   Be modular: divide the site functionality into
    independent pieces
‣   Several Features work together to build a site
Avoiding transversal Features

‣   All site permissions into one Feature?
‣   No: better to bundle permissions with the
    functionality they belong to
‣   Example: if you have a “Blog” Feature, associated
    permissions should be packaged with it
‣   Miscellaneous permissions can be put in a site
    specific feature.
core = "7.x"
name = "Blog"
package = "Features"
description = "Blog for your site."
project = "drupalissimo_blog"

...

features[field][] = "node-blog-body"
features[field][] = "node-blog-field_blog_attachments"
features[field][] = "node-blog-field_blog_image"
features[image][] = "blog-m"
features[image][] = "blog-s"
features[node][] = "blog"
features[user_permission][] = "create blog content"
features[user_permission][] = "delete any blog content"
features[user_permission][] = "edit any blog content"
features[variable][] = "node_options_blog"
features[views_view][] = "blog"
php = "5.2.4"
version = "7.x-1.0-dev"
core = "7.x"
name = "Blog"
package = "Features"
description = "Blog for your site."
project = "drupalissimo_blog"

...

features[field][] = "node-blog-body"
features[field][] = "node-blog-field_blog_attachments"
features[field][] = "node-blog-field_blog_image"
features[image][] = "blog-m"
features[image][] = "blog-s"
features[node][] = "blog"
features[user_permission][] = "create blog content"
features[user_permission][] = "delete any blog content"
features[user_permission][] = "edit any blog content"
features[variable][] = "node_options_blog"
features[views_view][] = "blog"
php = "5.2.4"
version = "7.x-1.0-dev"
Naming conventions
  Using Features Effectively
Building and Maintaining a  Distribution in Drupal 7 with Features
Code namespace



A feature must, to the best of the creator's knowledge,
use a unique code namespace.

Example: `drupalissimo_blog`, not `blog`
Machine name



A feature's machine name need not be unique.

Example: `blog`, `gallery`, `timetracker`
Component namespace



A feature's component namespace need not be unique.
Each component name should be prepended by the
feature machine name whenever possible.

Example: `blog_listing`, not `recent_blog_posts`
Developing a Feature
Feature Update              Feature Revert
    Export the current       Enforce the con guration
con guration into PHP code        from PHP code
How Features work
A closer look to the Code-Driven Development engine
A component can live in database, in code or both.
Features keeps track of it using a component state.
Component states

‣   Default: the object has no database entry or the
    database entry matches the state of the
    component in code.
‣   Overridden: the code is unchanged with respect to
    the latest check but the database object does not
    match the state of the component in code.
‣   Needs review: the previous code state, database
    state, and current code state all differ.
Features keeps a MD5 hash of:

‣   Current code for the component:
    the configuration as currently represented in code by a given feature.

‣   The most recent prior code state that differs
    from the current code state:
    if an svn update changes the configuration of a view, this contains a hash
    of the code as it was before the update.

‣   The "normal" component state:
    the configuration represented by the component as stored in the
    database or the default component, with any changes introduced by
    drupal_alter(), if no database override exists.
Hard and Soft con guration
 What to package into features and what not.
Hard con guration                   Soft con guration
‣   Configuration that is under     ‣   Configuration that is meant
    the distribution developer's       to be overridden by the site
    control (e.g., Views or            administrator (e.g., default
    Contexts)                          theme)

‣   Stored in Features             ‣   Stored in the installation
                                       Profile
‣   Altering it results in an
    overridden feature             ‣   Altering it does not change
                                       the Features state
‣   Upgrade-unsafe
                                   ‣   Upgrade-safe
/**
 * Implements hook_install_tasks() callback
 */
function drupalissimo_configure_site_features() {

    ...

    // Enable custom theme
    theme_enable(array('drupalissimo'));
    variable_set('theme_default', 'drupalissimo');
}




                       drupalissimo.pro le
                 Soft con guration: set default theme
Beyond con guration
 Taxonomy terms and other beasts.
/**
 * Implements hook_install_tasks() callback
 */
function drupalissimo_create_terms() {
  $terms = array();
  $vocabulary = taxonomy_vocabulary_machine_name_load('category');

    $terms[] = 'Solution';
    $terms[] = 'Client';
    $terms[] = 'Use case';

    foreach ($terms as $name) {
      $term = new stdClass();
      $term->vid = $vocabulary->vid;
      $term->name = $name;
      taxonomy_term_save($term);
    }
}



                         drupalissimo.pro le
             Soft con guration: create initial taxonomy terms
A feature can have a .make le too
       Drush Make operates recursively
Building and Maintaining a  Distribution in Drupal 7 with Features
api = 2
core = 7.x

; Modules =====================================================================

projects[colorbox][subdir] = contrib
projects[colorbox][version] = 1.0-beta4

projects[insert][subdir] = contrib
projects[insert][version] = 1.1



; Libraries ===================================================================

libraries[colorbox_library][download][type] = "get"
libraries[colorbox_library][download][url] = "http://colorpowered.com/colorbox/
libraries[colorbox_library][directory_name] = "colorbox"
libraries[colorbox_library][destination] = "libraries"




                       feature_core.make
      A feature can specify where to nd its own dependencies
Be picky in selecting contrib modules


‣   Prefer modules that can export their configuration
    in code.
‣   Otherwise, try and make configuration exportable.
‣   Variables are no problem: Strongarm will help you.
‣   If configuration is in tables (and no numeric IDs are
    around), CTools is your friend.
Maintaining a Distribution
Upgrading, the Drupal Way

‣   Focusing on migrating content is wrong: this is
    Drupal!
‣   Focus on upgrading the underlying platform, like a
    standard Drupal update would do.
‣   All hooks you need for a smooth upgrade are
    readily available in Drupal.
Updating Features
Features are modules.
Use hook_update_N() in the .install file of each
feature to:

 ‣   Manage the feature’s update process.
 ‣   Share changes with your development team.
Updating Distributions
Profiles behave like modules.
Use hook_update_N() in the .install file of the
installation profile to:

 ‣   Manage the distribution’s update process.
 ‣   Enable new features you have added.
 ‣   Handle structural updates.
 ‣   Share changes with your development team.
The Code-Driven Work ow
  Best practices for a distributed team
Your mantra: keep everything in code.
Code-driven work ow
Developer A




                                                         Time
Developer B




                                                         Time




              Start: both Developers run installation.
Code-driven work ow
Developer A




                                                            Time
Developer B




                                                            Time



              Developer A enables Blog feature,
              Developer B does other work on the project.
Pro les behave like modules
Modules can be updated via hook_update_N()
hook_update_N()


/**
  * Enabling Blog feature
  */
function drupalissimo_update_7001() {
   module_enable(array('drupalissimo_blog'));
}




                    drupalissimo.install
Code-driven work ow

              7001
Developer A




                                                        Time
Developer B




                                                        Time



               DevA$ svn ci -m “Enable Blog feature.”
               Developer A commits his changes.
Code-driven work ow

              7001
Developer A




                                                                         Time
Developer B




                                                                         Time



                     DevB$ svn up && drush updatedb -y && drush cc all
                     Developer B updates his local copy
                     and wants to remove a user role.
hook_update_N()

/**
  * Remove editor role
  */
function drupalissimo_update_7002() {
   // Remove user role
   $role = new stdClass();
   $role->name = 'editor';
   user_role_delete($role);
}




                     drupalissimo.install
Code-driven work ow

              7001
Developer A




                                                                Time
Developer B




                     7002

                                                                Time



                      DevB$ svn ci -m “Removing editor role.”
                      Developer B commits his changes.
Code-driven work ow

              7001
Developer A




                                                                           Time
Developer B




                     7002

                                                                           Time



                            Click. Click. Click.
                            DevB$ patch -p0 < admin.patch
                            Click. Click. Click.
                            Developer B adds an OpenID account for admin
                            and patches the Admin module.
hook_update_N()


/**
  * Adding Nuvole OpenID to admin account
  */
function drupalissimo_update_7003() {
   $claimed_id = 'http://admin.myopenid.com/';
   $return_to = url('user/1/openid', array('absolute' => TRUE));
   openid_begin($claimed_id, $return_to);
}




                     drupalissimo.install
drupalissimo.make




;
; Patches
;
projects[admin][patch][] = "http://drupal.org/files/issues/admin.patch"
Code-driven work ow

              7001
Developer A




                                                                               Time
Developer B




                     7002     7003

                                                                               Time



                            DevB$ svn ci -m “Add OpenID for admin. Patching Admin”
                            Developer B commits his changes.
Code-driven work ow

              7001
Developer A




                                                                                Time
Developer B




                     7002   7003

                                                                                Time
                                   Developer C




                                                                                Time

                                      DevC$ svn co http://svn.nuvole.org/drupalissimo
                                      Developer C joins.
hook_update_N() is not enough
Structural updates must go in hook_install() too
Code-driven work ow

                7001
Developer A




                                                   Time
Developer B




                       7002   7003

                                                   Time
                                     Developer C




                                                   Time

              drupalissimo_install()
hook_install()

/**
 * Implementation of hook_install()
 */
function drupalissimo_install() {

    // Add OpenID to admin user.
    $claimed_id = 'http://admin.myopenid.com/';
    $return_to = url('user/1/openid', array('absolute' => TRUE));
    openid_begin($claimed_id, $return_to);
}




                     drupalissimo.install
Code-driven work ow

              7001
Developer A




                                                                                     Time
Developer B




                     7002   7003

                                                                                     Time
                                   Developer C




                                                                                     Time
                                                 Click. Click. Click.
                                                 Developer C installs the project.
Analysis of the upgrade process in popular
               distributions.
       Practical examples from Open Atrium
/**
  * Implementation of hook_install().
  */
function atrium_install() {
   // Add timestamp index to comments table.
   if (db_table_exists('comments')) {
     db_query("ALTER TABLE {comments} ADD INDEX(timestamp)");
   }
   // Add type,nid index to node table. Allows for more efficient joins t
   // og_ancestry when limiting a view by a certain node type.
   if (db_table_exists('node')) {
     db_query("ALTER TABLE {node} ADD KEY type_node (type, nid)");
   }
}
/**
  * Update 6002: Enable new modules.
  */
function atrium_update_6002() {
   drupal_install_modules(array(
     'atrium_groups',
     'atrium_members',
   ));
   return array();
}

/**
  * Update 6003: Fix broken schema version for date_timezone.
  */
function atrium_update_6003() {
   $return = array();
   $status = db_result(db_query("SELECT status FROM {system} WHERE schema
   if ($status) {
     $return[] = update_sql("UPDATE {system} SET schema_version = 5999 WH
   }
   return $return;
}
The Code-Driven development cheatsheet
Building and Maintaining a  Distribution in Drupal 7 with Features
More on Code-Driven development:

       http://nuvole.org/blog
     http://nuvole.org/trainings
What did you think?

Locate this session on the
DrupalCon London website:
http://london2011.drupal.org/conference/schedule
Click the “Take the survey” link

THANK YOU!

More Related Content

PDF
Drupal 8 Configuration Management with Features
PDF
Drupal 8 CMI on a Managed Workflow
PPTX
Drupal 8 deploying
PDF
Advanced Configuration Management with Config Split et al.
PDF
Drupal 7
KEY
Automating Drupal Development: Makefiles, features and beyond
PDF
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
PDF
Configuration Management in Drupal 8: A preview (DrupalCamp Alpe Adria 2014)
Drupal 8 Configuration Management with Features
Drupal 8 CMI on a Managed Workflow
Drupal 8 deploying
Advanced Configuration Management with Config Split et al.
Drupal 7
Automating Drupal Development: Makefiles, features and beyond
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Configuration Management in Drupal 8: A preview (DrupalCamp Alpe Adria 2014)

What's hot (20)

PDF
Drupal 8 - Corso frontend development
PPT
Taking your module from Drupal 6 to Drupal 7
PDF
Configuration Deployment in Drupal 8
PDF
Improving your Drupal 8 development workflow DrupalCampLA
PDF
DDAY2014 - Features per Drupal 8
PDF
Using Puppet - Real World Configuration Management
PPTX
Becoming A Drupal Master Builder
PDF
Getting Into Drupal 8 Configuration
PDF
Cmake kitware
PDF
Ts drupal6 module development v0.2
PDF
Crank Up Your Apps With TorqueBox
PDF
Immutant
PDF
CMake: Improving Software Quality and Process
PPTX
Migrate in Drupal 8
PDF
Drupal 8 Services And Dependency Injection
PDF
Off the Treadmill: Building a Drupal Platform for Your Organization
KEY
Continuous Integration & Drupal
PDF
Drupal Continuous Integration (European Drupal Days 2015)
PDF
Introducing Immutant
PDF
Developing web apps
Drupal 8 - Corso frontend development
Taking your module from Drupal 6 to Drupal 7
Configuration Deployment in Drupal 8
Improving your Drupal 8 development workflow DrupalCampLA
DDAY2014 - Features per Drupal 8
Using Puppet - Real World Configuration Management
Becoming A Drupal Master Builder
Getting Into Drupal 8 Configuration
Cmake kitware
Ts drupal6 module development v0.2
Crank Up Your Apps With TorqueBox
Immutant
CMake: Improving Software Quality and Process
Migrate in Drupal 8
Drupal 8 Services And Dependency Injection
Off the Treadmill: Building a Drupal Platform for Your Organization
Continuous Integration & Drupal
Drupal Continuous Integration (European Drupal Days 2015)
Introducing Immutant
Developing web apps
Ad

Viewers also liked (10)

PPTX
Case Study - Developing Drupal Framework For ePublishing Platform Using Agile...
PDF
Introduction to Drupal features
ODP
Drupal distributions - how to build them
PDF
Build Custom Surveys and Forms Natively in Drupal Gardens
PDF
Drupal and Devops , the Survey Results
ODP
Drupal: My Search for a CMS
PDF
Introduction to Drupal Basics
PDF
Setting the Record Straight: Drupal as an Enterprise Web Content Management S...
PPTX
Drupal end.ppt
PDF
Agile Project Management for PMP's
Case Study - Developing Drupal Framework For ePublishing Platform Using Agile...
Introduction to Drupal features
Drupal distributions - how to build them
Build Custom Surveys and Forms Natively in Drupal Gardens
Drupal and Devops , the Survey Results
Drupal: My Search for a CMS
Introduction to Drupal Basics
Setting the Record Straight: Drupal as an Enterprise Web Content Management S...
Drupal end.ppt
Agile Project Management for PMP's
Ad

Similar to Building and Maintaining a Distribution in Drupal 7 with Features (20)

PDF
Gestione della configurazione in Drupal 8
PDF
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
ZIP
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
PDF
Docman - The swiss army knife for Drupal multisite docroot management and dep...
PDF
Staging Drupal 8 31 09 1 3
PDF
Lean Drupal Repositories with Composer and Drush
PDF
Drupal 8 Configuration Management for you and your team
PDF
Welcome aboard the team
PDF
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
PPTX
drupal ci cd concept cornel univercity.pptx
KEY
Open Atrium (DrupalCon Paris 2009, Day 3)
PDF
Recipes for Drupal distributions
PDF
Drupal 8 - Core and API Changes
PDF
Building a Custom Theme in Drupal 8
PDF
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
PDF
Ansible + Drupal: A Fortuitous DevOps Match
PDF
Drupal 8 improvements for developer productivity php symfony and more
PDF
Modernize Your Drupal Development
PPTX
Display Suite: A Themers Perspective
PDF
Composer Tools & Frameworks for Drupal
Gestione della configurazione in Drupal 8
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Staging Drupal 8 31 09 1 3
Lean Drupal Repositories with Composer and Drush
Drupal 8 Configuration Management for you and your team
Welcome aboard the team
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
drupal ci cd concept cornel univercity.pptx
Open Atrium (DrupalCon Paris 2009, Day 3)
Recipes for Drupal distributions
Drupal 8 - Core and API Changes
Building a Custom Theme in Drupal 8
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Ansible + Drupal: A Fortuitous DevOps Match
Drupal 8 improvements for developer productivity php symfony and more
Modernize Your Drupal Development
Display Suite: A Themers Perspective
Composer Tools & Frameworks for Drupal

More from Nuvole (9)

PDF
The OpenEuropa Initiative
PDF
CMI 2.0 session at Drupal DevDays in Cluj-Napoca
PDF
Introducing the UI Patterns module: use atomic UI components everywhere in Dr...
KEY
Remote Collaboration and Institutional Intranets with Drupal and Open Atrium
KEY
Public Works Monitoring
PDF
Extending and Customizing Open Atrium
PDF
Code driven development: using Features effectively in Drupal 6 and 7
PDF
Features based development workflow
ZIP
First Steps in Drupal Code Driven Development
The OpenEuropa Initiative
CMI 2.0 session at Drupal DevDays in Cluj-Napoca
Introducing the UI Patterns module: use atomic UI components everywhere in Dr...
Remote Collaboration and Institutional Intranets with Drupal and Open Atrium
Public Works Monitoring
Extending and Customizing Open Atrium
Code driven development: using Features effectively in Drupal 6 and 7
Features based development workflow
First Steps in Drupal Code Driven Development

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PPTX
Spectroscopy.pptx food analysis technology
PPTX
A Presentation on Artificial Intelligence
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Assigned Numbers - 2025 - Bluetooth® Document
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Empathic Computing: Creating Shared Understanding
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Spectroscopy.pptx food analysis technology
A Presentation on Artificial Intelligence
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Chapter 3 Spatial Domain Image Processing.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
Assigned Numbers - 2025 - Bluetooth® Document

Building and Maintaining a Distribution in Drupal 7 with Features

  • 1. Building and Maintaining a Distribution in Drupal 7 with Features Antonio De Marco Andrea Pescetti http://nuvole.org @nuvoleweb
  • 4. Working with Drupal Distributions
  • 8. Drupal Distribution A pre-packaged Drupal installation meant to address a specific use case.
  • 16. Products are Preconfigured. Distributions are Products
  • 17. Products are Repeatable. Distributions are Products
  • 18. Products Must be Maintained. Distributions are Products
  • 19. Products Need to be Upgraded. Distributions are Products
  • 20. They make things Minimally Preconfigured and Repeatable What about Installation Pro les?
  • 22. Syntactically, no difference. Not all Pro les are Distributions
  • 23. Pro les Distributions Ready to build upon Ready to use Focus on Developers Focus on Final User
  • 24. Core Code Con guration Modules, Themes, etc... + + Yet it is Drupal
  • 25. Con guration Storing Con guration ‣ Drupal traditionally stores configuration in database. ‣ But distributions cannot ship their default configuration this way.
  • 26. Con guration Con guration in Database: Major Drawbacks ‣ Severe limits on repeatability ‣ Database Engine ‣ Table prefixes ‣ “Dirty” state
  • 27. Con guration Con guration in Database: Major Drawbacks ‣ Difficult to upgrade ‣ Content and configuration are mixed in database ‣ Hard to maintain for developers ‣ Not ideal for a distributed team ‣ Easy to lose control
  • 29. Con guration in Code: Major Bene ts ‣ Configuration is generated via database-agnostic PHP code ‣ Clean installation procedure ‣ Clear upgrade path
  • 30. Con guration in Code: Major Bene ts ‣ Easier to maintain for developers ‣ Code can be versioned ‣ Conflicts can be solved ‣ Content and settings are separated
  • 31. Building a Distribution Packaging the code
  • 32. Meet... Your Drupal Shop Distro ...your distro buddy!
  • 33. Bootstrap A Make le to get your code A Pro le to manage the installation Make le Installation Pro le
  • 35. Core Modules Contributed, Custom, Patched Themes External Libraries A distribution’s building blocks
  • 36. drupal.org github.com example.com
  • 37. The best way to package code Introducing Drush Make
  • 39. Introducing Drush Make ‣ A single .info file to describe modules, dependencies and patches ‣ A one-line command to download contrib and custom code: libraries, modules, themes, etc... ‣ A trustworthy reference index for your project
  • 40. Make le close-up distro.make - drupalissimo.make
  • 42. ; distro.make ; Usage: ; $ drush make distro.make [directory] ; api = 2 core = 7.x projects[drupal][type] = core projects[drupal][version] = "7.7" ; Make system directories configurable to allow tests in profiles/[name]/modules ; http://drupal.org/node/911354 projects[drupal][patch][911354] = http://drupal.org/files/issues/911354.43.patch ; Missing drupal_alter() for text formats and filters ; http://drupal.org/node/903730 projects[drupal][patch][903730] = http://drupal.org/files/issues/drupal.filter-al ; Use vocabulary machine name for permissions ; http://drupal.org/node/995156 projects[drupal][patch][995156] = http://drupal.org/files/issues/995156-5_portabl
  • 43. $ drush make distro.make drupalissimo Project information for drupal retrieved. drupal downloaded from http://ftp.drupal.org/files/projects/drupal-7.7.tar.gz. drupal patched with 911354.43.patch. drupal patched with drupal.filter-alter.82.patch. drupal patched with 995156-5_portable_taxonomy_permissions.patch. Generated PATCHES.txt file for drupal
  • 44. Where is my installation pro le?
  • 45. ... api = 2 core = 7.x projects[drupal][type] = core projects[drupal][version] = "7.7" ; Make system directories configurable to allow tests in profiles/[name]/modules ; http://drupal.org/node/911354 projects[drupal][patch][911354] = http://drupal.org/files/issues/911354.43.patch ; Missing drupal_alter() for text formats and filters ; http://drupal.org/node/903730 projects[drupal][patch][903730] = http://drupal.org/files/issues/drupal.filter-al ; Use vocabulary machine name for permissions ; http://drupal.org/node/995156 projects[drupal][patch][995156] = http://drupal.org/files/issues/995156-5_portabl projects[drupalissimo][type] = profile projects[drupalissimo][download][type] = git projects[drupalissimo][download][url] = git://github.com/nuvoleweb/drupalissimo.
  • 46. $ git clone [email protected]:nuvoleweb/drupalissimo.git drupalissimo ... $ ls -l drupalissimo total 16 -rw-r--r-- 1 ademarco staff 1.1K Aug 15 07:59 README.txt -rw-r--r--@ 1 ademarco staff 1.2K Aug 15 07:58 distro.make -rw-r--r-- 1 ademarco staff 2.1K Aug 15 07:59 drupalissimo.install -rw-r--r--@ 1 ademarco staff 498B Aug 15 07:58 drupalissimo.make -rw-r--r-- 1 ademarco staff 3.2K Aug 15 07:59 drupalissimo.profile
  • 48. api = 2 core = 7.x ; Modules ===================================================================== projects[admin][subdir] = contrib projects[admin][version] = 2.0-beta3 projects[context][subdir] = contrib projects[context][version] = 3.0-beta1 ... ; Features ==================================================================== projects[drupalissimo_core][type] = module projects[drupalissimo_core][subdir] = features projects[drupalissimo_core][download][type] = "git" projects[drupalissimo_core][download][url] = "git://github.com/nuvoleweb/drupal projects[drupalissimo_blog][type] = module projects[drupalissimo_blog][subdir] = features projects[drupalissimo_blog][download][type] = "git" projects[drupalissimo_blog][download][url] = "git://github.com/nuvoleweb/drupal
  • 49. Build Kit Extendable distribution, reusable .make file
  • 51. ; distro.make ; ; $ drush make distro.make [directory] ; api = 2 core = 7.x ; Include Build Kit distro makefile via URL includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7. projects[drupalissimo][type] = profile projects[drupalissimo][download][type] = git projects[drupalissimo][download][url] = git://github.com/nuvoleweb/drupalissimo.
  • 52. ; ; drupalissimo.make ; api = 2 core = 7.x ; Include Build Kit install profile makefile via URL includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7. ; Features ==================================================================== projects[drupalissimo_core][type] = module projects[drupalissimo_core][subdir] = features projects[drupalissimo_core][download][type] = "git" projects[drupalissimo_core][download][url] = "git://github.com/nuvoleweb/drupali projects[drupalissimo_blog][type] = module projects[drupalissimo_blog][subdir] = features projects[drupalissimo_blog][download][type] = "git" projects[drupalissimo_blog][download][url] = "git://github.com/nuvoleweb/drupali
  • 54. Pro les: just like modules ‣ An .info file to specify dependencies ‣ An .install file to perform installation tasks and upgrades ‣ Fully customizable via .profile files
  • 56. name = Drupalissimo core = 7.x description = Drupalissimo installation profile. ; Core dependencies[] = book dependencies[] = block dependencies[] = contact dependencies[] = dblog dependencies[] = field_ui dependencies[] = file ... ; Contrib dependencies[] = admin dependencies[] = colorbox dependencies[] = ds ... ; Features dependencies[] = drupalissimo_core dependencies[] = drupalissimo_blog
  • 57. drupalissimo.pro le A quick APIs overview
  • 58. /** * Implements hook_form_FORM_ID_alter(). */ function drupalissimo_form_install_configure_form_alter(&$form, $form_state) { $form['site_information']['site_name'] ['#default_value'] = 'Drupalissimo'; $form['site_information'] ['site_mail']['#default_value'] = '[email protected]'; $form['admin_account']['account'] ['name']['#default_value'] = 'admin'; $form['admin_account']['account'] ['mail']['#default_value'] = '[email protected]'; $form['update_notifications'] ['update_status_module']['#default_value'] = array(1 => FALSE, 2 => FALSE }
  • 60. /** * Implements hook_install_tasks() */ function drupalissimo_install_tasks() { return array( 'drupalissimo_create_terms' => array( 'display_name' => st('Create taxonomy terms'), ), 'drupalissimo_configure_site_features' => array( 'display_name' => st('Configure site features'), ), ); }
  • 62. /** * Implements hook_install_tasks() callback */ function drupalissimo_create_terms() { $terms = array(); $vocabulary = taxonomy_vocabulary_machine_name_load('category'); $terms[] = 'Solution'; $terms[] = 'Client'; $terms[] = 'Use case'; foreach ($terms as $name) { $term = new stdClass(); $term->vid = $vocabulary->vid; $term->name = $name; taxonomy_term_save($term); } }
  • 63. /** * Implements hook_install_tasks() callback */ function drupalissimo_configure_site_features() { // Create user roles $role = new stdClass(); $role->name = 'editor'; user_role_save($role); // Revert features $features = features_get_features(); foreach ($features as $name => $feature) { if ($feature->status) { features_revert(array($name => array('variable', 'user_permission'))); } } cache_clear_all(); // Enable custom theme theme_enable(array('drupalissimo')); variable_set('theme_default', 'drupalissimo'); }
  • 64. Building a Distribution Packaging Con guration
  • 65. Features The best way to package configuration
  • 67. What is a feature? ‣ A collection of Drupal elements which taken together satisfy a certain use-case. ‣ A modular piece of functionality for a Drupal site. ‣ A way to export configuration into PHP code, in the form of a module. ‣ http://drupal.org/project/features
  • 68. Con guration in Database
  • 73. It’s all in the feature’s .info le Features are Modules
  • 74. core = "7.x" description = "Core feature, stuff we need all the time." dependencies[] = "colorbox" dependencies[] = "ds" dependencies[] = "features" dependencies[] = "insert" dependencies[] = "markdown" dependencies[] = "menu" dependencies[] = "pathauto" dependencies[] = "strongarm" dependencies[] = "token" features[ctools][] = "ds:ds:1" features[ctools][] = "strongarm:strongarm:1" features[ds_view_modes][] = "core_small_teaser" features[filter][] = "core_rich_text" features[menu_custom][] = "main-menu" features[menu_links][] = "main-menu:<front>" features[user_permission][] = "access content" features[user_permission][] = "use text format core_rich_text" features[variable][] = "admin_toolbar" features[variable][] = "date_format_long" ...
  • 76. De ning a Feature boundary ‣ One site, one Feature? ‣ Well you could, but don't do it! ‣ Be modular: divide the site functionality into independent pieces ‣ Several Features work together to build a site
  • 77. Avoiding transversal Features ‣ All site permissions into one Feature? ‣ No: better to bundle permissions with the functionality they belong to ‣ Example: if you have a “Blog” Feature, associated permissions should be packaged with it ‣ Miscellaneous permissions can be put in a site specific feature.
  • 78. core = "7.x" name = "Blog" package = "Features" description = "Blog for your site." project = "drupalissimo_blog" ... features[field][] = "node-blog-body" features[field][] = "node-blog-field_blog_attachments" features[field][] = "node-blog-field_blog_image" features[image][] = "blog-m" features[image][] = "blog-s" features[node][] = "blog" features[user_permission][] = "create blog content" features[user_permission][] = "delete any blog content" features[user_permission][] = "edit any blog content" features[variable][] = "node_options_blog" features[views_view][] = "blog" php = "5.2.4" version = "7.x-1.0-dev"
  • 79. core = "7.x" name = "Blog" package = "Features" description = "Blog for your site." project = "drupalissimo_blog" ... features[field][] = "node-blog-body" features[field][] = "node-blog-field_blog_attachments" features[field][] = "node-blog-field_blog_image" features[image][] = "blog-m" features[image][] = "blog-s" features[node][] = "blog" features[user_permission][] = "create blog content" features[user_permission][] = "delete any blog content" features[user_permission][] = "edit any blog content" features[variable][] = "node_options_blog" features[views_view][] = "blog" php = "5.2.4" version = "7.x-1.0-dev"
  • 80. Naming conventions Using Features Effectively
  • 82. Code namespace A feature must, to the best of the creator's knowledge, use a unique code namespace. Example: `drupalissimo_blog`, not `blog`
  • 83. Machine name A feature's machine name need not be unique. Example: `blog`, `gallery`, `timetracker`
  • 84. Component namespace A feature's component namespace need not be unique. Each component name should be prepended by the feature machine name whenever possible. Example: `blog_listing`, not `recent_blog_posts`
  • 86. Feature Update Feature Revert Export the current Enforce the con guration con guration into PHP code from PHP code
  • 87. How Features work A closer look to the Code-Driven Development engine
  • 88. A component can live in database, in code or both. Features keeps track of it using a component state.
  • 89. Component states ‣ Default: the object has no database entry or the database entry matches the state of the component in code. ‣ Overridden: the code is unchanged with respect to the latest check but the database object does not match the state of the component in code. ‣ Needs review: the previous code state, database state, and current code state all differ.
  • 90. Features keeps a MD5 hash of: ‣ Current code for the component: the configuration as currently represented in code by a given feature. ‣ The most recent prior code state that differs from the current code state: if an svn update changes the configuration of a view, this contains a hash of the code as it was before the update. ‣ The "normal" component state: the configuration represented by the component as stored in the database or the default component, with any changes introduced by drupal_alter(), if no database override exists.
  • 91. Hard and Soft con guration What to package into features and what not.
  • 92. Hard con guration Soft con guration ‣ Configuration that is under ‣ Configuration that is meant the distribution developer's to be overridden by the site control (e.g., Views or administrator (e.g., default Contexts) theme) ‣ Stored in Features ‣ Stored in the installation Profile ‣ Altering it results in an overridden feature ‣ Altering it does not change the Features state ‣ Upgrade-unsafe ‣ Upgrade-safe
  • 93. /** * Implements hook_install_tasks() callback */ function drupalissimo_configure_site_features() { ... // Enable custom theme theme_enable(array('drupalissimo')); variable_set('theme_default', 'drupalissimo'); } drupalissimo.pro le Soft con guration: set default theme
  • 94. Beyond con guration Taxonomy terms and other beasts.
  • 95. /** * Implements hook_install_tasks() callback */ function drupalissimo_create_terms() { $terms = array(); $vocabulary = taxonomy_vocabulary_machine_name_load('category'); $terms[] = 'Solution'; $terms[] = 'Client'; $terms[] = 'Use case'; foreach ($terms as $name) { $term = new stdClass(); $term->vid = $vocabulary->vid; $term->name = $name; taxonomy_term_save($term); } } drupalissimo.pro le Soft con guration: create initial taxonomy terms
  • 96. A feature can have a .make le too Drush Make operates recursively
  • 98. api = 2 core = 7.x ; Modules ===================================================================== projects[colorbox][subdir] = contrib projects[colorbox][version] = 1.0-beta4 projects[insert][subdir] = contrib projects[insert][version] = 1.1 ; Libraries =================================================================== libraries[colorbox_library][download][type] = "get" libraries[colorbox_library][download][url] = "http://colorpowered.com/colorbox/ libraries[colorbox_library][directory_name] = "colorbox" libraries[colorbox_library][destination] = "libraries" feature_core.make A feature can specify where to nd its own dependencies
  • 99. Be picky in selecting contrib modules ‣ Prefer modules that can export their configuration in code. ‣ Otherwise, try and make configuration exportable. ‣ Variables are no problem: Strongarm will help you. ‣ If configuration is in tables (and no numeric IDs are around), CTools is your friend.
  • 101. Upgrading, the Drupal Way ‣ Focusing on migrating content is wrong: this is Drupal! ‣ Focus on upgrading the underlying platform, like a standard Drupal update would do. ‣ All hooks you need for a smooth upgrade are readily available in Drupal.
  • 102. Updating Features Features are modules. Use hook_update_N() in the .install file of each feature to: ‣ Manage the feature’s update process. ‣ Share changes with your development team.
  • 103. Updating Distributions Profiles behave like modules. Use hook_update_N() in the .install file of the installation profile to: ‣ Manage the distribution’s update process. ‣ Enable new features you have added. ‣ Handle structural updates. ‣ Share changes with your development team.
  • 104. The Code-Driven Work ow Best practices for a distributed team
  • 105. Your mantra: keep everything in code.
  • 106. Code-driven work ow Developer A Time Developer B Time Start: both Developers run installation.
  • 107. Code-driven work ow Developer A Time Developer B Time Developer A enables Blog feature, Developer B does other work on the project.
  • 108. Pro les behave like modules Modules can be updated via hook_update_N()
  • 109. hook_update_N() /** * Enabling Blog feature */ function drupalissimo_update_7001() { module_enable(array('drupalissimo_blog')); } drupalissimo.install
  • 110. Code-driven work ow 7001 Developer A Time Developer B Time DevA$ svn ci -m “Enable Blog feature.” Developer A commits his changes.
  • 111. Code-driven work ow 7001 Developer A Time Developer B Time DevB$ svn up && drush updatedb -y && drush cc all Developer B updates his local copy and wants to remove a user role.
  • 112. hook_update_N() /** * Remove editor role */ function drupalissimo_update_7002() { // Remove user role $role = new stdClass(); $role->name = 'editor'; user_role_delete($role); } drupalissimo.install
  • 113. Code-driven work ow 7001 Developer A Time Developer B 7002 Time DevB$ svn ci -m “Removing editor role.” Developer B commits his changes.
  • 114. Code-driven work ow 7001 Developer A Time Developer B 7002 Time Click. Click. Click. DevB$ patch -p0 < admin.patch Click. Click. Click. Developer B adds an OpenID account for admin and patches the Admin module.
  • 115. hook_update_N() /** * Adding Nuvole OpenID to admin account */ function drupalissimo_update_7003() { $claimed_id = 'http://admin.myopenid.com/'; $return_to = url('user/1/openid', array('absolute' => TRUE)); openid_begin($claimed_id, $return_to); } drupalissimo.install
  • 116. drupalissimo.make ; ; Patches ; projects[admin][patch][] = "http://drupal.org/files/issues/admin.patch"
  • 117. Code-driven work ow 7001 Developer A Time Developer B 7002 7003 Time DevB$ svn ci -m “Add OpenID for admin. Patching Admin” Developer B commits his changes.
  • 118. Code-driven work ow 7001 Developer A Time Developer B 7002 7003 Time Developer C Time DevC$ svn co http://svn.nuvole.org/drupalissimo Developer C joins.
  • 119. hook_update_N() is not enough Structural updates must go in hook_install() too
  • 120. Code-driven work ow 7001 Developer A Time Developer B 7002 7003 Time Developer C Time drupalissimo_install()
  • 121. hook_install() /** * Implementation of hook_install() */ function drupalissimo_install() { // Add OpenID to admin user. $claimed_id = 'http://admin.myopenid.com/'; $return_to = url('user/1/openid', array('absolute' => TRUE)); openid_begin($claimed_id, $return_to); } drupalissimo.install
  • 122. Code-driven work ow 7001 Developer A Time Developer B 7002 7003 Time Developer C Time Click. Click. Click. Developer C installs the project.
  • 123. Analysis of the upgrade process in popular distributions. Practical examples from Open Atrium
  • 124. /** * Implementation of hook_install(). */ function atrium_install() { // Add timestamp index to comments table. if (db_table_exists('comments')) { db_query("ALTER TABLE {comments} ADD INDEX(timestamp)"); } // Add type,nid index to node table. Allows for more efficient joins t // og_ancestry when limiting a view by a certain node type. if (db_table_exists('node')) { db_query("ALTER TABLE {node} ADD KEY type_node (type, nid)"); } }
  • 125. /** * Update 6002: Enable new modules. */ function atrium_update_6002() { drupal_install_modules(array( 'atrium_groups', 'atrium_members', )); return array(); } /** * Update 6003: Fix broken schema version for date_timezone. */ function atrium_update_6003() { $return = array(); $status = db_result(db_query("SELECT status FROM {system} WHERE schema if ($status) { $return[] = update_sql("UPDATE {system} SET schema_version = 5999 WH } return $return; }
  • 128. More on Code-Driven development: http://nuvole.org/blog http://nuvole.org/trainings
  • 129. What did you think? Locate this session on the DrupalCon London website: http://london2011.drupal.org/conference/schedule Click the “Take the survey” link THANK YOU!