]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Values of 0 would not be updated because of DB_DataObject
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 5 Mar 2015 23:44:00 +0000 (00:44 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 5 Mar 2015 23:44:00 +0000 (00:44 +0100)
Upstream bug causing (int)0 to be interpreted as a "null string":
https://pear.php.net/bugs/bug.php?id=20291

actions/emailsettings.php
lib/action.php

index 47c6fe54e513a738cedf12a7275d6e8edcbbf19a..fb61b2a05f03ea7c3283fbf22c6cbd6cc2c0b3ec 100644 (file)
@@ -316,12 +316,12 @@ class EmailsettingsAction extends SettingsAction
         $user = $this->scoped->getUser();
 
         if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
-            $emailnotifysub   = $this->boolean('emailnotifysub');
-            $emailnotifymsg   = $this->boolean('emailnotifymsg');
-            $emailnotifynudge = $this->boolean('emailnotifynudge');
-            $emailnotifyattn  = $this->boolean('emailnotifyattn');
-            $emailmicroid     = $this->boolean('emailmicroid');
-            $emailpost        = $this->boolean('emailpost');
+            $emailnotifysub   = $this->booleanintstring('emailnotifysub');
+            $emailnotifymsg   = $this->booleanintstring('emailnotifymsg');
+            $emailnotifynudge = $this->booleanintstring('emailnotifynudge');
+            $emailnotifyattn  = $this->booleanintstring('emailnotifyattn');
+            $emailmicroid     = $this->booleanintstring('emailmicroid');
+            $emailpost        = $this->booleanintstring('emailpost');
 
             $user->query('BEGIN');
 
index d8b691093cc58a4489afdf213891513cb32cac03..66a5c69a719dd009bd00c2b661079300020203d9 100644 (file)
@@ -1356,6 +1356,19 @@ class Action extends HTMLOutputter // lawsuit
         }
     }
 
+    /**
+     * This is a cheap hack to avoid a bug in DB_DataObject
+     * where '' is non-type-aware compared to 0, which means it
+     * will always be true for values like false and 0 too...
+     *
+     * Upstream bug is::
+     * https://pear.php.net/bugs/bug.php?id=20291
+     */
+    function booleanintstring($key, $def)
+    {
+        return $this->boolean($key, $def) ? '1' : '0';
+    }
+
     /**
      * Integer value of an argument
      *