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 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 Slide

  3. Where is my data?

    View 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 Slide

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

    View 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 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 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 Slide

  9. View Slide

  10. Common Tasks

    View Slide

  11. Import freshly
    kickstarted site

    View Slide

  12. $  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 Slide

  13. Export to the
    site package

    View Slide

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

    View Slide

  15. View Slide

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

    View Slide

  17. View Slide

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

    View Slide

  19. Export to
    standard output

    View Slide

  20. $  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 Slide

  21. Export to a file

    View Slide

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

    View Slide

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

    View Slide

  24. Multiple site exports

    View Slide

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

    View Slide

  26. Showcase available
    node types.

    View Slide

  27. Provide a fixture for
    automated testing.

    View Slide

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

    View Slide

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

    View Slide

  30. $  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 Slide

  31. Creating content
    through code

    View Slide

  32. Warning: Only some
    user serviceable
    parts inside

    View Slide

  33. Option I
    Generate XML

    View Slide

  34. Option II
    Create nodes in PHP

    View Slide

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

    View Slide

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

    View Slide

  37. 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 Slide

  38. When importing,
    re-use existing tooling.

    View Slide

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

    View Slide

  40. View Slide

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

    View Slide

  42. View Slide

  43. Import performance

    View Slide

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

    View Slide

  45. You may need to use
    NodeData directly.

    View Slide

  46. 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 Slide

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

    View Slide

  48. Option III
    Do not import

    View Slide

  49. 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 Slide

  50. Option IV
    Content Object Proxy

    View Slide

  51. 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 Slide

  52. Questions?
    Ideas?

    View Slide

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

    View Slide

  54. www.flownative.com

    View Slide