tags:

views:

57

answers:

2

I need to build a simple change log for my application.

I have two tables: Store and Item.
I want to log each time a user updates info on store / item, and each time a user creates / deletes an association between item and store. (A user can associate an item with multiple stores).

The purpose is for the owner of that item, to see who has done any changes to that item.

What is the best way of doing this? I'm trying to avoid using a complicated logging system (since it might be a overkill).

I'm hoping that I can avoid manually calling a function each time a user clicks a button - because then I can easilly forgett to add that function for a button. So some kind of automatic logging based on user action would be sweet :)

I'm building my application in PHP using Wordpress as Framework.

A: 

First of all, wordpress is CMS, not framework.

Second, when user does an action that you want to log, just call a function you created for that purpose, which saves action to txt/xml/database. A few call are needed, not plenty.

usoban
I know it's a CMS - but in my termonology it's a framework for my propject.
Steven
A: 

The number of times you make the call shouldn't be that many (and you should be familiar enough with your own codebase) that you should be able to make a simple function like log($user,'action','related') which stores that data either in plain text or in a similarly defined database table.

TheLordRedbeard
Yup, that was my first approach to. But then I started thinking.... :) I thought maybe there was a common way of doing this - like 'business best practice"
Steven
It is, Observer pattern, but first of all, worpress is not written using objects and I havent' seen procedural code using patterns. And after all, it's not that simple to implement, so you should really concider rather calling those few functions.
usoban
Thanks Red Beard :) I'm just justing Wordpress as a framework - for managing users (and some content). My "plugin" is more or less WP independant, working with it's own tables. I might have a look at this later down the road: http://www.a-scripts.com/object-oriented-php/2009/02/21/the-observer-pattern. For now I'll just trigger a function for each time a user does a specific action.
Steven