FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Support for migration into Date fields.
|
||||
*/
|
||||
|
||||
class DateMigrateFieldHandler extends MigrateFieldHandler {
|
||||
|
||||
/**
|
||||
* Declares the types of fields used.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->registerTypes(array('date', 'datestamp', 'datetime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments for a date field migration.
|
||||
*
|
||||
* @param string $timezone
|
||||
* Timezone (such as UTC, America/New_York, etc.) to apply.
|
||||
* @param string $timezone_db
|
||||
* Timezone_db value for the field.
|
||||
* @param string $rrule
|
||||
* Rule string for a repeating date field.
|
||||
* @param string $language
|
||||
* Language of the text (defaults to destination language)
|
||||
*
|
||||
* @return array
|
||||
* An array of the defined variables in this scope.
|
||||
*/
|
||||
static function arguments($timezone = 'UTC', $timezone_db = 'UTC', $rrule = NULL, $language = NULL) {
|
||||
return get_defined_vars();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts incoming data into the proper field arrays for Date fields.
|
||||
*
|
||||
* @param object $entity
|
||||
* The destination entity which will hold the field arrays.
|
||||
* @param array $field_info
|
||||
* Metadata for the date field being populated.
|
||||
* @param array $instance
|
||||
* Metadata for this instance of the date field being populated.
|
||||
* @param array $values
|
||||
* Array of date values to be fielded.
|
||||
*
|
||||
* @return array|null
|
||||
* An array of date fields.
|
||||
*/
|
||||
public function prepare($entity, array $field_info, array $instance, array $values) {
|
||||
if (isset($values['arguments'])) {
|
||||
$arguments = $values['arguments'];
|
||||
unset($values['arguments']);
|
||||
}
|
||||
else {
|
||||
$arguments = array();
|
||||
}
|
||||
|
||||
if (isset($arguments['timezone'])) {
|
||||
$default_timezone = $arguments['timezone'];
|
||||
}
|
||||
else {
|
||||
$default_timezone = 'UTC';
|
||||
}
|
||||
if (isset($arguments['timezone_db'])) {
|
||||
$default_timezone_db = $arguments['timezone_db'];
|
||||
}
|
||||
else {
|
||||
$default_timezone_db = NULL;
|
||||
}
|
||||
if (isset($arguments['rrule'])) {
|
||||
$default_rrule = $arguments['rrule'];
|
||||
}
|
||||
else {
|
||||
$default_rrule = NULL;
|
||||
}
|
||||
$language = $this->getFieldLanguage($entity, $field_info, $arguments);
|
||||
|
||||
// Setup the standard Field API array for saving.
|
||||
$delta = 0;
|
||||
foreach ($values as $from) {
|
||||
// Set defaults.
|
||||
$to = NULL;
|
||||
$timezone = $default_timezone;
|
||||
$timezone_db = $default_timezone_db;
|
||||
$rrule = $default_rrule;
|
||||
|
||||
// Is the value a straight datetime value, or JSON containing a set of
|
||||
// properties?
|
||||
if (!empty($from) && $from{0} == '{') {
|
||||
$properties = drupal_json_decode($from);
|
||||
$from = $properties['from'];
|
||||
// Properties passed in with the date override any set via arguments.
|
||||
if (!empty($properties['to'])) {
|
||||
$to = $properties['to'];
|
||||
}
|
||||
if (!empty($properties['timezone'])) {
|
||||
$timezone = $properties['timezone'];
|
||||
}
|
||||
if (!empty($properties['timezone_db'])) {
|
||||
$timezone_db = $properties['timezone_db'];
|
||||
}
|
||||
if (!empty($properties['rrule'])) {
|
||||
$rrule = $properties['rrule'];
|
||||
}
|
||||
}
|
||||
|
||||
// Missing data? Create an empty value and return;
|
||||
// Don't try to turn the empty value into a bogus
|
||||
// timestamp for 'now'.
|
||||
if (empty($from)) {
|
||||
$return[$language][$delta]['value'] = NULL;
|
||||
if (!empty($field_info['settings']['todate'])) {
|
||||
$return[$language][$delta]['value2'] = NULL;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
// If there is no 'to' date, just use the 'from' date.
|
||||
if (!empty($field_info['settings']['todate']) && empty($to)) {
|
||||
$to = $from;
|
||||
}
|
||||
|
||||
// If we have a value, work from a timestamp.
|
||||
$from = MigrationBase::timestamp($from);
|
||||
if ($to) {
|
||||
$to = MigrationBase::timestamp($to);
|
||||
}
|
||||
|
||||
// What does the destination field expect?
|
||||
switch ($field_info['type']) {
|
||||
case 'datestamp':
|
||||
// Already done.
|
||||
break;
|
||||
case 'datetime':
|
||||
// YYYY-MM-DD HH:MM:SS.
|
||||
$from = format_date($from, 'custom', 'Y-m-d H:i:s', $timezone);
|
||||
if ($to) {
|
||||
$to = format_date($to, 'custom', 'Y-m-d H:i:s', $timezone);
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
// ISO date: YYYY-MM-DDTHH:MM:SS.
|
||||
$from = format_date($from, 'custom', 'Y-m-d\TH:i:s', $timezone);
|
||||
if ($to) {
|
||||
$to = format_date($to, 'custom', 'Y-m-d\TH:i:s', $timezone);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle repeats, coming in as RRULEs. Many field instances may be
|
||||
// created.
|
||||
if (function_exists('date_repeat_build_dates') && !empty($field_info['settings']['repeat']) && $rrule) {
|
||||
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_api') . '/date_api_ical.inc';
|
||||
$item = array('value' => $from, 'value2' => $to, 'timezone' => $timezone);
|
||||
// Can be de-uglified when http://drupal.org/node/1159404 is committed.
|
||||
$return[$language] = date_repeat_build_dates(NULL, date_ical_parse_rrule($field_info, $rrule), $field_info, $item);
|
||||
}
|
||||
else {
|
||||
$return[$language][$delta]['value'] = $from;
|
||||
if (!empty($to)) {
|
||||
$return[$language][$delta]['value2'] = $to;
|
||||
}
|
||||
}
|
||||
$delta++;
|
||||
}
|
||||
if (!isset($return)) {
|
||||
$return = NULL;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
name = Date Migration
|
||||
description = Provides support for importing into date fields with the Migrate module.
|
||||
core = 7.x
|
||||
package = Date/Time
|
||||
|
||||
dependencies[] = migrate
|
||||
dependencies[] = date
|
||||
files[] = date.migrate.inc
|
||||
files[] = date_migrate.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-08-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "date"
|
||||
datestamp = "1344850024"
|
||||
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Migration integration for Date Migrate.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_api().
|
||||
*/
|
||||
function date_migrate_migrate_api() {
|
||||
$api = array(
|
||||
'api' => 2,
|
||||
);
|
||||
return $api;
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test for using date fields with Migrate module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test date migration.
|
||||
*/
|
||||
class DateMigrateExampleUnitTest extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* Provides information about this test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Date2 migration',
|
||||
'description' => 'Testing migration of date fields',
|
||||
'group' => 'Migrate',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declars the module dependencies for the test.
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp('migrate', 'features', 'date', 'date_repeat', 'date_repeat_field', 'date_migrate_example');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that date fields are imported correctly. When no timezone is
|
||||
* explicitly provided with the source data, we want the displayed time on the
|
||||
* Drupal site to match that in the source data. To validate that, we make
|
||||
* sure we have set a consistent timezone at the PHP and Drupal levels, and
|
||||
* that the format used on the page is not locale-dependent (no day or month
|
||||
* names). Then, we can just look for the desired date/time strings in the
|
||||
* node page.
|
||||
*/
|
||||
function testDateImport() {
|
||||
date_default_timezone_set('America/Los_Angeles');
|
||||
variable_set('date_default_timezone', 'America/Los_Angeles');
|
||||
variable_set('date_format_medium', 'Y-m-d H:i');
|
||||
$migration = Migration::getInstance('DateExample');
|
||||
$result = $migration->processImport();
|
||||
$this->assertEqual($result, Migration::RESULT_COMPLETED, t('Variety term import returned RESULT_COMPLETED'));
|
||||
$rawnodes = node_load_multiple(FALSE, array('type' => 'date_migrate_example'), TRUE);
|
||||
$this->assertEqual(count($rawnodes), 2, t('Two sample nodes created'));
|
||||
$node = reset($rawnodes);
|
||||
$this->drupalGet('/node/' . $node->nid);
|
||||
$this->assertText('2011-05-12 19:43', t('Simple date field found'));
|
||||
$this->assertText('2011-06-13 18:32 to 2011-07-23 10:32', t('Date range field found'));
|
||||
$this->assertText('2011-07-22 12:13', t('Datestamp field found'));
|
||||
$this->assertText('2011-08-01 00:00 to 2011-09-01 00:00', t('Datestamp range field found'));
|
||||
$this->assertText('2011-11-18 15:00', t('Datetime field with +9 timezone found'));
|
||||
$this->assertText('2011-10-30 14:43 to 2011-12-31 17:59', t('Datetime range field with -5 timezone found'));
|
||||
$this->assertText('2011-11-25 09:01', t('First date repeat instance found'));
|
||||
$this->assertText('2011-12-09 09:01', t('Second date repeat instance found'));
|
||||
$this->assertNoText('2011-12-23 09:01', t('Skipped date repeat instance not found'));
|
||||
$this->assertText('2012-05-11 09:01', t('Last date repeat instance found'));
|
||||
$node = next($rawnodes);
|
||||
$this->drupalGet('/node/' . $node->nid);
|
||||
$this->assertText('2012-06-21 15:32', t('First date value found'));
|
||||
$this->assertText('2012-12-02 11:08', t('Second date value found'));
|
||||
$this->assertText('2004-02-03 01:15', t('Start for first date range found'));
|
||||
$this->assertText('2005-03-04 22:11', t('End for first date range found'));
|
||||
$this->assertText('2014-09-01 17:21', t('Start for second date range found'));
|
||||
$this->assertText('2015-12-23 00:01', t('End for first second range found'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,680 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Examples and test folder for migration into date fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_default_fields().
|
||||
*/
|
||||
function date_migrate_example_field_default_fields() {
|
||||
$fields = array();
|
||||
|
||||
// Exported field: 'node-date_migrate_example-body'
|
||||
$fields['node-date_migrate_example-body'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(
|
||||
'0' => 'node',
|
||||
),
|
||||
'field_name' => 'body',
|
||||
'foreign keys' => array(
|
||||
'format' => array(
|
||||
'columns' => array(
|
||||
'format' => 'format',
|
||||
),
|
||||
'table' => 'filter_format',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'format' => array(
|
||||
'0' => 'format',
|
||||
),
|
||||
),
|
||||
'module' => 'text',
|
||||
'settings' => array(),
|
||||
'translatable' => '1',
|
||||
'type' => 'text_with_summary',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'default_value' => NULL,
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'hidden',
|
||||
'module' => 'text',
|
||||
'settings' => array(),
|
||||
'type' => 'text_default',
|
||||
'weight' => '0',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'hidden',
|
||||
'module' => 'text',
|
||||
'settings' => array(
|
||||
'trim_length' => 600,
|
||||
),
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'body',
|
||||
'label' => 'Body',
|
||||
'required' => FALSE,
|
||||
'settings' => array(
|
||||
'display_summary' => TRUE,
|
||||
'text_processing' => 1,
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'module' => 'text',
|
||||
'settings' => array(
|
||||
'rows' => 20,
|
||||
'summary_rows' => 5,
|
||||
),
|
||||
'type' => 'text_textarea_with_summary',
|
||||
'weight' => '1',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_date'
|
||||
$fields['node-date_migrate_example-field_date'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '-1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_date',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => '',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'date',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '1',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_date',
|
||||
'label' => 'Date',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'blank',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text',
|
||||
'weight' => '2',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_date_range'
|
||||
$fields['node-date_migrate_example-field_date_range'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '-1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_date_range',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => 'required',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'date',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '2',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_date_range',
|
||||
'label' => 'Date range',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'strtotime',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '+7 days',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text',
|
||||
'weight' => '3',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_date_repeat'
|
||||
$fields['node-date_migrate_example-field_date_repeat'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '-1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_date_repeat',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 1,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => '',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'date',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '7',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_date_repeat',
|
||||
'label' => 'Date with repeat',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'blank',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '',
|
||||
'repeat_collapsed' => '0',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text_repeat',
|
||||
'weight' => '8',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_datestamp'
|
||||
$fields['node-date_migrate_example-field_datestamp'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_datestamp',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => '',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'datestamp',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '3',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_datestamp',
|
||||
'label' => 'Datestamp',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'blank',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text',
|
||||
'weight' => '4',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-migrate_example_date-field_datestamp_range'
|
||||
$fields['node-date_migrate_example-field_datestamp_range'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_datestamp_range',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => 'optional',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'datestamp',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '4',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_datestamp_range',
|
||||
'label' => 'Datestamp range',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'strtotime',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '+3 months',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => '1',
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_select',
|
||||
'weight' => '5',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_datetime'
|
||||
$fields['node-date_migrate_example-field_datetime'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_datetime',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => '',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'datetime',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '5',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_datetime',
|
||||
'label' => 'Datetime',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'blank',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text',
|
||||
'weight' => '6',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Exported field: 'node-date_migrate_example-field_datetime_range'
|
||||
$fields['node-date_migrate_example-field_datetime_range'] = array(
|
||||
'field_config' => array(
|
||||
'active' => '1',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_datetime_range',
|
||||
'foreign keys' => array(),
|
||||
'indexes' => array(),
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'granularity' => array(
|
||||
'day' => 'day',
|
||||
'hour' => 'hour',
|
||||
'minute' => 'minute',
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
),
|
||||
'repeat' => 0,
|
||||
'timezone_db' => 'UTC',
|
||||
'todate' => 'required',
|
||||
'tz_handling' => 'site',
|
||||
),
|
||||
'translatable' => '1',
|
||||
'type' => 'datetime',
|
||||
),
|
||||
'field_instance' => array(
|
||||
'bundle' => 'date_migrate_example',
|
||||
'deleted' => '0',
|
||||
'description' => '',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'above',
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'format_type' => 'medium',
|
||||
'fromto' => 'both',
|
||||
'multiple_from' => '',
|
||||
'multiple_number' => '',
|
||||
'multiple_to' => '',
|
||||
'show_repeat_rule' => 'show',
|
||||
),
|
||||
'type' => 'date_default',
|
||||
'weight' => '6',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'above',
|
||||
'settings' => array(),
|
||||
'type' => 'hidden',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_datetime_range',
|
||||
'label' => 'Datetime range',
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'default_format' => 'medium',
|
||||
'default_value' => 'now',
|
||||
'default_value2' => 'blank',
|
||||
'default_value_code' => '',
|
||||
'default_value_code2' => '+1 year',
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'date',
|
||||
'settings' => array(
|
||||
'increment' => 1,
|
||||
'input_format' => 'm/d/Y - H:i:s',
|
||||
'input_format_custom' => '',
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
'text_parts' => array(),
|
||||
'year_range' => '-3:+3',
|
||||
),
|
||||
'type' => 'date_text',
|
||||
'weight' => '7',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Translatables
|
||||
// Included for use with string extractors like potx.
|
||||
t('Body');
|
||||
t('Date');
|
||||
t('Date range');
|
||||
t('Date with repeat');
|
||||
t('Datestamp');
|
||||
t('Datestamp range');
|
||||
t('Datetime');
|
||||
t('Datetime range');
|
||||
|
||||
return $fields;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Examples and test folder for migration into date fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_node_info().
|
||||
*/
|
||||
function date_migrate_example_node_info() {
|
||||
$items = array(
|
||||
'date_migrate_example' => array(
|
||||
'name' => t('Migrate example - dates'),
|
||||
'base' => 'node_content',
|
||||
'description' => t('This content type is used for demonstrating and testing migration into Date fields.'),
|
||||
'has_title' => '1',
|
||||
'title_label' => t('Title'),
|
||||
'help' => '',
|
||||
),
|
||||
);
|
||||
return $items;
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
core = "7.x"
|
||||
dependencies[] = "date"
|
||||
dependencies[] = "date_repeat"
|
||||
dependencies[] = "date_repeat_field"
|
||||
dependencies[] = "date_migrate"
|
||||
dependencies[] = "features"
|
||||
dependencies[] = "migrate"
|
||||
description = "Examples of migrating with the Date module"
|
||||
features[field][] = "node-date_migrate_example-body"
|
||||
features[field][] = "node-date_migrate_example-field_date"
|
||||
features[field][] = "node-date_migrate_example-field_date_range"
|
||||
features[field][] = "node-date_migrate_example-field_date_repeat"
|
||||
features[field][] = "node-date_migrate_example-field_datestamp"
|
||||
features[field][] = "node-date_migrate_example-field_datestamp_range"
|
||||
features[field][] = "node-date_migrate_example-field_datetime"
|
||||
features[field][] = "node-date_migrate_example-field_datetime_range"
|
||||
features[node][] = "date_migrate_example"
|
||||
files[] = date_migrate_example.migrate.inc
|
||||
name = "Date Migration Example"
|
||||
package = "Features"
|
||||
project = "date_migrate_example"
|
||||
version = "7.x-2.0"
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-08-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "date"
|
||||
datestamp = "1344850024"
|
||||
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the Date Migrate Example module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function date_migrate_example_disable() {
|
||||
Migration::deregisterMigration('DateExample');
|
||||
}
|
||||
|
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Examples and test folder for migration into date fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Migration class to test import of various date fields.
|
||||
*/
|
||||
class DateExampleMigration extends XMLMigration {
|
||||
|
||||
/**
|
||||
* Sets up the migration.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$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('uid')
|
||||
->defaultValue(1);
|
||||
$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');
|
||||
|
||||
// RRULEs on repeat fields are also done in prepareRow().
|
||||
$this->addFieldMapping('field_date_repeat', 'date_repeat');
|
||||
|
||||
$this->addFieldMapping('field_datestamp', 'datestamp')
|
||||
->xpath('datestamp');
|
||||
$this->addFieldMapping('field_datestamp_range', 'datestamp_range_from');
|
||||
|
||||
// You can specify a timezone to be applied to all values going into the
|
||||
// field (Tokyo is UTC+9, no DST)
|
||||
$arguments = DateMigrateFieldHandler::arguments('Asia/Tokyo');
|
||||
$this->addFieldMapping('field_datetime', 'datetime')
|
||||
->xpath('datetime')
|
||||
->arguments($arguments);
|
||||
|
||||
// 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');
|
||||
|
||||
// Unmapped destination fields.
|
||||
$this->addUnmigratedDestinations(array('is_new', 'status', 'promote', 'revision', 'language', 'sticky', 'created', 'changed', 'revision_uid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$date_data = array(
|
||||
'from' => (string) $range->from[0],
|
||||
'to' => (string) $range->to[0],
|
||||
);
|
||||
$current_row->date_range_from[] = drupal_json_encode($date_data);
|
||||
}
|
||||
|
||||
$date_data = array(
|
||||
'from' => (string) $current_row->xml->datestamp_range->from[0],
|
||||
'to' => (string) $current_row->xml->datestamp_range->to[0],
|
||||
);
|
||||
$current_row->datestamp_range_from = drupal_json_encode($date_data);
|
||||
|
||||
$date_data = array(
|
||||
'from' => (string) $current_row->xml->datetime_range->from[0],
|
||||
'to' => (string) $current_row->xml->datetime_range->to[0],
|
||||
'timezone' => (string) $current_row->xml->datetime_range->timezone[0],
|
||||
);
|
||||
$current_row->datetime_range_from = drupal_json_encode($date_data);
|
||||
|
||||
$date_data = array(
|
||||
'from' => (string) $current_row->xml->date_repeat->date[0],
|
||||
'rrule' => (string) $current_row->xml->date_repeat->rule[0],
|
||||
);
|
||||
$current_row->date_repeat = drupal_json_encode($date_data);
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Migration integration for Date Migrate Example.
|
||||
*/
|
||||
|
||||
include_once 'date_migrate_example.features.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_api().
|
||||
*/
|
||||
function date_migrate_example_migrate_api() {
|
||||
$api = array(
|
||||
'api' => 2,
|
||||
);
|
||||
return $api;
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<source_data>
|
||||
<item>
|
||||
<id>3</id>
|
||||
<title>Simple example</title>
|
||||
<body>This is pretty straight-forward.</body>
|
||||
<date>05/12/2011 19:43</date>
|
||||
<date_range>
|
||||
<from>06/13/2011 6:32pm</from>
|
||||
<to>07/23/2011 10:32am</to>
|
||||
</date_range>
|
||||
<datestamp>07/22/2011 12:13</datestamp>
|
||||
<datestamp_range>
|
||||
<from>8/1/2011 00:00</from>
|
||||
<to>9/1/2011 00:00</to>
|
||||
</datestamp_range>
|
||||
<datetime>11/18/2011 06:00</datetime>
|
||||
<datetime_range>
|
||||
<from>10/30/2011 19:43</from>
|
||||
<to>12/31/2011 23:59</to>
|
||||
<timezone>America/Chicago</timezone>
|
||||
</datetime_range>
|
||||
<date_repeat>
|
||||
<date>11/25/2011 9:01</date>
|
||||
<rule>RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=20120512T040000Z;WKST=MO
|
||||
EXDATE:20111223</rule>
|
||||
</date_repeat>
|
||||
</item>
|
||||
<item>
|
||||
<id>8</id>
|
||||
<title>Example with multi-value fields</title>
|
||||
<body>This is not as straight-forward.</body>
|
||||
<date>06/21/2012 15:32</date>
|
||||
<date>12/02/2012 11:08</date>
|
||||
<date_range>
|
||||
<from>02/03/2004 1:15am</from>
|
||||
<to>03/04/2005 10:11pm</to>
|
||||
</date_range>
|
||||
<date_range>
|
||||
<from>09/01/2014 5:21pm</from>
|
||||
<to>12/23/2015 00:01</to>
|
||||
</date_range>
|
||||
<datestamp>07/22/2011 12:13</datestamp>
|
||||
<datestamp_range>
|
||||
<from>8/1/2011 00:00</from>
|
||||
<to>9/1/2011 00:00</to>
|
||||
</datestamp_range>
|
||||
<datetime>11/18/2011 06:00</datetime>
|
||||
<datetime_range>
|
||||
<from>10/30/2011 19:43</from>
|
||||
<to>12/31/2011 23:59</to>
|
||||
<timezone>America/Chicago</timezone>
|
||||
</datetime_range>
|
||||
<date_repeat>
|
||||
<date>11/25/2011 9:01</date>
|
||||
<rule>RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=20120512T040000Z;WKST=MO
|
||||
EXDATE:20111223</rule>
|
||||
</date_repeat>
|
||||
</item>
|
||||
</source_data>
|
Reference in New Issue
Block a user