Published by Fabian on 26 Aug 2007
lets get … technical – symfony: Propel export and import data
Okay, the intention of this blog was to share also thoughts and tips about software development. So here something I worked with the last two day:
Exporting and importing data with propel as ORM layer.
I read already sometime about problems with exporting and importing data. I can see that the functionality behind that is not that elaborated as it is only a side task. However, I wanted to achieve two things:
- test all forms in our web application
- save that data as fixtures for future reuse.
Up to now our fixtures were like “hello world” & “dummy 123″ which works for most functionality, but doe snot work for other things, e.g. layout. But there is no good way to generate the data. So I took the hard way, which actually allowed me to user test ALL forms in one go. Normally we had tested them when we created them, but I had to notice that some changes broke some behavior (nothing critical, also a lot of cosmetical things). So I fixed those, and created tons of data. So whats next:
(new sfPropelData())->dumpData(SF_ROOT_DIR . '/data');
Hangs, out of memory, or just stops, with no data generated. The script is very silent, and the code of the 1.0 version not very telling, so I checked the latest version from trac, which had undergone a major overhaul by Fabien.
My initial guess was right, and an added echo in fixOrderingOfForeignKeyData() proved that this was hanging in an endless loop.
Why? because the sfPropelData resolves FK based on tables, not on rows. Which means that between two tables there should be FK’s only in one direction. We had two. An Entity belonged to a Section, and a Section should be also an Entity. This led to that Propel class always changing order of those two tables. Of course a row in Section could reference an Entity that does belong to no, or a different Section and this would not loop, but on table level this is a loop.
I resolved this by removing the FK from Section to Entity and doing the lookup in code myself. After that and a patch I made to the SfPropelData (sent to Fabien and included) it worked great and produced a lot of fixture data. There was still another problem with a null FK, but I also resolved that and sent patch to Fabien (in that case, an Entity not belonging to a section would render following YAML: section_id : Section_ ). Trac issues will follow. I should take all my accounts with me, but I didn’t, so it have to look it up at home.
So the message is: if you have problems with importing and exporting with 1.0.x of symfony and Propel, go ahead and check out the latest trunk version of the propel addon classes.