From 2a4ed74cd01d55a0d0a4ab10d0764f666b3ab994 Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Fri, 14 Jan 2022 07:58:39 -0300 Subject: [PATCH] Fixed issue #17773: Code name change while we updated from Edit Question screen (#2201) Co-authored-by: encuestabizdevgit --- application/config/version.php | 2 +- application/helpers/update/updatedb_helper.php | 7 +++++++ .../admin/labels/_labelviewtabcontent_view.php | 2 +- .../Question/question_subviews/_modals.twig | 3 +++ assets/scripts/admin/answers.js | 15 ++++++++++++++- installer/create-database.php | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/application/config/version.php b/application/config/version.php index 8306bb9fcbf..5a681bfbd58 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -13,7 +13,7 @@ $config['versionnumber'] = '3.27.31'; -$config['dbversionnumber'] = 365; +$config['dbversionnumber'] = 366; $config['buildnumber'] = ''; $config['updatable'] = true; $config['templateapiversion'] = 3; diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index 13542f41ff5..dda322f4261 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -2542,6 +2542,13 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false) $oTransaction->commit(); } + // Allow label sets to contain full subquestion codes + if ($iOldDBVersion < 366) { + $oTransaction = $oDB->beginTransaction(); + alterColumn('{{labels}}', 'code', "string(20)", false); + $oDB->createCommand()->update('{{settings_global}}', ['stg_value' => 366], "stg_name='DBVersion'"); + $oTransaction->commit(); + } } catch (Exception $e) { Yii::app()->setConfig('Updating', false); diff --git a/application/views/admin/labels/_labelviewtabcontent_view.php b/application/views/admin/labels/_labelviewtabcontent_view.php index 71ce5fe2688..85baf22dfa1 100644 --- a/application/views/admin/labels/_labelviewtabcontent_view.php +++ b/application/views/admin/labels/_labelviewtabcontent_view.php @@ -44,7 +44,7 @@ ' /> - ' name='code_' maxlength='5' size='6' value=''/> + ' name='code_' maxlength='20' size='20' value=''/> diff --git a/application/views/admin/survey/Question/question_subviews/_modals.twig b/application/views/admin/survey/Question/question_subviews/_modals.twig index 50a9a698c77..62325ff384d 100644 --- a/application/views/admin/survey/Question/question_subviews/_modals.twig +++ b/application/views/admin/survey/Question/question_subviews/_modals.twig @@ -49,6 +49,9 @@
+
diff --git a/assets/scripts/admin/answers.js b/assets/scripts/admin/answers.js index 996f31996eb..020f8f773fa 100644 --- a/assets/scripts/admin/answers.js +++ b/assets/scripts/admin/answers.js @@ -450,6 +450,7 @@ function lsbrowser(e) $('#labelsets').select2(); $("#labelsetpreview").html(''); + $('#longcodesalert').hide(); // e.preventDefault(); var scale_id=window.LS.removechars($(this).attr('id')); var surveyid=$('input[name=sid]').val(); @@ -513,6 +514,7 @@ function lspreview(lid) $tabbody=$('
'), count=0; + var hasInvalidCodes = false; console.ls.group('LanguageParsing'); var i=0; @@ -548,12 +550,20 @@ function lspreview(lid) $listItem.append('
'); $listItem.attr('data-label', JSON.stringify(label)); $itemList.append($listItem); - + if (label.code.length > 5) { + hasInvalidCodes = true; + } }); console.ls.groupEnd('ParseLabels'); $bodyItem.append('

'+labelSet.label_name+'

'); $itemList.appendTo($bodyItem); + + if (hasInvalidCodes) { + $('#longcodesalert').show(); + } else { + $('#longcodesalert').hide(); + } console.ls.groupEnd('ParseLabelSet'); }); @@ -598,6 +608,9 @@ function transferlabels(type) var $tr = $row.eq(4); var randId = 'new'+Math.floor(Math.random()*10000); + // Make sure codes are limited to 5 characters + label.code = label.code.substr(0, 5); + // $tr.attr('data-common-id', $tr.attr('data-common-id').replace(/new[0-9]{3,6}/,randId)); // $tr.attr('id', $tr.attr('id').replace(/new[0-9]{3-5}/,randId)); diff --git a/installer/create-database.php b/installer/create-database.php index 195c8866c0a..91633f25590 100755 --- a/installer/create-database.php +++ b/installer/create-database.php @@ -143,7 +143,7 @@ function createDatabase($oDB){ $oDB->createCommand()->createTable('{{labels}}', array( 'id' => "pk", 'lid' => "integer NOT NULL DEFAULT 0", - 'code' => "string(5) NOT NULL default ''", + 'code' => "string(20) NOT NULL default ''", 'title' => "text", 'sortorder' => "integer NOT NULL", 'language' => "string(20) NOT NULL DEFAULT 'en'",