Fix an edge case where invalid JSON is written the database. Fixes bug #12303.

This commit is contained in:
Colin Kuskie 2011-11-20 22:24:14 -08:00
parent b1133d9118
commit 200494b28d
3 changed files with 16 additions and 1 deletions

View file

@ -5,6 +5,7 @@
- fixed #12269: Login / Loginbox with encryptlogin
- fixed #12271: Calendar List View does not always show labels
- fixed Passive Analytics, UI, Progress Bar, server load.
- fixed #12303: Survey custom multiple choice question types
7.10.23
- fixed #12225: Stock asset, multiple instances on a page

View file

@ -34,6 +34,7 @@ my $session = start(); # this line required
addPALastLogTable($session);
addForkRedirect($session);
extendBucketName($session);
fixSurveyQuestionTypes($session);
finish($session); # this line required
@ -81,6 +82,19 @@ EOSQL
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
# Describe what our function does
sub fixSurveyQuestionTypes {
my $session = shift;
print "\tFix bad custom Question Types in the Survey... " unless $quiet;
# and here's our code
$session->db->write(<<EOSQL);
update Survey_questionTypes set answers="{}" where answers like 'HASH%';
EOSQL
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
# Describe what our function does
#sub exampleFunction {

View file

@ -169,7 +169,7 @@ sub addType {
my $questionType = shift;
my $address = shift;
my $question = $self->question($address);
my $ansString = $question->{answers} ? to_json $question->{answers} : {};
my $ansString = $question->{answers} ? to_json $question->{answers} : '{}';
$self->session->db->write("INSERT INTO Survey_questionTypes VALUES(?,?) ON DUPLICATE KEY UPDATE answers = ?",[$questionType,$ansString,$ansString]);
$question->{questionType} = $questionType;
}