Hi. Migrate's 2.4 update made some changes in how arguments are handled. Instead of taking arguments in a json serialized array, Migrate 2.4 lets fields use subfields, which show up in the Migrate interface. For instance, you'd have something like date, date:to (for the end time), date:language each showing up as fields to be mapped.

Comments

jsagotsky’s picture

StatusFileSize
new1.49 KB

I've attached my first stab at a patch. It uses the fields method to define the subfields mentioned above. I also made a slight change to get $from and $to from the arguments, so that their subfields are usable.

karens’s picture

We probably need to do this in a way that it won't break migrations that were already created using older methods. I can't tell if you're taking this into account.

mikeryan’s picture

Status: Active » Needs review

Eyeballing this patch, it shouldn't affect existing migrations. The new subfield method passes the subfield internally using the same method as the former arguments method, the main thing this adds is documentation of the available subfields.

Status: Needs review » Needs work

The last submitted patch, date-migrate_v24-1715700-1.patch, failed testing.

mikeryan’s picture

Guess it does affect the old code;). So, it should be fixed to support legacy code, and there should be a new test added for the subfield approach.

mikeryan’s picture

Title: Support for migrate v2.4 » Support for migrate v2.4 (subfields)
Version: 7.x-2.2 » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new7.12 KB

OK, here's some refactoring plus updated examples. This version allows the subfields to be arrays with distinct values per primary value (i.e., in a multi-value date range field each data has its own from/to). The testbot isn't going to be happy until #1832544: Class registration for Migrate 2.5 or later is committed, so that should go first, but the tests do pass in my environment with both patches present.

Status: Needs review » Needs work

The last submitted patch, migrate_subfields-1715700-6.patch, failed testing.

mikeryan’s picture

Status: Needs work » Needs review

#6: migrate_subfields-1715700-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, migrate_subfields-1715700-6.patch, failed testing.

drclaw’s picture

I think #1832544: Class registration for Migrate 2.5 or later needs to be committed before this patch will pass testing...

jantoine’s picture

Status: Needs work » Reviewed & tested by the community

Code is clean and causes the Date Migrate module to function properly with the Migrate module v7.x-2.5, following the application of the patch from #1832544: Class registration for Migrate 2.5 or later.

joelstein’s picture

Agreed. I applied the patch in #6 and had no problems migrating a date with the new subfield syntax.

schuffr’s picture

Great news. How can we get this into date? I (and many others from what I can tell) are stuck in the water trying to import calendar events into Drupal with Migrate. It looks like the with this patch, the capability is there but when will it move to code with an even brief example of how to apply it.

Thanks all!

mikeryan’s picture

#6: migrate_subfields-1715700-6.patch queued for re-testing.

mikeryan’s picture

mikeryan’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.13 KB

Updated patch - I had trouble with timezones coming in with empty strings, !empty() works better than isset().

tangent’s picture

@mikeryan, this works great for me. I simply extended (overrode) the DateMigrateFieldHandler in my custom migrate_d2d module since the patch hasn't been committed yet and that works fine.

nno’s picture

Works great! Thank you very much!

rsbecker’s picture

Two more additions to date.migration.inc are needed or migration fails because of undefined language variable.

<?php
      // Add language subfield
      if (!empty($arguments['language'])) {
        if (is_array($arguments['language'])) {
          $language = $arguments['language'][$delta];
        }
        else {
          $language = $arguments['language'];
        }
      }
      else {
        $language = NULL;
      }

and

<?php
  public function fields($migration = NULL) {
    return array(
      'timezone' => t('Timezone'),
      'rrule' => t('Recurring event rule'),
      'to' => t('End date date'),
      'language' => t('Language'), //Added to array so you can $this->addFieldMapping('field_event_date:language')->defaultValue('und');
    );
  }
rsbecker’s picture

One more fix is needed to deal with date fields that are not date ranges. The date.migrate.inc file assumes there is a field_date:to subfield. If none exists the following error messages are thrown.

3	Informational	Undefined variable: to File /home/spjdco5/public_html/spjdc.net/drupal7/sites/all/modules/date/date_migrate/date.migrate.inc, line 142(file: /home/spjdco5/public_html/spjdc.net/drupal7/sites/all/modules/date/date_migrate/date.migrate.inc, line 142)
3	Informational	Undefined variable: to File /home/spjdco5/public_html/spjdc.net/drupal7/sites/all/modules/date/date_migrate/date.migrate.inc, line 154(file: /home/spjdco5/public_html/spjdc.net/drupal7/sites/all/modules/date/date_migrate/date.migrate.inc, line 154)

The class should determine whether there is a 'to' subfield and if not skip this test.

One more thing. Considering that it has been nearly 9 months since the last version and over 7 months since the last dev version, and there have been at least two patches to adapt to new versions of migrate, can you roll a new release incorporating the changes.

mxt’s picture

@Mikeryan: I've use your #16 patch and all works well, start and end date are registered, except for this issue: dates are imported 1 day back!

For example:

source dates:

  • start date: 2005-07-08
  • end date: 2005-07-10

resulting imported dates:

  • start date: 2005-07-07 <- Notice the day before!
  • end date: 2005-07-09 <- Notice the day before!

How can this happen?

Thank you for helping me

rsbecker’s picture

It is likely that you are having timezonebissues where the modulebis converting from your tz to utc. One fix is to append 00:00:00 to dates before importing.

mxt’s picture

Thank you rsbecker for your suggestion: I've tried it but doesn't work.

Instead, specifying precisely the timezone, everything works perfectly:

$this->addFieldMapping('field_period:timezone')
         ->defaultValue('Europe/Rome');

Thank you very much!

mikeryan’s picture

This patch has been incorporated into the consolidated patch at #2034231: [META] Integrated patch for migration changes.

cafuego’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.