views:

85

answers:

3

I am creating a CMS and am using serialize to handle publish and rollback, which seems to work fine. Basically, The normal site tables are what gets displayed and anything not displayed is serialized in a separate table. The problem however is in making the 'Preview' functions work.

Since the front end is created using normal SQL calls, and all the pre-published/rolled back data is in a separate table it would mean updating every sql statement with some fancy code to pull the version correct to the preview. It will also get especially problematic with things like limits etc and would be a nightmare for the front end.

The only other approach I can see is a separate database/table(s) for the preview copy, but many people may be using the preview function and I am loathe to create a duplicate database for every person using preview as it will very quickly get out of hand.

Is there any way of doing this that will allow preview, and rollback preview, but will not require much from the code that displays the contents of the database and also avoid the problem of mass duplication?

A: 

If you seperate Model, View and Controller, this should be no problem: You just take the model from somewhere else in the controller and pass it on to the view.

eWolf
Sorry, but what has that got to do with anything?
Meep3D
A: 

What eWolf means is that when you have a seperate model and view you can have your model supplying different data to the view and then you don't need to copy your database, but instead simply create a standard and a preview model.

The preview model doesn't have to make queries to the database but instead delivers the data that you store in it before passing it to the view.

Consider this example:

//in the controller:
$previewPage->setTitle("foo");
...
//in the view(when previewing):
$previewPage->getTitle(); // returns whatever you stored beforehand

//in the view(regular viewing):
$livePage->getTitle(); // queries the database and returns the result

To learn more about the Model-View-Controller pattern you might want to check out this article.

I hope that helps.

André Hoffmann
I am fairly familiar with MVC. The problem is it would basically disallow anyone from ever using SQL ever, either reads or writes. CMS Modules are expected to handle themselves and I would like the whole process to be transparent to them to keep things simple.
Meep3D
+1  A: 

I'm not sure that storing your content data in more than 1 table depending on its state is the way to go.

I would store every version of the content in the same table, having a field which purpose would be to set the state of the content (old version, current version, currently being edited, whatever you want depending on your content editing workflow). That kind of status field plus a date date, would make your content versions way easier to manage.

I used this method for various applications, and was always satisfied with how easy it was to implement rollbacks, previews and even more complex stuff (cvs-like pseudo-branches, ...).

Nicolas