Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Importing & Exporting Nodes with Neos

Importing & Exporting Nodes with Neos

Wondering how to use the site import / export features during development and while delivering / maintaining a project? Do you have the need to import content from various sources into your brand new Neos project?
These slides give you an overview of how to get the most out of the import / export commands and will show you how an import of content can be done through code in various ways.

Karsten Dambekalns

July 18, 2015
Tweet

More Decks by Karsten Dambekalns

Other Decks in Programming

Transcript

  1. Importing & Exporting
    Nodes with Neos

    View full-size slide

  2. Karsten Dambekalns
    Neos and Flow developer
    37 years old
    lives in Lübeck
    is a Flownative
    1 wife, 3 sons
    1 manual espresso maker
    likes canoeing & climbing

    View full-size slide

  3. Where is my data?

    View full-size slide

  4. A node is the smallest unit in which
    Neos stores content. A node can
    represent a document or pieces of
    content on a document, so nodes
    can be nested.
    Node

    View full-size slide

  5. The content repository is the storage
    for all nodes.
    Content Repository

    View full-size slide

  6. Database
    The content repository uses a
    regular relational database to store
    nodes and their properties.
    Actively dealing with that should be
    the exception to the rule.

    View full-size slide

  7. Site package
    In Neos the site package acts as a
    container for all assets a site needs
    and can also contain the site content.

    View full-size slide

  8. Sites.xml
    Site content can be exported to an
    XML file in the site package or
    elsewhere. That file contains the
    structure, content.
    Used assets of a site can be
    contained there or be exported
    alongside.

    View full-size slide

  9. Common Tasks

    View full-size slide

  10. Import freshly
    kickstarted site

    View full-size slide

  11. $  flow  kickstart:site  -­‐-­‐package-­‐key  Neos.Sprint  
    -­‐-­‐site-­‐name  'Neos  Sprint  Nuremberg'  
    Created  .../Sites.xml  
    Created  .../Root.ts2  
    Created  .../Default.html  
    Created  .../NodeTypes.yaml  
    $  flow  site:import  -­‐-­‐package-­‐key  Neos.Sprint  
    Import  of  site  "Neos  Sprint  Nuremberg"  finished.

    View full-size slide

  12. Export to the
    site package

    View full-size slide

  13. $  flow  site:export  -­‐-­‐package-­‐key  Neos.Sprint  
    All  sites  have  been  exported  to  package  
    "Neos.Sprint".

    View full-size slide

  14. $  flow  site:export  -­‐-­‐tidy  -­‐-­‐package-­‐key  Neos.Sprint  
    All  sites  have  been  exported  to  package  
    "Neos.Sprint".

    View full-size slide

  15. Use the tidy option if
    you want to be able to
    read diffs between
    states.

    View full-size slide

  16. Export to
    standard output

    View full-size slide

  17. $  flow  site:export  -­‐-­‐tidy  >  site-­‐export.xml  
    $  flow  site:export  -­‐-­‐tidy  
     
     
     siteResourcesPackageKey="Neos.Sprint"  
    siteNodeName="sprint">  
         
         ef20-­‐9d5e-­‐6fd5578c9713"  nodeName="sprint">  
           nodeType="TYPO3.Neos.NodeTypes:Page"  version="1"  

    View full-size slide

  18. Export to a file

    View full-size slide

  19. $  flow  site:export  -­‐-­‐filename  site-­‐export.xml  
    All  sites  have  been  exported  to  "site-­‐
    export.xml".

    View full-size slide

  20. Export to a package
    or file to have
    resources exported to
    individual files.

    View full-size slide

  21. Multiple site exports

    View full-size slide

  22. Why would you need
    more than one site
    export in a project?

    View full-size slide

  23. Showcase available
    node types.

    View full-size slide

  24. Provide a fixture for
    automated testing.

    View full-size slide

  25. Have a “demo site”
    giving an impression
    of how the final site
    could look like.

    View full-size slide

  26. Deliver base structure
    for a site to the client.
    Removal of nodes is not supported,
    import only adds/updates currently.

    View full-size slide

  27. $  flow  site:export  -­‐-­‐filename  site-­‐base.xml  
    All  sites  have  been  exported  to  “site-­‐base.xml".  
    $flow  site:prune  
    All  sites  and  content  have  been  removed.  
    $flow  site:import  -­‐-­‐package-­‐key  Neos.Sprint  
    Import  of  site  "Neos  Sprint  Nuremberg"  finished.  
    $flow  site:import  -­‐-­‐filename  base-­‐structure.xml  
    Import  of  site  "Neos  Sprint  Nuremberg"  finished.

    View full-size slide

  28. Creating content
    through code

    View full-size slide

  29. Warning: Only some
    user serviceable
    parts inside

    View full-size slide

  30. Option I
    Generate XML

    View full-size slide

  31. Option II
    Create nodes in PHP

    View full-size slide

  32. Generating valid
    node names
    use  \TYPO3\TYPO3CR\Utility;  
    Utility::renderValidNodeName($name);

    View full-size slide

  33. Use NodeTemplate
    $tpl  =  new  NodeTemplate();  
    …  
    $node  =  $parent  
    -­‐>createNodeFromTemplate($tpl);

    View full-size slide

  34. Handle node variants in all
    workspaces in case an editor
    has modified it and not
    published it yet.
    Otherwise the data gets
    overwritten again when the
    editor publishes.

    View full-size slide

  35. When importing,
    re-use existing tooling.

    View full-size slide

  36. This will avoid memory
    and performance issues
    by batch processing.

    View full-size slide

  37. Generate a lot of nodes
    for up-front testing, to
    see how the system will
    perform when you
    imported in the end.

    View full-size slide

  38. Import performance

    View full-size slide

  39. When using the Node API
    performance issues will
    come up eventually.

    View full-size slide

  40. You may need to use
    NodeData directly.

    View full-size slide

  41. Do not
    get used to
    working with
    NodeData.
    While needed for fast and memory-conserving imports, it is not public API and should be used with great care.

    View full-size slide

  42. Be prepared to handle
    things like updating the
    node index, flushing the
    content cache and setting
    uriPathSegment manually.

    View full-size slide

  43. Option III
    Do not import

    View full-size slide

  44. Fetch content on-the-fly
    If you can fetch (some) of the content
    from an external source, like Redis or
    Elasticsearch, you could just use an
    Eel helper in TypoScript to pass it to
    the rendering.
    No “real” nodes, but still cached in
    the content cache, hence fast.

    View full-size slide

  45. Option IV
    Content Object Proxy

    View full-size slide

  46. Use content objects
    If you have your data in some Flow
    application anyway, or it makes
    sense to have it as entities, you can
    add a content object to a node.
    The node acts as a proxy to the
    entity, exposing its properties.

    View full-size slide

  47. Questions?
    Ideas?

    View full-size slide

  48. karsten@flownative.com
    www.flownative.com
    @kdambekalns
    share your thoughts

    View full-size slide

  49. www.flownative.com

    View full-size slide