Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix an edge case where invalid JSON is written the database. Fixes bu…
…g #12303.
  • Loading branch information
perlDreamer committed Nov 21, 2011
1 parent b1133d9 commit 200494b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docs/upgrades/upgrade_7.10.23-7.10.24.pl
Expand Up @@ -34,6 +34,7 @@ BEGIN
addPALastLogTable($session);
addForkRedirect($session);
extendBucketName($session);
fixSurveyQuestionTypes($session);

finish($session); # this line required

Expand Down Expand Up @@ -81,6 +82,19 @@ sub extendBucketName {
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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm
Expand Up @@ -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;
}
Expand Down

0 comments on commit 200494b

Please sign in to comment.