By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

Item changelogs and rollback

P: n/a
I have been wanting to add a changelog capability to our in house CMS
system. The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.

I would like to add this capability for 2 reasons:

a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary

The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. What
I'd really like to do is store the difference between the current and
the previous version.

Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.
Sep 29 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Gordon wrote:
I have been wanting to add a changelog capability to our in house CMS
system. The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.

I would like to add this capability for 2 reasons:

a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary

The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. What
I'd really like to do is store the difference between the current and
the previous version.

Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.
You can do it, but it will be complicated. If you can exec() diff and
patch, that will help (but you'll have to save the article to a file
temporarily, anyway). Otherwise you'll need to write your own code to
get the differences and make the changes.

I think it would be easier to just store the entire article. They
aren't that big, are they?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 29 '08 #2

P: n/a
On 29 Sep, 12:39, Gordon <gordon.mc...@ntlworld.comwrote:
I have been wanting to add a changelog capability to our in house CMS
system. The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.

I would like to add this capability for 2 reasons:

a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary

The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. What
I'd really like to do is store the difference between the current and
the previous version.

Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.
Why not use diff with temporary files (see also man patch). But it
might just be simpler to maintain the content in numbered files via
CVS?

C.
Sep 29 '08 #3

P: n/a
On Sep 29, 12:53*pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On 29 Sep, 12:39, Gordon <gordon.mc...@ntlworld.comwrote:
I have been wanting to add a changelog capability to our in house CMS
system. *The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.
I would like to add this capability for 2 reasons:
a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary
The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. *What
I'd really like to do is store the difference between the current and
the previous version.
Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.

Why not use diff with temporary files (see also man patch). But it
might just be simpler to maintain the content in numbered files via
CVS?

C.
My first thought was to do that, but to be honest I'd rather not be
dependant on a host having particular extermal programs available, as
the CMS needs to run in several different environments and with
different configurations. Some will have the exec() function disabled,
some won't have Diff installed (for example PHP on a Windows server).
I did take a brief look at xdiff but ruled it out for the same
reason.

The MediaWiki software seems to support what I want to be able to do
without resorting to extensions or external programs, but
unfortunately the MediaWiki source code is rather tricky to follow and
I've not managed to work out how it works yet.
Sep 29 '08 #4

P: n/a
r0g
Gordon wrote:
On Sep 29, 12:53 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
>On 29 Sep, 12:39, Gordon <gordon.mc...@ntlworld.comwrote:
>>I have been wanting to add a changelog capability to our in house CMS
system. The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.
I would like to add this capability for 2 reasons:
a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary
The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. What
I'd really like to do is store the difference between the current and
the previous version.
Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.
Why not use diff with temporary files (see also man patch). But it
might just be simpler to maintain the content in numbered files via
CVS?

C.

My first thought was to do that, but to be honest I'd rather not be
dependant on a host having particular extermal programs available, as
the CMS needs to run in several different environments and with
different configurations. Some will have the exec() function disabled,
some won't have Diff installed (for example PHP on a Windows server).
I did take a brief look at xdiff but ruled it out for the same
reason.

The MediaWiki software seems to support what I want to be able to do
without resorting to extensions or external programs, but
unfortunately the MediaWiki source code is rather tricky to follow and
I've not managed to work out how it works yet.

I know it feels inefficient but you'd have to have an awful lot of
articles and an awful lot of revisions to make this a practical problem,
plus you'd be making your code slower and more complex; premature
optimisation yada yada yada...

If you expect your system to be used at the kind of scales where this
might be a serious issue how about datestamping and retiring your old
revisions from the database after a set period? You could have it zip
and mail you these as they are retired just dredge them back from your
backups if it turned out you needed them.

For something like this you may also want to consider just using flat
files, space is cheap and old revisions aren't likely to be needed that
often, why make your DB backups take longer?

If you are undissuadable then here's an implementation of diff in PHP
that may help... http://www.holomind.de/phpnet/diff.src.php

:-)

Roger Heathcote.
Sep 29 '08 #5

P: n/a
On Sep 29, 6:07*pm, r0g <aioe....@technicalbloke.comwrote:
Gordon wrote:
On Sep 29, 12:53 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On 29 Sep, 12:39, Gordon <gordon.mc...@ntlworld.comwrote:
>I have been wanting to add a changelog capability to our in house CMS
system. *The approach I was thinking of was adding a changelog table
to the database. It records the ID of the editor, the timestamp of
when the edit occurred and a list of changes made to the item
edited.
I would like to add this capability for 2 reasons:
a) To see what changes have been made to an article since its last
edit
b) To be able to "roll back" changes to an earlier revision if
necessary
The easy way would be to simply store the entire text of the article
each time in the changelog, but that is of course very wasteful. *What
I'd really like to do is store the difference between the current and
the previous version.
Is there a way of achieving this in PHP? I found a few functions in
the manual that claim to analyse strings and work out the differences
but these functions seem to return integers, and what I'd ideally need
is something akin to the output of utilities like diff.
Why not use diff with temporary files (see also man patch). But it
might just be simpler to maintain the content in numbered files via
CVS?
C.
My first thought was to do that, but to be honest I'd rather not be
dependant on a host having particular extermal programs available, as
the CMS needs to run in several different environments and with
different configurations. Some will have the exec() function disabled,
some won't have Diff installed (for example PHP on a Windows server).
I did take a brief look at xdiff but ruled it out for the same
reason.
The MediaWiki software seems to support what I want to be able to do
without resorting to extensions or external programs, but
unfortunately the MediaWiki source code is rather tricky to follow and
I've not managed to work out how it works yet.

I know it feels inefficient but you'd have to have an awful lot of
articles and an awful lot of revisions to make this a practical problem,
plus you'd be making your code slower and more complex; premature
optimisation yada yada yada...

If you expect your system to be used at the kind of scales where this
might be a serious issue how about datestamping and retiring your old
revisions from the database after a set period? You could have it zip
and mail you these as they are retired just dredge them back from your
backups if it turned out you needed them.

For something like this you may also want to consider just using flat
files, space is cheap and old revisions aren't likely to be needed that
often, why make your DB backups take longer?

If you are undissuadable then here's an implementation of diff in PHP
that may help...http://www.holomind.de/phpnet/diff.src.php

:-)

Roger Heathcote.
Thanks for the script, I'll take a look into it when I can. I know
just saving the whole article every time would be easier, but I like a
challenge. :) Besides, to do the feature where you can see how one
revision differs from another would require some kind of way of
discovering the differences between two strings anyway. And from an
aesthetic point of view the idea of storing another entire copy just
for one or two corrected spelling mistakes just bothers me. It's not
a massively high priority feature, but as more and more users (most of
whom could find a way of screwing up a recipie for boiled eggs :P )
get added to the system a day is eventually going to come where
somebody does something they shouldn't.
Sep 29 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.