]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Start and End EmailSaveForm events now take a scoped profile
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 13 Jul 2014 13:42:15 +0000 (15:42 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 13 Jul 2014 13:42:15 +0000 (15:42 +0200)
EVENTS.txt
actions/emailsettings.php
plugins/EmailSummary/EmailSummaryPlugin.php

index 5b6483093e45a2996702cb91fadfb90d5abd93d8..255869afda41845dd1cd1654358d443f37aaf599 100644 (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
 - $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)
 - $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
 - $action: action object being shown
index 117c4c4f7c21519f0b2ca031ef2bb0eab7137de3..cc1a345f09cdce080e4e2b707b882f92548a7dca 100644 (file)
@@ -322,7 +322,7 @@ class EmailsettingsAction extends SettingsAction
     {
         $user = common_current_user();
 
-        if (Event::handle('StartEmailSaveForm', array($this, &$user))) {
+        if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
             $emailnotifysub   = $this->boolean('emailnotifysub');
             $emailnotifyfav   = $this->boolean('emailnotifyfav');
             $emailnotifymsg   = $this->boolean('emailnotifymsg');
@@ -355,7 +355,7 @@ class EmailsettingsAction extends SettingsAction
 
             $user->query('COMMIT');
 
-            Event::handle('EndEmailSaveForm', array($this));
+            Event::handle('EndEmailSaveForm', array($this, $this->scoped));
 
             // TRANS: Confirmation message for successful e-mail preferences save.
             $this->showForm(_('Email preferences saved.'), true);
index da94322411c533e59a4a1c15b7be69d043678968..da682e0454e2834054ff298bb95ed894a5d278a5 100644 (file)
@@ -115,39 +115,35 @@ class EmailSummaryPlugin extends Plugin
      * Add a checkbox to turn off email summaries
      *
      * @param Action $action Action being executed (emailsettings)
+     * @param Profile $scoped Profile for whom settings are configured (current user)
      *
      * @return boolean hook value
      */
-    function onEndEmailSaveForm($action)
+    public function onEndEmailSaveForm(Action $action, Profile $scoped)
     {
         $sendSummary = $action->boolean('emailsummary');
 
-        $user = common_current_user();
-
-        if (!empty($user)) {
-
-            $ess = Email_summary_status::getKV('user_id', $user->id);
+        $ess = Email_summary_status::getKV('user_id', $scoped->id);
 
-            if (empty($ess)) {
+        if (empty($ess)) {
 
-                $ess = new Email_summary_status();
+            $ess = new Email_summary_status();
 
-                $ess->user_id      = $user->id;
-                $ess->send_summary = $sendSummary;
-                $ess->created      = common_sql_now();
-                $ess->modified     = common_sql_now();
+            $ess->user_id      = $scoped->id;
+            $ess->send_summary = $sendSummary;
+            $ess->created      = common_sql_now();
+            $ess->modified     = common_sql_now();
 
-                $ess->insert();
+            $ess->insert();
 
-            } else {
+        } else {
 
-                $orig = clone($ess);
+            $orig = clone($ess);
 
-                $ess->send_summary = $sendSummary;
-                $ess->modified     = common_sql_now();
+            $ess->send_summary = $sendSummary;
+            $ess->modified     = common_sql_now();
 
-                $ess->update($orig);
-            }
+            $ess->update($orig);
         }
 
         return true;