开发者

CakePHP save snapshot of data as XML/JSON

I have a CakePHP/MySQL app which stores Job data in a variety of tables.

The Job data is used to eventually generate Reports. However I need to implement a way of creating Report Versions so that if Job data is modified a new Report version is created. It must keep a copy of all versions created.

I thought I'd approach this by having a Reports table associated with the Job table that takes an XML snapshot of the Job data. Whenever a Report is generated it creates a new Report record with a unique ID and associated Job ID along with an XML 'snapshot' of the data at that point.

Is this a sensible approach? I'm reluctant to store the xml snapshot as a file as there will be several thousand reports generated and I would like to keep the data secure in the database.

Lastly, How would I best go about saving the XML to the DB? I'm using the XML Helper to generate the XML of the data but having trouble saving this. I'm certain this is due to the size of the XML generated (The Job I'm testing with generates 600+ lines of XML and comes in at 41KiB when manually inserted into DB...).

Am I going about this totally the wrong way? It feels right, given that I need to store 'snapshots' of the data and can then use the XML Parser in later processing. Would JSON be more practical (I'm not all too familier with how I could use JSON data or whether it would be as structured...)

If anyone could help me out on this, I would most grateful.


UPDATE: I've managed to get it to save the XML by having it generated in the save function and then开发者_如何学Go adding it to a $data array thats saved. But it's still racking up storage. Any ideas on a more efficient way of doing this?


Have you considered alkemann's Revision behavior?

Sounds like it might do what you're looking for (without involving XML).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜