Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

AuditLog of many_many?


Go to End


2 Posts   749 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

29 September 2014 at 4:35pm

Hi,

We have an audit log that records all changes for data objects using a decorator and onBeforeWrite and onBeforeDelete to determine changes and write them - but there isn't anything I can see that will aid us it determining changes to the relationships - which is very often key - e.g. "The member is in the wrong group and I never put them there..."

I can only see the option to hack framework ss to log the change directly for add / addMany / remove / removeAll or enhance framework to extend the above to the DataExtention.

Can anyone please advise me differently?

Avatar
swaiba

Forum Moderator, 1899 Posts

30 September 2014 at 4:18pm

As this has now been resolved... I thought I'd update the thread... using a custom class as a wrapper to allow us to log, but not hack the framework...

Object::useCustomClass('ManyManyList', 'MyManyManyList', true);

class MyManyManyList extends ManyManyList {

	public function add($item, $extraFields = null) {
		parent::add($item, $extraFields);

		if(!$this->IgnoreFromSaving()){
			//do logging
		}
	}

	public function removeByID($itemID) {
		if(!$this->IgnoreFromSaving()) {
			//do logging
		}
		
		parent::removeByID($itemID);
	}

	public function removeAll() {
		if(!$this->IgnoreFromSaving()){
			//do logging
		}

		parent::removeAll();
	}
}