I have a taxonomy with field "field_points_of_interest" and this field have multiple values and multiple languages 'en' and 'zh'

I tried with following methods in migration fields mapping

//..........  
      $this->addFieldMapping('field_points_of_interest', 'points_of_interest');
       $this->addFieldMapping('field_points_of_interest:language', 'points_of_interest_language');
//.............................
// prepareRow function
 public function prepareRow($current_row) {
           $current_row->points_of_interest = array($current_row->points_of_interest_en,$current_row->points_of_interest_zh);
            $current_row->points_of_interest_language = array('en','zh');

}
 

But its not working and showing the sql error to field_points_of_interest data base table. If any idea Please help us

If we are using only one language with multiple values , its working with out any issues.

Any one doing the migration with multiple values with multiple languages in a taxonomy field?

eg:
the values in side the $current_row->points_of_interest is like array('a','b','c') and
$current_row->points_of_interest_zh is array('e','f','g')
so after the migration i have to get the values in side the field like

 [field_points_of_interest] => Array
        (
            [en] => Array
                (
                    [0] => Array
                        (
                            [value] => a
                            [format] => full_html
                            [safe_value] => a
                        )

                    [1] => Array
                        (
                            [value] => b
                            [format] => full_html
                            [safe_value] => b
                        )

                    [2] => Array
                        (
                            [value] => c
                            [format] => full_html
                            [safe_value] => c 
                        )                    

                )

            [zh] => Array
                (
                    [0] => Array
                        (
                            [value] => e
                            [format] => full_html
                            [safe_value] => e
                        )

                    [1] => Array
                        (
                            [value] =>  f
                            [format] => full_html
                            [safe_value] =>  f
                        )

                    [2] => Array
                        (
                            [value] =>  g
                            [format] => full_html
                            [safe_value] =>  g
                        )

                )

        )

Comments

basilbaby6’s picture

Issue summary: View changes
basilbaby6’s picture

Issue summary: View changes
basilbaby6’s picture

Priority: Major » Critical
basilbaby6’s picture

Issue tags: +migration, +multilingual, +drupal7
basilbaby6’s picture

Category: Support request » Bug report
Alienpruts’s picture

Actually, I'm having the same problem, but with translated (entity translation) multiple-value fields.

My problem is more about handling the translation part of the migration. I can add a mapping like this :

$this->addFieldMapping('field_product_properties','properties')

just fine (if I construct an array with all values in prepareRow() function. But I am stumped as to how to handle the translation part.

I thought If I constructed an array with array's in it like this :

$row->properties = array($properties_nl, $properties_en);

and a mapping

$this->addFieldMapping('field_product_properties','properties';
$this->addFieldMapping('field_product_properties:language', 'languages');

(where languages if ofcourse an array with the defined languages)

that would do the trick, but no cigar.

Does anyone have any light to shed on this situation?

EDIT : This is the output in the messages table, for the curious. I understand the message (it's because I'm passing an array containing arrays), but I have no clue how to remedie this

mb_substr() expects parameter 1 to be string, array given File /workspace/easym_kul/includes/unicode.inc, line 589

cthos’s picture

Component: migrate_example » Code
Priority: Critical » Normal

Updating some fields. Dropping the priority to Normal, and changing the component to Code.

Multiple languages in destination fields is not something Migrate handles very well currently. What you're probably going to have to do for the time being is making use of prepare in order to get the field into the right shape during the migration for these fields.

mikeryan’s picture

To expand on the previous comment, given the original example use case here:

the values in side the $current_row->points_of_interest is like array('a','b','c') and
$current_row->points_of_interest_zh is array('e','f','g')

In your migration you would implement a prepare function like:

public function prepare($entity, stdClass $row) {
  foreach ($row->points_of_interest as $english_point_of_interest) {
    $entity->field_points_of_interest['en'][] = array('value' => $english_point_of_interest);
  }
  foreach ($row->points_of_interest_zh as $chinese_point_of_interest) {
    $entity->field_points_of_interest['zh'][] = array('value' => $chinese_point_of_interest);
  }
}
basilbaby6’s picture

Hi Mikeryan,

Thanks a lot for your suggestion :) . This is working in the text fields with multiple values. Last time I tried with "prepare" function, but I declared the "value" array seems to be little different, because of that it was failing.

Regards,
Basil

basilbaby6’s picture

Mikeryan ,

I have identified a few more issues in migrations
1. Image fields with multilingual migration.
2. File field with multiple value migration.
3. File field with multilingual migration.

I will try with "file_save_data" and "prepare" functions and let you know if this is a success or failed.

basilbaby6’s picture

Here is the way we can map the file fields and image fields.
This will support multiple file fields migration and multilingual file field migration.

  public function prepare($entity, stdClass $row) {
  $port_guide_uri = $row->field_port_guide; //this is the source object with array of file url from other server  
    $port_guide_filename = $row->field_port_guide_filename; //this is the file name object 
    if ($port_guide_uri != NULL) {

      foreach ($port_guide_uri as $language => $uris) {

        foreach ($uris as $i => $uri) {

          $filename = $port_guide_filename->$language;
          $file_temp = file_get_contents($uri);
          if ($file_temp) {
            $file_saved_data = file_save_data($file_temp, 'public://port_guide/' . $filename[$i], FILE_EXISTS_REPLACE);
            $entity->field_port_guide[$language][$i] = array(
              'fid' => $file_saved_data->fid,
              'filename' => $file_saved_data->filename,
              'filemime' => $file_saved_data->filemime,
              'uid' => 1,
              'uri' => $file_saved_data->uri,
              'status' => 1,
              'display' => 1
            );
          }
        }
      }
    }
    else {
      $entity->field_port_guide = array();
    }
}

Make sure that "field_port_guide" removed from field mapping.

apaderno’s picture

Issue tags: -taxonomy text field with multiple values and multilingual migration in drupal7, -migration, -multilingual, -drupal7