Skip to content

Commit

Permalink
Input to decodeTokenAttributes must not be null
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 29, 2023
1 parent dac9b88 commit fac323d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ function upgradeSurveys177()
$oSurveyResult = $oDB->createCommand($sSurveyQuery)->queryAll();
$sSurveyLSUpdateQuery = "update {{surveys_languagesettings}} set surveyls_attributecaptions=:attributecaptions where surveyls_survey_id=:surveyid and surveyls_language=:language";
foreach ($oSurveyResult as $aSurveyRow) {
$aAttributeDescriptions = decodeTokenAttributes($aSurveyRow['surveyls_attributecaptions']);
$aAttributeDescriptions = decodeTokenAttributes($aSurveyRow['surveyls_attributecaptions'] ?? '');
if (!$aAttributeDescriptions) {
$aAttributeDescriptions = array();
}
Expand All @@ -2208,7 +2208,7 @@ function upgradeSurveys177()
$oSurveyResult = $oDB->createCommand($sSurveyQuery)->queryAll();
$sSurveyUpdateQuery = "update {{surveys}} set attributedescriptions=:attributedescriptions where sid=:surveyid";
foreach ($oSurveyResult as $aSurveyRow) {
$aAttributeDescriptions = decodeTokenAttributes($aSurveyRow['attributedescriptions']);
$aAttributeDescriptions = decodeTokenAttributes($aSurveyRow['attributedescriptions'] ?? '');
if (!$aAttributeDescriptions) {
$aAttributeDescriptions = array();
}
Expand Down
4 changes: 2 additions & 2 deletions application/models/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ private function createColumnsInTokenTable($surveyId, array $newAttributes)
->from('{{surveys}}')
->bindParam(":sid", $surveyId, PDO::PARAM_INT);
$aTokenAttributes = $previousatt->queryRow();
$aTokenAttributes = decodeTokenAttributes($aTokenAttributes['attributedescriptions']);
$aTokenAttributes = decodeTokenAttributes($aTokenAttributes['attributedescriptions'] ?? '');

foreach ($fieldcontents as $key => $iIDAttributeCPDB) {
$aTokenAttributes[$key] = $iIDAttributeCPDB;
Expand Down Expand Up @@ -1894,7 +1894,7 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove
$sucessfull = 0;
$attid = []; //Will store the CPDB attribute_id of new or existing attributes keyed by CPDB at

$aTokenAttributes = decodeTokenAttributes($survey->attributedescriptions);
$aTokenAttributes = decodeTokenAttributes($survey->attributedescriptions ?? '');
$aAutoMapped = $survey->getCPDBMappings();

/* Create CPDB attributes */
Expand Down
4 changes: 2 additions & 2 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public function getAllLanguages()
*/
public function getTokenAttributes()
{
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions);
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');

// Catches malformed data
if ($attdescriptiondata && strpos((string) key(reset($attdescriptiondata)), 'attribute_') === false) {
Expand Down Expand Up @@ -1446,7 +1446,7 @@ public function getCountPartialAnswers()
*/
public function getDecodedAttributedescriptions()
{
return decodeTokenAttributes($this->attributedescriptions);
return decodeTokenAttributes($this->attributedescriptions ?? '');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/models/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function attributeLabels()
'validfrom' => gT('Valid from'),
'validuntil' => gT('Valid until'),
);
foreach (decodeTokenAttributes($this->survey->attributedescriptions) as $key => $info) {
foreach (decodeTokenAttributes($this->survey->attributedescriptions ?? '') as $key => $info) {
$labels[$key] = !empty($info['description']) ? $info['description'] : '';
}
return $labels;
Expand Down Expand Up @@ -435,7 +435,7 @@ public function rules()
array('validfrom', 'date','format' => ['yyyy-M-d H:m:s.???','yyyy-M-d H:m:s','yyyy-M-d H:m','yyyy-M-d'],'allowEmpty' => true),
array('validuntil','date','format' => ['yyyy-M-d H:m:s.???','yyyy-M-d H:m:s','yyyy-M-d H:m','yyyy-M-d'],'allowEmpty' => true),
);
foreach (decodeTokenAttributes($this->survey->attributedescriptions) as $key => $info) {
foreach (decodeTokenAttributes($this->survey->attributedescriptions ?? '') as $key => $info) {
$aRules[] = array(
$key, 'filter',
'filter' => array(self::class, 'sanitizeAttribute'),
Expand Down

0 comments on commit fac323d

Please sign in to comment.