I'm trying to include formats for text fields in my migration, specifically allowing for the use of php code (switching from the default setting of "filtered HTML"). In my content set I've tried setting the default value to 3; I've also tried actually importing the number 3 via the actual source field - but it doesn't make the change in the database (it continues to say "null"). Note that I can go into the db and make the change directly and can immediately see the change reflected in the node's edit page - but that's the only way. For some reason, migrate is refusing to carry the number into the field/table.

Can I not simply put a 2 or 3 into the default field when migrating to switch the "input format" for a field in a node from, let's say "filtered html" to "full HTML" or "php code"?

Comments

khosman’s picture

Okay, upon much tinkering, I found a work around: I went into Site Config > Input Formats and set the default to "Full HTML" (for this example) and re-imported. This time the text areas picked up that format. (Before doing this, I set the migration fields to empty.) I still haven't figured out how to set these defaults from the Migrate > (content set) > edit page, so the changes will disappear if I set my defaults back (via the master Input Formats page) and re-import. It'd be pretty cool if I could actually set these via the "default value" there on the migrate page, but this works for now.

khosman’s picture

Category: support » bug

Okay - I'm having much luck with migrating data - EXCEPT FOR this issue. No matter what I try I can't get the "Input Format" to be set when migrating. Were this not a bug, I think it woulda worked by now.

mikeryan’s picture

Project: Migrate Extras » Migrate
Version: 6.x-1.0-alpha1 » 6.x-1.x-dev
Component: Migrate Extras Features » Code

Looks like a migrate module issue, not migrate_extras.

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

With the current dev release of Migrate, I can't reproduce this. I enabled the PHP Filter module, set the Node:Input Format default value in a node migration to 3, and when I imported a node it ended up with the PHP filter selected.

Are you using the most recent version of Migrate (at least the RC release)? Is there anything else particular to your environment which might help reproduce this problem?

Thanks.

khosman’s picture

For the most part, I've got 'migrate'/'migrate extras' working great - I've got much of my past site imported, with tables brought in and related to each other - it's been terrific. However... even with all the tricks I've got this thing doing... I can't get the individual fields to import as format 1, 2 or 3 (let's say). It looks as though it should be very simple. I have done those things you mention plus a pile of other tests. Note that I don't see how changing the "node as a whole" as you mention plays out, as it's the individual fields (CCK) I'm trying to affect, so maybe I'm missing something there (and maybe I shoulda posted this in the migrate extras section). I do know that regardless of what I try, the fields for "description format" (in my case) remain "null" after migration.

I am using recent releases of all mods - so I'm not sure what else might be at play.

Am I expecting something to happen that isn't meant to happen? Shouldn't I be able to put a 2 in the default field of my "description format" field (migrate > (content set) > edit page) and then, when editing that field, shouldn't I see "Full HTML" checked when I click on "input format?"

markabur’s picture

i came here due to the same issue -- the ui doesn't seem to affect the input format for individual cck fields.

i was able to get around this in my hook_migrate_prepare_node function by setting the format there.

function example_migrate_prepare_node(&$node, $tblinfo, $row) {
  // lots of other preprocessing
  // ...
  // Set the field's input format to Full HTML.
  $node->field_mycckfield[0]['format'] = '2'; 
}
markabur’s picture

Version: 6.x-1.x-dev » 6.x-1.0
mikeryan’s picture

Title: Input format - switching from Filtered HTML to PHP Code » Support migrating input formats for CCK text fields
Project: Migrate » Migrate Extras
Version: 6.x-1.0 » 6.x-1.x-dev
Component: Code » CCK
Category: bug » feature
Status: Postponed (maintainer needs more info) » Active

I misunderstood initially, it wasn't clear to me that you were looking to migrate input formats for CCK text fields. (Re)reassigning and retitling.

mathieu’s picture

Same issue with migrate_extras 6.x-1.0-alpha2 and migrate 1.0.

I am not importing any specific value for format : I just need it to always be 1, so I put that as default value in the content set definition. When performing the migration, this is completely ignored (database value is null), but if I call $node->field_name[0]['format'] = 1;, then it works fine.

I was having a look at migrate_extras/content.migrate.inc... it looks like other people above are also trying to import a default value (leaving the import value to <none>) and this default value is ignored.

I'll see if I can dig deeper later...

cmejo’s picture

Where exactly do I put this code?

function example_migrate_prepare_node(&$node, $tblinfo, $row) {
  // lots of other preprocessing
  // ...
  // Set the field's input format to Full HTML.
  $node->field_mycckfield[0]['format'] = '2'; 
}

Does it go here?

/**
 * Implementation of hook_migrate_prepare_node().
 */
function content_migrate_prepare_node(&$node, $tblinfo, $row) {
  static $types, $fieldinfo = array();
  $errors = array();
  if (!isset($types)) {
    $types = (array) content_types();
DO I PLACE THOSE LINES OF CODE HERE?
  }
  if (isset($types[$node->type])) {
    $content_type = $types[$node->type];
    foreach ($content_type['fields'] as $field) {
      $field_name = $field['field_name'];
      // Find the column names for this field type and process each.
      if (!isset($fieldinfo[$node->type][$field_name])) {
        $fieldinfo[$node->type][$field_name] = content_database_info($field);
      }
      $db_info = $fieldinfo[$node->type][$field_name];
      foreach ($db_info['columns'] as $column => $info) {
        $dummy_name = $field['field_name'] .'_'. $column;

        // Force a node value for missing data.
        if (empty($node->$dummy_name)) {
          $values = array();
        }
        else {
          // Explode multiple values to create the $delta and $value for each.
          if ($field['multiple']) {
            $values = explode($tblinfo->multiple_separator, $node->$dummy_name);
          }
          else {
            $values = array(0 => $node->$dummy_name);
          }
        }

(content.migrate.inc file)

Thanks!

markabur’s picture

no, you would create a custom module and put that code in there. if your module is called "mymodule" then the function would be

function mymodule_migrate_prepare_node(&$node, $tblinfo, $row) {
  // lots of other preprocessing
  // ...
  // Set the field's input format to Full HTML.
  $node->field_mycckfield[0]['format'] = '2'; 
}

drupal's system of function overrides means that you pretty much never have to hack core files or contributed modules. content_migrate_prepare_node will do its thing first, then your module will be able to manipulate the data using mymodule_migrate_prepare_node.

mikeryan’s picture

Status: Active » Closed (won't fix)

Migrate and Migrate Extras V1 are no longer supported. Migrate V2 supports passing an input format on text fields.