Unless you are starting with a fresh project, one of the first things you need to get done when starting with Neos is to migrate content from old TYPO3 installation.
To my surprise, I found almost zero information on this subject. There are great slides available by Karsten, but his awesome plugin is not ready yet, so I was stuck in the middle of nowhere with zero knowledge about the new system.
I hope this post will save you at least from part of frustration that I had gone through.
I needed to migrate only tt_news records, but you can easily adapt it to anything you need just grasp the methode.
1. Command Controller
The first question I had was where to put my migration code. Most apropriate is to create a command line task for that. Luckily Neos provides an easy way of creating command controllers. Here is a good tutorial on how to create one.
2. Get records from old TYPO3
Next I copied all of the relevant tables from old database to the new one.
I needed a few minutes to figure out how to deal with direct database connections, but it wasn’t hard. This is a function that retrieves all records of certain tt_news category, but you can use any query you want here.
3. Node template
I had defined my own node type: Sfi.Sfi:News to hold news records. Now to actually insert anything to TYPO3CR, you need to create a NodeTemplate object for every news record, and fill it in with relevant properties.
The simple properties were easy to nail:
I wanted my new News object to be really flexible in the future, so I decided to store bodytext in the mainContent child node.
TODO: I’ll need to parse bodytext for TYPO3 specific things like tag.
With images I had to spend even more time.
Here’s the code:
And this is how to create an image:
And finally, migrating files:
And a relevant file creation function:
Adding properties in different content dimensions
At first create the context for the different content dimensions.
Create the context before iterating your data.
While iterating your data, adopt the newly generated node into the context of the other content dimension.
Be sure to do this after setting all the properties you want to keep in the new context.