bolt / ImportWXR

[Bolt Extension] An Import filter for WXR files, as created by Wordpress or PivotX
MIT License
14 stars 5 forks source link

Importing into video and image fields doesn't work #13

Open hansfn opened 8 years ago

hansfn commented 8 years ago

(Example based on export from PivotX, but the same problem is present for people exporting Wordpress content.)

Having entries with two extrafields in PivotX:

  1. Youtube - containing the URL to an Youtube video
  2. Pic - containg the filename of an image

To import these two extra fields into the default entry content type add the following two lines to the Post mapping of the default importwxr.bolt.yml / config.yml.dist.

      pivx_extrafield_pic: image
      pivx_extrafield_youtube: video

This seems to work when you look at the preview/dryrun, but after running the import the video and image fields are empty. The problem is that these field types stores the actual value under keys ('url' and 'file'). So basically the fix is check for these field types in the importer and make sure that the values are stored on the keys. After line 174 in bolt/extensions/vendor/bolt/importwxr/Extension.php add:

                case "video":
                    $value = serialize(array('url' => $value));
                    break;
                case "image":
                    $value = serialize(array('file' => $value));
                    break;

This works great if you use the default entry content type in Bolt. However, if you add a field yourself named for example Youtube with type "video" and try to import the same PivotX Youtube extra field into that Bolt fields it will fail because the function importPost doesn't load the field type, only the field name ... @bobdenotter, what do you think?

PS! Excerpt from entries.xml that contains these two extrafields:

<wp:postmeta>
<wp:meta_key>pivx_extrafield_pic</wp:meta_key>
<wp:meta_value><![CDATA[someimage.jpg]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_pivx_extrafield_pic</wp:meta_key>
<wp:meta_value><![CDATA[field_5467c15f00012]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>pivx_extrafield_youtube</wp:meta_key>
<wp:meta_value><![CDATA[https://www.youtube.com/watch?v=8K-xfQ9zcgo]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_pivx_extrafield_youtube</wp:meta_key>
<wp:meta_value><![CDATA[field_5467c15f00002]]></wp:meta_value>
</wp:postmeta>