class DateExampleMigration

  1. cis7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration
  2. cle7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration
  3. elmsmedia7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration
  4. icor7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration
  5. meedjum_blog7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration
  6. mooc7 sites/all/modules/ulmus/date/date_migrate/date_migrate_example/ DateExampleMigration

Migration class to test import of various date fields.


Expanded class hierarchy of DateExampleMigration


Contains filters are case sensitive
Namesort descending Modifiers Type Description
DateExampleMigration::prepareRow public function Transforms the raw migration data into the expected date formats.
DateExampleMigration::__construct public function Sets up the migration.


sites/all/modules/ulmus/date/date_migrate/date_migrate_example/, line 11
Examples and test folder for migration into date fields.

View source
class DateExampleMigration extends XMLMigration {

   * Sets up the migration.
  public function __construct($arguments = array()) {
    $this->description = t('Example migration into date fields');

    $this->map = new MigrateSQLMap($this->machineName, array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Date ID',
    ), MigrateDestinationNode::getKeySchema());

    // Source fields available in the XML file.
    $fields = array(
      'id' => t('Source id'),
      'title' => t('Title'),
      'body' => t('Description'),
      'date' => t('A simple date'),
      'date_range_from' => t('Start value for a date range'),
      'datestamp' => t('Simple datestamp'),
      'datestamp_range_from' => t('Start value for a datestamp range'),
      'datetime' => t('Simple datetime'),
      'datetime_range_from' => t('Start value for a datetime range'),
      'date_repeat' => t('Sample of a repeating date field'),

    // Our test data is in an XML file.
    $xml_folder = drupal_get_path('module', 'date_migrate_example');
    $items_url = $xml_folder . '/date_migrate_example.xml';
    $item_xpath = '/source_data/item';
    $item_ID_xpath = 'id';
    $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
    $this->source = new MigrateSourceMultiItems($items_class, $fields);
    $this->destination = new MigrateDestinationNode('date_migrate_example');

    // Basic fields.
    $this->addFieldMapping('title', 'title')->xpath('title');
    $this->addFieldMapping('body', 'body')->xpath('body');

    // For simple date fields, we just need the xpath.
    $this->addFieldMapping('field_date', 'date')->xpath('date');

    // For date ranges, we add the "end" value in prepareRow() below.
    $this->addFieldMapping('field_date_range', 'date_range_from');
    $this->addFieldMapping('field_date_range:to', 'date_range_to');

    // RRULEs on repeat fields are also done in prepareRow().
    $this->addFieldMapping('field_date_repeat', 'date_repeat');
    $this->addFieldMapping('field_date_repeat:rrule', 'date_repeat_rrule');

    $this->addFieldMapping('field_datestamp', 'datestamp')->xpath('datestamp');
    $this->addFieldMapping('field_datestamp_range', 'datestamp_range_from');
    $this->addFieldMapping('field_datestamp_range:to', 'datestamp_range_to');

    // You can specify a timezone to be applied to all values going into the
    // field (Tokyo is UTC+9, no DST)
    $this->addFieldMapping('field_datetime', 'datetime')->xpath('datetime');

    // You can also get the timezone from the source data - it can be different
    // for each instance of the field. Like To and RRULE values, it is added
    // in prepareRow().
    $this->addFieldMapping('field_datetime_range', 'datetime_range_from');
    $this->addFieldMapping('field_datetime_range:to', 'datetime_range_to');
    $this->addFieldMapping('field_datetime_range:timezone', 'datetime_range_timezone');

    // Unmapped destination fields.

   * Transforms the raw migration data into the expected date formats.
   * An advanced feature of the date field handler is that in addition to the
   * basic (Start) date itself, we can add additional properties like timezone,
   * encapsulating them as JSON.
  public function prepareRow($current_row) {
    // The date range field can have multiple values.
    $current_row->date_range_from = array();
    foreach ($current_row->xml->date_range as $range) {
      $current_row->date_range_from[] = (string) $range->from[0];
      $current_row->date_range_to[] = (string) $range->to[0];

    $current_row->datestamp_range_from = (string) $current_row->xml->datestamp_range->from[0];
    $current_row->datestamp_range_to = (string) $current_row->xml->datestamp_range->to[0];

    $current_row->datetime_range_from = (string) $current_row->xml->datetime_range->from[0];
    $current_row->datetime_range_to = (string) $current_row->xml->datetime_range->to[0];
    $current_row->datetime_range_timezone = (string) $current_row->xml->datetime_range->timezone[0];

    $current_row->date_repeat = (string) $current_row->xml->date_repeat->date[0];
    $current_row->date_repeat_rrule = (string) $current_row->xml->date_repeat->rule[0];
1 string reference to 'DateExampleMigration'
date_migrate_example_migrate_api in sites/all/modules/ulmus/date/date_migrate/date_migrate_example/date_migrate_example.module
Implements hook_migrate_api().



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.