Skip to content

Commit

Permalink
Fixed issue #15289: potential PHP warning in question editor with que…
Browse files Browse the repository at this point in the history
…stion theme

Dev: Check only in QuestionTemplate only
Dev: validateImage clearly put information about file must exist
  • Loading branch information
Shnoulle committed Sep 17, 2019
1 parent 053e954 commit 11e9eaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions application/core/LSYii_ImageValidator.php
Expand Up @@ -34,6 +34,7 @@ public static function validateImage($file)
$type = 'image/' . $parts[count($parts) - 1];
} else {
return [
// No translation ? send $file ?
'uploadresult' => 'Internal error: $file is not array or string',
'check' => false
];
Expand Down
15 changes: 10 additions & 5 deletions application/models/QuestionTemplate.php
Expand Up @@ -425,12 +425,17 @@ static public function getQuestionTemplateUserList($type)
if (!empty($oConfig->files->preview->filename)){
$fileName = json_decode(json_encode($oConfig->files->preview->filename), TRUE)[0];
$previewPath = $sFullPathToQuestionTemplate."/assets/".$fileName;
$check = LSYii_ImageValidator::validateImage($previewPath);
if(is_file($previewPath) && $check['check']) {
$aQuestionTemplates[$file]['preview'] = App()->getAssetManager()->publish($previewPath);
if(is_file($previewPath)) {
$check = LSYii_ImageValidator::validateImage($previewPath);
if($check['check']) {
$aQuestionTemplates[$file]['preview'] = App()->getAssetManager()->publish($previewPath);
} else {
/* Log it a theme.question.$oConfig->name as error, review ? */
Yii::log("Unable to use $fileName for preview in $sFullPathToQuestionTemplate/assets/",'error','theme.question.'.$oConfig->metadata->name);
}
} else {
/* Log it a theme.question.$oConfig->name as error, review ? */
Yii::log("Unable to use $fileName for preview in $sFullPathToQuestionTemplate/assets/",'error','theme.question.'.$oConfig->metadata->name);
/* Log it a theme.question.$oConfig->name as error, review ? */
Yii::log("Unable to find $fileName for preview in $sFullPathToQuestionTemplate/assets/",'error','theme.question.'.$oConfig->metadata->name);
}
}
if(empty($aQuestionTemplates[$file]['preview'])) {
Expand Down

0 comments on commit 11e9eaa

Please sign in to comment.