bolt / ImportWXR

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

extra fields problem #12

Open bcmans opened 8 years ago

bcmans commented 8 years ago

I added the fields in contenttypes.yml that I could find in the dump entries.xml form pivotx

entries.xml

<item>
<!-- Item for old id 1116 to post_id 1416 -->
<title>DJ Wonder</title>
<link>http://www.com/dat/?e=1116</link>
<pubDate>Fri, 05 Feb 2016 23:11:00 +0000</pubDate>
<dc:creator><![CDATA[boris]]></dc:creator>
<category><![CDATA[video]]></category>
<category domain="category" nicename="video"><![CDATA[video]]></category>
<category><![CDATA[Default]]></category>
<category domain="category" nicename="default"><![CDATA[Default]]></category>
<guid isPermaLink="true">http://www.test.com/dat/?e=1116</guid>
<description></description>
<image></image>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<content:encoded><![CDATA[<p>Hoe laat halen we Heather op? 9 uur!! Kunnen jullie alles verzamelen en in de auto vast doen? Skies check, ski passen,check ski boots, check gaan we hopelijk fun hebben, check!!!!!  dan gaan we!!!!</p>  <p>30 minuten later jahooooooeeeee schreewut pap als hij vliegt door de bomen. Heen en weer en een sprong hier en een spring daar in de zachte sneeuw. Op een moment zegt papa wil je jij misschien een filmpje maken. Laten we naar Gold Nugget gaan!!</p>  <p>Michelle en Heather zagen we aan het einde van dag. Maandag (pro d day) wil je dat we je weer ophalen heather? </p>  <p>What is a pro d day</p>  <p>A professional development day is basically a learning day for educators or business professionals.</p> ]]></content:encoded>
<wp:post_id>1416</wp:post_id>
<wp:post_name>dj-wonder</wp:post_name>
<wp:post_date>2016-02-05 23:11:00</wp:post_date>
<wp:post_date_gmt>2016-02-05 23:11:00</wp:post_date_gmt>
<wp:comment_status>closed</wp:comment_status>
<wp:ping_status>closed</wp:ping_status>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order></wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
<wp:postmeta>
<wp:meta_key>pivx_extrafield_intro_wordcount</wp:meta_key>
<wp:meta_value><![CDATA[121]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_pivx_extrafield_intro_wordcount</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[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>
<wp:postmeta>
<wp:meta_key>pivx_extrafield_achtergrond</wp:meta_key>
<wp:meta_value><![CDATA[3561]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_pivx_extrafield_achtergrond</wp:meta_key>
<wp:meta_value><![CDATA[field_5467c15f00005]]></wp:meta_value>
<!-- Warning! Extrafields key not found! galleryimagelist. Value: 2016-02/2016_02_05_12_49_17.jpg######
 Extension inactive? Check code to find fields. -->
</wp:postmeta>
</item>

contenttypes.yml

# This file defines the contenttypes on the website. See the documentation for
# details: https://docs.bolt.cm/contenttypes-and-records#defining-contenttypes

# Pages can be used for the more 'static' pages on your site. Things like
# 'about us', 'contact' or a 'disclaimer'. This content-type has a 'templateselect'
# field, which allows you to override the record_template setting for an
# individual page.
# The taxonomy for this contenttype is defined as 'chapters', which is a so-called
# "grouping taxonomy". This way you can easily group sets of pages that logically
# belong together. If your site has a 'services' section, in which you'd like to
# list the different types of services a company provides, you can group these
# together.

pages:
    name: Pages
    singular_name: Page
    fields:
        title:
            type: text
            class: large
            group: content
        slug:
            type: slug
            uses: title
        image:
            type: image
        teaser:
            type: html
            height: 150px
        body:
            type: html
            height: 300px
        template:
            type: templateselect
            filter: '*.twig'
    taxonomy: [ chapters ]
    recordsperpage: 100

# Entries can be used for things like 'news' or 'blogpostings'. They have a 'teaser',
# which can be used for a short blurb on listing-pages, allowing visitors to
# click-through to the rest of the entry. It also has fields for an image and an
# optional video.
# A relation is defined to the pages contenttype. This way you can refer to a page
# from your news-item.
# This contenttype defines 'categories' and 'tags' as taxonomies, allowing the
# editor to use both to categorize a specific entry.
# The 'sort' is set to '-datepublish', which means that newer entries will be
# shown above older entries.

entries:
    name: Entries
    singular_name: Entry
    fields:
        title:
            type: text
            class: large
            group: content
        slug:
            type: slug
            uses: title
        teaser:
            type: html
            height: 150px
        body:
            type: html
            height: 300px        
        gallery:
             type: imagelist             
        image:
            type: image
            group: media
        image-background:
            type: image
            group: content      
        video:
            type: video
    relations:
        pages:
          multiple: false
          order: title
          label: Select a page
    taxonomy: [ categories, tags ]
    record_template: entry.twig
    listing_template: listing.twig
    listing_records: 10
    default_status: publish
    sort: -datepublish
    recordsperpage: 10

# The 'Showcases' is not particularly useful in most cases, but it does a good
# job of showcasing most of the available fieldtypes. Feel free to delete it, or
# copy some fields to your own contenttypes.
# Since no templates are defined for this contenttype, the default record_template,
# listing_template, and related settings are used from config.yml

showcases:
    name: Showcases
    slug: showcases
    singular_name: Showcase
    singular_slug: showcase
    fields:
        title:
            type: text
            class: large
            required: true
            pattern: ".{2,255}" # see: http://html5pattern.com/
            error: "The Title field is required, and must contain at least 2 characters"
            group: Text
        slug:
            type: slug
            uses: [ title ]
        html:
            type: html
            height: 150px
        textarea:
            type: textarea
            postfix: "<p><em>This is a plain text area. the contents will not be processed.</em></p>"
        markdown:
            type: markdown
            postfix: "<p><em>This field gets parsed as <a href='https://help.github.com/articles/markdown-basics'>Markdown</a>, when rendered on the site.</em></p>"
        geolocation:
            type: geolocation
            group: Media
        video:
            type: video
        image:
            type: image
            attrib: title # Note: retrieve this in your template with {{ record.values.image.title }}
            extensions: [ gif, jpg, png ]
        imagelist:
            type: imagelist
        file:
            type: file
            group: files
        filelist:
            type: filelist
        checkbox:
            type: checkbox
            label: "This is a checkbox"
            group: other
        datetime:
            type: datetime
            default: "2000-01-01"
            variant: inline
        date:
            type: date
            default: "first day of last month"
            variant: inline
        integerfield:
            type: integer
            index: true
        floatfield:
            type: float
        selectfield:
            type: select
            values: [ none, foo, bar ]
        multiselect:
            type: select
            values: [ A-tuin, Donatello, Rafael, Leonardo, Michelangelo, Koopa, Squirtle ]
            multiple: true
            postfix: "Select your favourite turtle(s)."
        selectentry:
            type: select
            values: entries/id,title
            postfix: "Select an entry"
            autocomplete: true
            sort: title
        template:
            type: templateselect
            filter: '*.twig'
            group: meta
    relations:
        entries:
            multiple: false
            label: "Choose an entry"
            order: -id
            format: "{{ item.title|escape }} <span>(№ {{ item.id }})</span>"
            postfix: "By selecting an Entry, you're creating a bi-directional relationship to that Entry."
        pages:
            multiple: true
            order: title
            label: Select zero or more pages
    taxonomy: [ categories, tags ]
    show_on_dashboard: true
    default_status: publish
    searchable: false
    icon_many: "fa:cubes"
    icon_one: "fa:cube"

# Using YAML repeated nodes
#
# YAML allows the defining of "repeated nodes". These allow you to define a 'node'
# with a 'key: &name' and referenced later with '<<: *name'
#
# Bolt allows you to define this with the special entry of '__nodes:' that itself 
# won't create a Contenttype, but will allow you to use it in actual contenttypes
# to prevent repeating yourself.
#
# To achieve this, first create a key '__nodes:' 
#__nodes:
#    field_defaults: &field_defaults
#        title:
#            type: text
#            class: large
#            group: main
#        slug:
#            type: slug
#            uses: title
#    template_defaults: &template_defaults
#        template:
#            type: templateselect
#            filter: '*.twig'
#            group: meta
#
# Then, as an example, you could create a Contenttype with default fields, with 
# an additional 'image' field.
#
#contenttype_abc:
#    name: Contenttype Abc
#    fields:
#        <<: *field_defaults
#        image:
#            type: image
#            attrib: title
#            extensions: [ gif, jpg, png ]
#        <<: *template_defaults
#    taxonomy: [ chapters ]
#    recordsperpage: 10
#
# Alternatively, or additionally, you then can thencreate a Contenttype with 
# default fields, and a 'select' field, and a different 'templateselect' option.
#
#contenttype_xyz:
#    name: Contenttype Xyz
#    fields:
#        <<: *field_defaults
#        selectfield:
#            type: select
#            values: [ none, foo, bar ]
#        template:
#            type: templateselect
#            filter: '*_xyz.twig'
#    taxonomy: [ tags ]
#    recordsperpage: 20

# Possible field types:
#
# text - varchar(256) - input type text.
# integer - integer - Input field for integer numbers.
# float - double - Input field for floating numbers, stored as 'Double'.
# geolocation - text (65kb) - Input field for geolocation. Enter an address, and the location is geocoded to latitude/longitude coordinates
# imagelist - text (65kb) - Input type for imagelists. Add multiple images with a description. Useful for image sliders, galleries, etcetera.
# image - varchar(256) - image select/upload widget, stored as filename.
# file - varchar(256) - file select/upload widget, stored as filename.
# filelist - text (65kb) - Input type for a list of files. Including a description.
# video - varchar(256) - Video embed widget, stored as filename.
# html - text (65kb) - wysiwyg element.
# textarea - varchar(32768) - Simple, plain < textarea > field.
# markdown - varchar(32768) - Simple, plain < textarea > field, which is parsed as Markdown text.
# datetime - datetime - date and time selector widget.
# date - datetime - date selector widget.
# select - varchar(256) - select with predefined values
# templateselect - varchar(256) - select with template filenames
# checkbox - integer - checkbox-field which is 1 (checked) or 0 (unchecked)

# number (deprecated) - input type decimal(18,9), useful for storing number that need to be sortable

importwxr.bolt.yml

 # The name of the XML file to import. Place this file in the folder:
# extensions/vendor/bolt/importwxr/files/

#file: files/pages.xml
file: files/entries.xml

import_authors: true # not yet supported.

# If 'author' is set, all records of that contenttype will have that author. If
# left unset, Bolt will import it, as if it belongs to the original author,
# regardless of whether the author exists.

# Make sure your mappings are actually mapping to fields that exist in your
# contenttypes. If they don't some of the data from the import will be lost.

# If 'post_id' is mapped to 'id', it will preserve the ID's in bolt, so this
# will overwrite your content, if these ID's are already taken in Bolt. Comment
# this line out, to add the records, regardless of id. An added benefit of re-
# using the id's (end therefore overwriting the records) is that you'll be able
# to do the import multiple times. Do the import, tweak the settings, import
# again, repeat until done.

mapping:

  #wordpress mappings 

  post: # Wordpress entries..
    targetcontenttype: entries
    #author: admin
    fields:
      post_title: title
      post_author: username
      post_content: body
      post_excerpt: teaser
      post_id: id
      post_date: datecreated
      post_name: slug
      status: status
      image: image
      _pivx_extrafield_achtergrond:  image-background
      _pivx_extrafield_youtube: video
      galleryimagelist: gallery
    category: categories
    tags: tags      

  attachment: # Wordpress entries..
    targetcontenttype: attachments
    #author: admin
    fields:
      post_title: title
      post_author: username
      attachment_url: url
      _wp_attached_file: image
      post_content: body
      post_id: id
      post_date: datecreated
      post_name: slug
      status: status
      post_parent: parent
      post_parent_contenttype: "entries"

  page: # Wordpress pages / PivotX pages..
    targetcontenttype: pages
    #author: admin
    fields:
      post_title: title
      post_author: username
      post_excerpt: body
      post_id: id
      post_date: datecreated
      post_name: slug
      status: status
      image: image

what do I do wrong as the import does not import the extrafields

hansfn commented 8 years ago
  1. Please format your three pieces of code as code ...
  2. Please provide some lines around the example code from entries.xml

I have successfully imported extrafields, but I don't see exactly what you are doing wrong. Slightly better formatted info will help :-)

bcmans commented 8 years ago

hi hans! thanks for you help

hansfn commented 8 years ago

The XML code from entries.xml is still unreadable. Have you marked it as code using angle brackets in the menu - you should have 3 back ticks on a separate line before and after the code. Example of wanted output:

<tag1>Some text </tag1>
hansfn commented 8 years ago

While I'm waiting for you to fix the display of XML code in your issue, I used the login you sent me to your Bolt site. I have 2 important observations:

  1. In importwxr.bolt.yml you had added the extrafields to the PivotX entries mapping, not the Wordpress entries mapping. If you look at https://github.com/bolt/ImportWXR/blob/master/config.yml.dist you'll see that you no longer should use a PivotX specific mapping.
  2. I also noticed that you used _pivx_extrafield_achtergrond in stead of pivx_extrafield_achtergrond (and similar).

I have fixed your importwxr.bolt.yml, but I haven't run the import to avoid breaking anything on your site.

bcmans commented 8 years ago

finally (sorry) i got the ` correct now

  1. thank you 2 sorry (mistake)

I ran the script but the import was not correct yet You can run the script if you like (website is not live)

thanks!

bcmans commented 8 years ago

Hi Hans

I also made the data xml file a bit smaller so you see the records with the extra fields when you run the import script. thanks!

hansfn commented 8 years ago

OK, I have tracked down the bug - see issue #13. (You can close this issue.)

Some comments to the code you have posted in the issue:

PS! To get the embed magic for Youtube videos to work for the newly imported entries, you have to edit the field in Bolt. And an X and the remove it again. If you have a lot of entries with Youtube videos you have some work to do ...