Hi there, I have the requirement to build a functionality where I’ll send a mail to an admin user if any user belonging to a given group has taken any changes, my first approach was to create a plugin and attach it to the OnUserProfileSave
event, but after testing I realized that both in my code, as well as MODx internally, there were calls to $profile->save();
, thus generating the event every time as the modUserProfile is intended to do it:
public function save($cacheFlag = null)
{
$isNew = $this->isNew();if ($this->xpdo instanceof modX) { $this->xpdo->invokeEvent('OnUserProfileBeforeSave', array( 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'userprofile' => &$this, 'cacheFlag' => $cacheFlag, )); } $saved = parent:: save($cacheFlag); if ($saved && $this->xpdo instanceof modX) { $this->xpdo->invokeEvent('OnUserProfileSave', array( 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'userprofile' => &$this, 'cacheFlag' => $cacheFlag, )); } return $saved; }
Having said that, what should be the right way to catch the and event related to a profile change?