Community Documentation

Less commonly implemented Migration methods

Last updated May 4, 2012. Created by bleedev on November 16, 2011.
Edited by twom, mikeryan, dale42, mgifford. Log in to edit this page.

pre/post Import/Rollback methods

You can execute code before or after an import or rollback operation by implementing the Migration class methods preImport(), postImport(), preRollback(), or postRollback(). Each of these is called once per individual Migration - that is, if you implement preImport() in an article node migration class, it will be called after any previous migrations you've defined, and immediately before the first row of your article node migration is called.

Typical actions can be the enabling / disabling of certain modules or changing configurations.

<?php
class ArticleMigration implements Migration {
...
  public function
preImport() {
   
parent::preImport();
   
// Code to execute before first article row is imported
 
}
...
  public function
postImport() {
   
parent::postImport();
   
// Code to execute after the last article row has been imported
 
}
...
  public function
preRollback() {
   
parent::preRollback();
   
// Code to execute before first article row is deleted
 
}
...
  public function
postRollback() {
   
parent::postRollback();
   
// Code to execute after the last article row has been deleted
 
}
?>

A practical example can be found here.

NOTE: If you are running your migrations through the web UI, which chunks the work into batches, if a given migration takes long enough to be broken into separate batches, these functions will be called for each batch.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Programmers
Keywords
import, migration, rollback

Administration & Security Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here