[FLOW3-general] Howto: Convert Data to Doctrine

Alexander Stehlik alexander.stehlik at googlemail.com
Sat Jul 9 01:53:14 CEST 2011


Hi everyone,

I just merged an application I wrote to the current master branch of 
FLOW3 that is using doctrine2 for persisting objects by default now.

The problem I faced was: How do I get my data from the "old" persistence 
framework of FLOW3 to the new doctrine. I didn't find any conversion 
scripts or something like that.

But I realized, the solution is not that complicated.

First of all: you can still use the classic persistence framework by 
creating a file Configuration/Objects.yaml (if you don't already have 
it) and putting these 2 lines in there:

TYPO3\FLOW3\Persistence\PersistenceManagerInterface:
   className: TYPO3\FLOW3\Persistence\Generic\PersistenceManager

But this is not what you need to do when you want to migrate your data.

The first thing you need to to is, apply the attached patch to your 
FLOW3 Package. This will make sure that the whole "Generic" persistence 
framework makes use of the generic persistence manager and not the one 
that is configured in Objects.yaml

Second step is: Make sure you marked all relations correctly with the 
@ManyToMany, @ManyToOne, @OneToOne etc. annotations, see [1] for more 
information. Please note that you don't need to set the "targetEntity" 
property because this is already specified in the @var annotation. You 
also have to create all needed tables with the flow3 command line using 
typo3.flow3:doctrine:update.

Third step: For every entity you want to persist, create an additional 
repository, eg. your model is "Post", create "PostRepositoryClassic". In 
this repository you need to add a method, that overwrites the 
injectPersistenceManager method and does NOTHING because it would inject 
the Doctrine persistence manager, which is not what we want.

Additionally you need to add a method that incjects the 
TYPO3\FLOW3\Persistence\Generic\PersistenceManager object (not the 
interface!). In this method, make sure to run 
$persistenceManager->initialize(), otherwise you will get an exception 
later on.

Now you are ready. Simply add a controller action that calls findAll() 
on the classic repository, loops over all entities and calls add() on 
your default repository. Your data is now in the new doctrine format.

I hope this is useful to some of you. If you need help / more 
information, please let me know.

Kind regards,
Alex

[1] 
http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-associations.html



More information about the FLOW3-general mailing list