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
This commit is contained in:
Mikael Nordfeldth 2015-03-06 00:44:00 +01:00
parent 72015d499f
commit f35ea45e09
2 changed files with 19 additions and 6 deletions

View File

@ -316,12 +316,12 @@ class EmailsettingsAction extends SettingsAction
$user = $this->scoped->getUser(); $user = $this->scoped->getUser();
if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) { if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
$emailnotifysub = $this->boolean('emailnotifysub'); $emailnotifysub = $this->booleanintstring('emailnotifysub');
$emailnotifymsg = $this->boolean('emailnotifymsg'); $emailnotifymsg = $this->booleanintstring('emailnotifymsg');
$emailnotifynudge = $this->boolean('emailnotifynudge'); $emailnotifynudge = $this->booleanintstring('emailnotifynudge');
$emailnotifyattn = $this->boolean('emailnotifyattn'); $emailnotifyattn = $this->booleanintstring('emailnotifyattn');
$emailmicroid = $this->boolean('emailmicroid'); $emailmicroid = $this->booleanintstring('emailmicroid');
$emailpost = $this->boolean('emailpost'); $emailpost = $this->booleanintstring('emailpost');
$user->query('BEGIN'); $user->query('BEGIN');

View 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 * Integer value of an argument
* *