Start and End EmailSaveForm events now take a scoped profile

This commit is contained in:
Mikael Nordfeldth 2014-07-13 15:42:15 +02:00
parent c8873de08b
commit 933bf0b026
3 changed files with 19 additions and 23 deletions

View File

@ -300,11 +300,11 @@ EndEmailFormData: just after showing form input fields on email settings page
StartEmailSaveForm: before starting to save a email settings form StartEmailSaveForm: before starting to save a email settings form
- $action: action object being shown - $action: action object being shown
- &$user: user being saved - $scoped: Profile user having their email settings saved
EndEmailSaveForm: after saving a email settings form (after commit) EndEmailSaveForm: after saving a email settings form (after commit)
- $action: action object being shown - $action: action object being shown
- &$user: user being saved - $scoped: Profile user having their email settings saved
StartRegistrationFormData: just before showing text entry fields on registration page StartRegistrationFormData: just before showing text entry fields on registration page
- $action: action object being shown - $action: action object being shown

View File

@ -322,7 +322,7 @@ class EmailsettingsAction extends SettingsAction
{ {
$user = common_current_user(); $user = common_current_user();
if (Event::handle('StartEmailSaveForm', array($this, &$user))) { if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
$emailnotifysub = $this->boolean('emailnotifysub'); $emailnotifysub = $this->boolean('emailnotifysub');
$emailnotifyfav = $this->boolean('emailnotifyfav'); $emailnotifyfav = $this->boolean('emailnotifyfav');
$emailnotifymsg = $this->boolean('emailnotifymsg'); $emailnotifymsg = $this->boolean('emailnotifymsg');
@ -355,7 +355,7 @@ class EmailsettingsAction extends SettingsAction
$user->query('COMMIT'); $user->query('COMMIT');
Event::handle('EndEmailSaveForm', array($this)); Event::handle('EndEmailSaveForm', array($this, $this->scoped));
// TRANS: Confirmation message for successful e-mail preferences save. // TRANS: Confirmation message for successful e-mail preferences save.
$this->showForm(_('Email preferences saved.'), true); $this->showForm(_('Email preferences saved.'), true);

View File

@ -115,39 +115,35 @@ class EmailSummaryPlugin extends Plugin
* Add a checkbox to turn off email summaries * Add a checkbox to turn off email summaries
* *
* @param Action $action Action being executed (emailsettings) * @param Action $action Action being executed (emailsettings)
* @param Profile $scoped Profile for whom settings are configured (current user)
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onEndEmailSaveForm($action) public function onEndEmailSaveForm(Action $action, Profile $scoped)
{ {
$sendSummary = $action->boolean('emailsummary'); $sendSummary = $action->boolean('emailsummary');
$user = common_current_user(); $ess = Email_summary_status::getKV('user_id', $scoped->id);
if (!empty($user)) { if (empty($ess)) {
$ess = Email_summary_status::getKV('user_id', $user->id); $ess = new Email_summary_status();
if (empty($ess)) { $ess->user_id = $scoped->id;
$ess->send_summary = $sendSummary;
$ess->created = common_sql_now();
$ess->modified = common_sql_now();
$ess = new Email_summary_status(); $ess->insert();
$ess->user_id = $user->id; } else {
$ess->send_summary = $sendSummary;
$ess->created = common_sql_now();
$ess->modified = common_sql_now();
$ess->insert(); $orig = clone($ess);
} else { $ess->send_summary = $sendSummary;
$ess->modified = common_sql_now();
$orig = clone($ess); $ess->update($orig);
$ess->send_summary = $sendSummary;
$ess->modified = common_sql_now();
$ess->update($orig);
}
} }
return true; return true;