From f35ea45e09a344f405f4a4c45f1c6a34d7e835e0 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 6 Mar 2015 00:44:00 +0100 Subject: [PATCH] Values of 0 would not be updated because of DB_DataObject Upstream bug causing (int)0 to be interpreted as a "null string": https://pear.php.net/bugs/bug.php?id=20291 --- actions/emailsettings.php | 12 ++++++------ lib/action.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/actions/emailsettings.php b/actions/emailsettings.php index 47c6fe54e5..fb61b2a05f 100644 --- a/actions/emailsettings.php +++ b/actions/emailsettings.php @@ -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'); diff --git a/lib/action.php b/lib/action.php index d8b691093c..66a5c69a71 100644 --- a/lib/action.php +++ b/lib/action.php @@ -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 * -- 2.39.5